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

import/order group by prefix

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

Description

I import from all over my app, with a mix of relative and root imports. The current order rule covers most of my cases, and with #629 fixing #389 (sorting alphabetically), that will cover more. But one case that won't be covered is that I prefer to have all my global functions imported first, which come from a `/lib` directory, followed by my components which come from a `/client/modules` directory.

Sorting alphabetically, I would have to do
```
import someComponent from '/client/modules/someComponent';
import someFunction from '/lib/someFunction';
```

But I'd rather do
```
import someFunction from '/lib/someFunction';
import someComponent from '/client/modules/someComponent';
```

Within the rule itself, there's one way I could see it being defined

Use the existing `groups` option, and anything that isn't currently an option (`builtins`, `sibling`, etc) would be considered a prefix
```
"import/order": ["error", {"groups": ["builtins", "external", "/lib", "/client"]}]
```

This would also handle the concern in [this comment](https://github.com/benmosher/eslint-plugin-import/issues/389#issuecomment-227575812) that people will start to request a bunch of order types and exceptions to them

Contributor guide

Open the contributing guide

Research direction

Start by examining the existing import/order rule and its groups option. Determine how directory prefixes such as /lib and /client should be represented alongside the existing group names, then verify that the proposed ordering works while preserving alphabetical sorting within each prefix.

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.