[sort-imports] Allow the users to group their imports in a simple way
See original GitHub issueWhat 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 to true
, which when set to false
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:
/*eslint sort-imports: "error" */
import b from 'foo.js';
import c from 'baz.js';
import a from 'bar.js';
import x from 'qux.js';
🟢Examples of correct code for this rule with the { “ignoreBlankLines”: false } option:
/*eslint sort-imports: ["error", { "ignoreBlankLines": false }]*/
import b from 'foo.js';
import c from 'baz.js';
import a from 'bar.js';
import x from 'qux.js';
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:
/*eslint sort-imports: ["error", { "ignoreBlankLines": false }]*/
import React from 'react';
import moment from 'moment';
// Components
import Footer from '@app/footer.js';
import Header from '@app/header.js';
Are you willing to submit a pull request to implement this change? Yes
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:11 (7 by maintainers)
Top GitHub Comments
We still need to figure out the option’s name.
Thoughts about
allowSeparatedGroups
?just need 1 champion to accept it! friendly ping @eslint/eslint-team