-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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] additional new lines are generated when the list of imports to squash is long #2027
Comments
And if you run |
@ljharb a subsequent run of import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'
import { One , OneDoc } from '../fragments/one'
import { Two , TwoDoc } from '../fragments/two'
import { Three , ThreeDoc } from '../fragments/three'
import { Four , FourDoc } from '../fragments/four'
import { Five , FiveDoc } from '../fragments/five'
import { Six , SixDoc } from '../fragments/six'
import { Seven , SevenDoc } from '../fragments/seven'
import { Eight , EightDoc } from '../fragments/eight'
export const Vars = any |
So what's the issue? eslint autofixing sometimes does require multiple passes. |
The issue is that those extra new lines are generated. If we remove
Afaik |
ahhh, i see what you mean. If the autofixes from the import rules - when enabled alone - are producing those empty lines, then that does seem like something we can avoid doing. |
Correct, the empty lines are the result of auto-fixing. I plan to take a closer look what exactly is producing empty lines, at the moment I only narrowed it down to those 3 rules: The case I provided is also important to the reproduction, when the example.js is slightly adjusted the problem is gone. It must be some really edge case. |
I eliminated the role of It appears that the new lines are injected starting from 9th import to squash if we have those two rules enabled. However, when I keep just
The result is import { One , OneDoc } from '../fragments/one'
import { Two , TwoDoc } from '../fragments/two'
import { Three , ThreeDoc } from '../fragments/three'
import { Four , FourDoc } from '../fragments/four'
import { Five , FiveDoc } from '../fragments/five'
import { Six , SixDoc } from '../fragments/six'
import { Seven , SevenDoc } from '../fragments/seven'
import { Eight , EightDoc } from '../fragments/eight'
import { Nine , NineDoc } from '../fragments/nine'
import { Ten , TenDoc } from '../fragments/ten'
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'
export const Vars = any |
Seems like no-duplicates is to blame. |
I agree and reflected that in the issue title. I'm looking into the problem but I'm new to the codebase so it may take a while until I grasp the idea behind the fixer. Any help/pointers are appreciated 🙇 |
Thanks! I'll take a look at #2028 and offer as much help as i can, once i have time to do so :-) |
I marked #2028 as ready for review. Turned out that this problem occurs with any number of imports. I guess it's not so popular to have more than 2 duplicated imports so it was not causing any issues for most of the users. |
Also since it’s corrected by a second autofix, people may have not bothered reporting it. |
I have some trouble with failing tests, they highlighted some more scenarios not covered by my change. The test cases are formatted with leading spaces like
so removing just a new line character produces a very weird formatting. I considered reworking the test to ignore the leading spaces, but IMO it shows that the fix tries to be too smart now. The problem occurred in autogenerated files, it may be much easier to update the generator to not produce duplicates. Any thoughts on this @ljharb ? I'm leaning towards closing this issue as |
I stubled upon a weird problem. My
eslint --fix
results in excessive spacing created, a few additional new lines are inserted with no reason.I narrowed down the case to the clash of those 3 rules:
no-multiple-empty-lines
import/no-duplicates
import/order
The original file:
The result of
eslint --fix
The final configuration looks like below
I put together an example repo affected by the issue: https://github.com/ertrzyiks/import-order-multiple-empty-lines-demo
The result of
eslint --fix
is the following error:Examples
8 imports
A file with 8 imports to squash looks good 👍
https://github.com/ertrzyiks/import-order-multiple-empty-lines-demo/blob/main/example8.js
https://github.com/ertrzyiks/import-order-multiple-empty-lines-demo/blob/main/results/example8.js
9 imports
A file with 9 imports starts to generate empty lines at the end of the imports block
https://github.com/ertrzyiks/import-order-multiple-empty-lines-demo/blob/main/example9.js
https://github.com/ertrzyiks/import-order-multiple-empty-lines-demo/blob/main/results/example9.js
10 imports
A file with 10 imports starts to generate empty lines between the imports block and left-overs from merging
https://github.com/ertrzyiks/import-order-multiple-empty-lines-demo/blob/main/example10.js
https://github.com/ertrzyiks/import-order-multiple-empty-lines-demo/blob/main/results/example10.js
The text was updated successfully, but these errors were encountered: