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
[sort-imports] Allow the users to group their imports in a simple way #12951
Comments
Should the option look specifically for blank lines somewhere between import lines, or allow all cases where imports are not on consecutive lines: /*eslint sort-imports: ["error", { "ignoreBlankLines": false }]*/
import b from 'foo.js';
import c from 'baz.js';
// comment
import a from 'bar.js'; // error?
import x from 'qux.js'; /*eslint sort-imports: ["error", { "ignoreBlankLines": false }]*/
import b from 'foo.js';
import c from 'baz.js';
foo();
import a from 'bar.js'; // error?
import x from 'qux.js'; |
@mdjermanovic In my opinion, both should be correct with the option set to |
It makes sense to me, especially for the example with another statement between imports (less sure about the comment example). Then, we should probably find a new name for the option, since it isn't about blank lines. Maybe something like |
@mdjermanovic Agreed, maybe it's a good idea to take something from the TSLint ordered-imports property, which is behaving very similar to my proposal and it was the inspiration for it. However, both libraries are different and might not be applicable to ESLint. Let's keep this discussion open and get a third opinion! Thanks for your feedback! |
Just to mention that, regardless of its name, in a certain way this option isn't compatible with the This would be a misconfiguration: {
"rules": {
"padding-line-between-statements": ["error",
{ "blankLine": "always", "prev": "import", "next": "import" }
],
"sort-imports": ["error", { "ignoreBlankLines": false }]
}
} Autofix for I'm not sure if that's an issue. |
@mdjermanovic Agreed! Although when used in conjunction the developer should be aware of the results. The |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
just need 1 champion to accept it! friendly ping @eslint/eslint-team |
I'll champion this, it needs one more 👍 now. |
Added my 👍 and marked as accepted. |
We still need to figure out the option's name. Thoughts about |
What rule do you want to change?
sort-imports
Does this change cause the rule to produce more or fewer warnings?
Yes
How will the change be implemented? (New option, new default behavior, etc.)?
Add a new option called
ignoreBlankLines
, defaults totrue
, which when set tofalse
will not trigger the alphabetical sort if the previous line is blank.Please provide some example code that this change will affect:
🔴Examples of incorrect code for this rule with the { "ignoreBlankLines": true } option:
🟢Examples of correct code for this rule with the { "ignoreBlankLines": false } option:
What does the rule currently do for this code?
Currently the rule doesn't respect blank lines, meaning that even if there is a line break between imports, it will still error out that they're not sorted alphabetically.
What will the rule do after it's changed?
After the change, the new option will allow grouping of imports, each of which will be alphabetically sort.
Example:
Are you willing to submit a pull request to implement this change?
Yes
The text was updated successfully, but these errors were encountered: