azat-io / eslint-plugin-perfectionist

☂️ ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://perfectionist.dev
MIT License
1.92k stars 41 forks source link

Bug(sort-imports): Invalid newlines auto-fix under very special conditions #329

Open hugop95 opened 3 weeks ago

hugop95 commented 3 weeks ago

Describe the bug

Newline auto-fixes can in very specific configurations result in code that does not compile. See code example.

Code example

Configuration:

"newlinesBetween": "always" or "never".

Code:

import a from 'a'

 import b from 'b'

Notice the whitespace before the second import.

The resulting code is:

import a from 'a' import b from 'b'

ESLint version

8.57.0

ESLint Plugin Perfectionist version

3.9.1

Additional comments

No response

Validations

hugop95 commented 3 weeks ago

@azat-io This is fixed by #324, but that PR will be available in the next major version.

I don't think that this bug appears that often in practice: this requires two imports to be separated by more than the required number of newlines and the additional whitespace, so should not be a recurring issue. I don't think that a hotfix in v3.9 is mandatory, but I can make a PR for that if you want as well.