Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-duplicates] invalid fix when there are 3 imports with named imports and dangling commas #2840

Closed
bradzacher opened this issue Jul 25, 2023 · 5 comments

Comments

@bradzacher
Copy link
Contributor

bradzacher commented Jul 25, 2023

Input:

import {A1,} from 'foo';
import {B1,} from 'foo';
import {C1,} from 'foo';

import {
  A2,
} from 'bar';
import {
  B2,
} from 'bar';
import {
  C2,
} from 'bar';

Expected:

Error and fixed to

import {A1,B1,C1,} from 'foo';
import {
  A2,
  B2,
  C2,
} from 'bar';

(or something similar)

Actual:

Error and fixed to

import {A1,B1,,C1,} from 'foo';
              ^ SYNTAX ERROR
import {
  A2,

  B2,
,
^ SYNTAX ERROR
  C2,
} from 'bar';

Interestingly this bug requires 3 (or more) duplicate declarations to trigger.

I haven't looked yet - but given it happens for 3 and not 2 - I'd assume that ESLint is merging the distinct fixes poorly - leading to the syntax error.

@AngusMacrae
Copy link

facing this bug too, can confirm it only occurs with 3 or more duplicate import paths

@ljharb
Copy link
Member

ljharb commented Nov 25, 2023

Tests pass on latest master with this snippet, so I'll close this shortly when I push those up.

@ljharb ljharb closed this as completed in 9fd3c42 Nov 25, 2023
@bradzacher
Copy link
Contributor Author

@ljharb the ESLint rule tester might not pick this up? Depends how it composites fixes together I guess. Might be worth a quick whirl as a manual test against a file with the CLI to triple check.

@ljharb
Copy link
Member

ljharb commented Nov 25, 2023

I’ve not run into any cases like that with the rule tester; could you make a small repro repo?

@bradzacher
Copy link
Contributor Author

Hmm - investigating more this appears to be working fine now yeah.
Some combination of the latest ESLint version and the latest plugin version appears to have fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants