question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[sort-imports] Allow the users to group their imports in a simple way

See original GitHub issue

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 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Apr 3, 2020

We still need to figure out the option’s name.

Thoughts about allowSeparatedGroups ?

1reaction
aladdin-addcommented, Apr 2, 2020

just need 1 champion to accept it! friendly ping @eslint/eslint-team

Read more comments on GitHub >

github_iconTop Results From Across the Web

sort-imports - ESLint - Pluggable JavaScript Linter
This rule checks all import declarations and verifies that all imports are first sorted by the used member syntax and then alphabetically by...
Read more >
How to Sort Imports in React Project - Level Up Coding
But I found that the easy way is to sort the imports. ... there is an awesome plugin that can use to sort...
Read more >
ESLint simple-import-sort Groupings - Stack Overflow
I am trying to use the eslint-plugin-simple-import-sort library to sort my imports. I am trying to get my imports to look like this:...
Read more >
How to Sort Imports in TypeScript Automatically in VS Code
But thanks to the TS Import Sorter extension, there's an easier way, and all you have to do to use it is save...
Read more >
Sorting your imports correctly in React - DEV Community ‍ ‍
So, in the end, I will probably resort to simple-import-sort which does both, grouping and sorting in groups as well as import members....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found