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

import/order ignores pathGroups order

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

Description

eslint ignores the order in which imports are listed

example imports:
```
import React from 'react';

import Test from "components/Test";
import Api from "pages/api";
```

eslint must throw an error saying that import from "pages/api" must be over "components/Test" and also be separated with a new line but it ignores this

eslint-plugin-import and eslint-import-resolver-typescript are already installed so I'm sure that I made a mistake somewhere, but where?

eslint rule:
```
"import/order": ["error", {
"newlines-between": "always-and-inside-groups",
"groups": ["builtin", "external", "internal"],
"pathGroups": [
{
"pattern": "react",
"group": "external",
"position": "before"
},
{
"pattern": "~/**",
"group": "external",
"position": "before"
},
{
"pattern": "~/pages/**",
"group": "internal"
},
{
"pattern": "~/components/**",
"group": "internal"
},
{
"pattern": "~/startup/**",
"group": "internal"
},
{
"pattern": "~/hooks/**",
"group": "internal"
},
{
"pattern": "~/helpers/**",
"group": "internal"
},
{
"pattern": "~/generated/**",
"group": "internal"
},
{
"pattern": "~/styles/**",
"group": "internal"
}
],
"pathGroupsExcludedImportTypes": ["react"],
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}]
```
Project structure:
![image](https://user-images.githubusercontent.com/54347665/106421578-051e8b00-646e-11eb-8905-978d06e8a233.png)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the example with the supplied import/order configuration, including the pathGroups entries and pathGroupsExcludedImportTypes setting. Compare the expected ordering of pages/api and components/Test and the required blank line with the rule's actual diagnostics; done means the rule reports both violations.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.