[Fix] no-duplicates with type imports
Follow up fixes to https://github.com/import-js/eslint-plugin-import/pull/2475
Ref bug PRs:
- [x] https://github.com/import-js/eslint-plugin-import/issues/2715
- [ ] https://github.com/import-js/eslint-plugin-import/issues/2686
- [ ] https://github.com/import-js/eslint-plugin-import/issues/2691
- [ ] test fix: https://github.com/emberjs/ember.js/pull/20378
Am I correct this would fix #2675 ? If so this is my new favourite PR. 😄
If you need any testing done, I can probably help.
all the loops should be iteration methods whenever possible
Is there a reason for this guidance?
@runspired loops make code harder to understand and reason about. It's explained in the airbnb styleguide as well.
Look forward to the other 2 fixes :-)
@ljharb @snewcomer I am very interested in these fixes, so I wanted to take a stab at the remaining TODO items. As it turns out, they were already covered by this PR!
I reorganised some tests (inspired by tests/src/rules/consistent-type-specifier-style.js) to prove that both TypeScript and Flow work — see https://github.com/snewcomer/eslint-plugin-import/pull/1
Test results
no-duplicates
<snip>
with types
Babel/Flow
no-duplicates
valid
✓ import type { x } from './foo'; import y from './foo'
✓ import type x from './foo'; import type y from './bar'
✓ import type {x} from './foo'; import type {y} from './bar'
✓ import type x from './foo'; import type {y} from './foo'
✓
import type {} from './module';
import {} from './module2';
✓
import type { Identifier } from 'module';
declare module 'module2' {
import type { Identifier } from 'module';
}
declare module 'module3' {
import type { Identifier } from 'module';
}
✓ import { type x } from './foo'; import type y from 'foo'
invalid
✓ import { type x } from './foo'; import y from './foo';
✓ import type x from './foo'; import type y from './foo'
✓ import type x from './foo'; import type x from './foo'
✓ import type {x} from './foo'; import type {y} from './foo'
✓ import {type x} from './foo'; import {y} from './foo'
✓ import type {x} from './foo'; import {type y} from './foo'
✓ import type {x} from './foo';import {type y} from './foo';
✓ import {type x} from './foo'; import type {y} from './foo';
✓ import {type x} from 'foo'; import type {y} from 'foo'
✓ import {type x, C} from './foo'; import type {y} from './foo';
✓ import type {y} from './foo'; import {type x, C} from './foo';
✓ import {type x, C} from 'foo';import type {y} from 'foo';
✓ import type {y} from './foo'; import {type x, C} from './foo';
✓ import {type x} from './foo';import {type y} from './foo';
✓ import {type x} from './foo';import {type y} from './foo';
✓ import {type x} from './foo';import {type y} from './foo';import {type z} from './foo';
✓ import {type x} from './foo';import {type y} from './foo';import A from './foo';
✓ import {type x} from './foo';import {type y} from './foo';import A, { C } from './foo';
✓ import {AValue, type x, BValue} from './foo';import {type y, CValue} from './foo';
✓ import AValue from './foo'; import {type y} from './foo';
✓ import {type y} from './foo';import AValue from './foo';
✓ import AValue, {BValue} from './foo'; import {type y, CValue} from './foo';
✓ import {AValue, type x, BValue} from './foo'; import type {y} from './foo';
✓ import {AValue, type x, BValue} from './foo'; import type {y} from './foo'
✓ import AValue, {type x, BValue} from './foo';import type {y} from './foo';
✓ import AValue, {type x, BValue} from './foo'; import type {y} from './foo'
✓ import { type C, } from './foo';import {AValue, BValue, } from './foo';
TypeScript
no-duplicates
valid
✓ import type { x } from './foo'; import y from './foo'
✓ import type x from './foo'; import type y from './bar'
✓ import type {x} from './foo'; import type {y} from './bar'
✓ import type x from './foo'; import type {y} from './foo'
✓
import type {} from './module';
import {} from './module2';
✓
import type { Identifier } from 'module';
declare module 'module2' {
import type { Identifier } from 'module';
}
declare module 'module3' {
import type { Identifier } from 'module';
}
✓ import { type x } from './foo'; import type y from 'foo'
invalid
✓ import { type x } from './foo'; import y from './foo';
✓ import type x from './foo'; import type y from './foo'
✓ import type x from './foo'; import type x from './foo'
✓ import type {x} from './foo'; import type {y} from './foo'
✓ import {type x} from './foo'; import {y} from './foo'
✓ import type {x} from './foo'; import {type y} from './foo'
✓ import type {x} from './foo';import {type y} from './foo';
✓ import {type x} from './foo'; import type {y} from './foo';
✓ import {type x} from 'foo'; import type {y} from 'foo'
✓ import {type x, C} from './foo'; import type {y} from './foo';
✓ import type {y} from './foo'; import {type x, C} from './foo';
✓ import {type x, C} from 'foo';import type {y} from 'foo';
✓ import type {y} from './foo'; import {type x, C} from './foo';
✓ import {type x} from './foo';import {type y} from './foo';
✓ import {type x} from './foo';import {type y} from './foo';
✓ import {type x} from './foo';import {type y} from './foo';import {type z} from './foo';
✓ import {type x} from './foo';import {type y} from './foo';import A from './foo';
✓ import {type x} from './foo';import {type y} from './foo';import A, { C } from './foo';
✓ import {AValue, type x, BValue} from './foo';import {type y, CValue} from './foo';
✓ import AValue from './foo'; import {type y} from './foo';
✓ import {type y} from './foo';import AValue from './foo';
✓ import AValue, {BValue} from './foo'; import {type y, CValue} from './foo';
✓ import {AValue, type x, BValue} from './foo'; import type {y} from './foo';
✓ import {AValue, type x, BValue} from './foo'; import type {y} from './foo'
✓ import AValue, {type x, BValue} from './foo';import type {y} from './foo';
✓ import AValue, {type x, BValue} from './foo'; import type {y} from './foo'
✓ import { type C, } from './foo';import {AValue, BValue, } from './foo';
123 passing (560ms)
Hey, it would be great to handle type imports with no-duplicates - Is there anything that I could help with?
Is there anything else we can help with to get this merged? It's a great improvement over the current behaviour.
Also eager to see this merged and happy to help where needed!
@snewcomer Hi! Sorry for mention, but this PR is super helpfull and it will be great to see this merged! Are there any additional things you would like to work on? Maybe it also fixes https://github.com/import-js/eslint-plugin-import/issues/2792
I havent tested yet, but this might be fixed by https://github.com/import-js/eslint-plugin-import/pull/2835
I've rebased this PR, but tests seem to be failing. @mrm007 sorry i hadn't looked at your PR-PR yet - would you mind rebasing yours, and then I can pull it in?
@snewcomer is there a reason you overwrote my rebase?
Hi sorry. I didn't see any commits. If I was mistaken due to keeping this PR open in Safari and not getting real time updates, I'm sorry.
FYI put a comment here.
https://github.com/import-js/eslint-plugin-import/commit/f302f7d31d28c91bd483c5da14600ce6e26cd0e3#r123760801