eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

[Fix] no-duplicates with type imports

Open snewcomer opened this issue 2 years ago • 12 comments

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

snewcomer avatar Feb 12 '23 19:02 snewcomer

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.

simmo avatar Feb 14 '23 12:02 simmo

all the loops should be iteration methods whenever possible

Is there a reason for this guidance?

runspired avatar Feb 14 '23 20:02 runspired

@runspired loops make code harder to understand and reason about. It's explained in the airbnb styleguide as well.

ljharb avatar Feb 14 '23 21:02 ljharb

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)

mrm007 avatar Apr 08 '23 05:04 mrm007

Hey, it would be great to handle type imports with no-duplicates - Is there anything that I could help with?

niklasnatter avatar Apr 11 '23 08:04 niklasnatter

Is there anything else we can help with to get this merged? It's a great improvement over the current behaviour.

mrm007 avatar May 23 '23 23:05 mrm007

Also eager to see this merged and happy to help where needed!

seanCodes avatar Jun 29 '23 03:06 seanCodes

@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

oceandrama avatar Jul 14 '23 09:07 oceandrama

I havent tested yet, but this might be fixed by https://github.com/import-js/eslint-plugin-import/pull/2835

niklasnatter avatar Jul 27 '23 08:07 niklasnatter

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?

ljharb avatar Jul 27 '23 20:07 ljharb

@snewcomer is there a reason you overwrote my rebase?

ljharb avatar Jul 28 '23 17:07 ljharb

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

snewcomer avatar Aug 06 '23 19:08 snewcomer