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

`pathGroupsExcludedImportTypes` must be set to an empty array?

Open
#2,291 6 comments 7 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Here's the relevant bit of our config:
```json
"import/order": [ "error", {
"groups": [
[ "builtin", "external" ],
[ "internal" ],
[ "parent", "sibling", "index" ],
[ "object", "type" ]
],
"pathGroups": [
{
"pattern": "Forms/**",
"group": "internal",
"position": "before"
}
],
"pathGroupsExcludedImportTypes": [],
"newlines-between": "always"
} ],
```

This works, I think. But I fail to understand why. The `pathGroups`, I assume, tells `import/order` the patterns that belong to `internal` imports.

But then why would I *ever* need to specify the `position` as well? Surely this is handled by `groups` already? 🤨

Also why does this *only* work when `pathGroupsExcludedImportTypes` is an empty array? I cannot understand *for the life of me* what that thing actually does. But it has to do with `pathGroups`, in some way or another, so I just started guessing at its value. The documentation is incredibly vague on this. Something is excluded - what is exlcuded, and from what? And what effect does it have on import order, and why?

Lastly, I shouldn't have to use `pathGroups` in the first place. This is a workaround for the fact that even with a parser that understands `jsconfig.json` or `tsconfigjson`, after [2 years](https://github.com/import-js/eslint-plugin-import/issues/1490) it still doesn't see that these aliased paths actually belong to `internal`. I haven't looked at the code, but it feels like `import/order` way of deterining what sort of import is external vs internal, is hardcoded, instead of taken from any kind of configuration to speak of.

I'd like to keep my configs DRY, but that seems impossible with this plugin. Can we get this fixed please?

Recap:

* `position` shouldn't be neccesary - handled by `groups` order.
* `pathGroupsExcludedImportTypes` is vague:
* Needs better explanation
* Might need a more sane default value
* Should not be neccesary when just using `pathGroups` to "assign" certain paths to a group
* Please respect project config in `jsconfig.json` or `tsconfig.json`. Using one of these is the defacto standard to configure path aliases. And ESLint is aware of these when using a parser that requires them.

Contributor guide

Open the contributing guide

Research direction

Start with the import/order rule documentation and the linked issue #1490 to understand the existing alias-resolution limitation. Review how pathGroups, position, and pathGroupsExcludedImportTypes are currently defined, then determine the intended configuration behavior and document or implement it with appropriate coverage; done means aliased paths and exclusions have clear, predictable ordering without unnecessary configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.