import-js / import-js/eslint-plugin-import

[import/order]: `allowSeparatedGroups`

Open
#3,203 0 comments 1 reaction 0 assignees View on GitHub
enhancement import/export ordering
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

ESLint `sort-imports` has a option `allowSeparatedGroups` that checks the sorting of import declaration statements only for those that appear on consecutive lines. But `import/order` doesn't have. Although you can achieve it by using `groups` and `newlines-between` options, I don't want to set the groups at eslint config, but respect the existed separated groups in the file.

For example:

Config rule:
```json
{
"import/order": ["warn", {
"alphabetize": { "order": "asc", "orderImportKind": "asc", "caseInsensitive": false },
"named": true,
}],
}
```

Original code:
```javascript
import c from "c";

import b from "b";
import a from "a";
```

Current fix behavior:
```javascript
import a from "a";
import b from "b";
import c from "c";
```

Expected fix behavior:
```javascript
import c from "c";

import a from "a";
import b from "b";
```

Original code:
```javascript
// Group 1
import c from "c";
// Group 2
import e from "e";
import d from "d";
// Group 3
import b from "b";
import a from "a";
```

Current fix behavior:
```javascript
// Group 1
import a from "a";
import b from "b";
import c from "c";
// Group 2
import d from "d";
import e from "e";
// Group 3
```

Expected fix behavior:
```javascript
// Group 1
import c from "c";
// Group 2
import d from "d";
import e from "e";
// Group 3
import a from "a";
import b from "b";
```

I wish there will be a new option like `allowSeparatedGroups` in `import/order` rule to achieve this behavior.

Contributor guide

Open the contributing guide

Research direction

Start by locating the import/order rule implementation and its tests. Review how separated import groups and the existing groups and newlines-between options are handled. Done means a new option preserves each separated group while sorting imports within that group, with tests covering both examples in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.