Skip to content

Commit 5d14f7f

Browse files
committed
Update docs
1 parent 1fd182c commit 5d14f7f

File tree

5 files changed

+55
-33
lines changed

5 files changed

+55
-33
lines changed

README.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
## eslint-plugin-import-sorting
1+
# eslint-plugin-import-sorting
22

3-
Enforce a convention in the order of `import` statements, inspired by [isort](https://timothycrosley.github.io/isort/#how-does-isort-work)’s grouping style:
3+
Enforce a convention in the order of `import` statements, inspired by
4+
[isort](https://timothycrosley.github.io/isort/#how-does-isort-work)’s grouping style:
45

56
1. Node standard modules
67
2. Framework modules
78
3. External modules
89
4. Internal modules
910
5. Explicitly local modules
1011

11-
This plugin includes an additional group for “style” imports where the import source ends in `.css` or other style format. Imports are sorted alphabetically, except for local modules, which are sorted by the number of `.` segements in the path first, then alphabetically.
12+
This plugin includes an additional group for “style” imports where the import
13+
source ends in `.css` or other style format. Imports are sorted alphabetically,
14+
except for local modules, which are sorted by the number of `.` segements in
15+
the path first, then alphabetically.
1216

1317
## Usage
1418

15-
Install the plugin, and ESLint if is not already.
19+
Install the plugin, and ESLint if it is not already.
1620

1721
```sh
1822
npm install --save-dev eslint eslint-plugin-import-sorting
1923
```
2024

21-
Include the plugin in the `plugins` key of your ESLint config and enable the rule.
25+
Include the plugin in the `plugins` key of your ESLint config and enable the
26+
rules.
2227

2328
```js
2429
// eslint.config.js
@@ -31,26 +36,19 @@ export default [
3136
'import-sorting': importSortingPlugin,
3237
},
3338
rules: {
34-
'import-sorting/order': 'warn',
39+
'import-sorting/order': 'error',
3540
},
3641
},
3742
]
3843
```
3944

40-
<details>
41-
<summary>Legacy config example</summary>
45+
<!-- begin auto-generated rules list -->
4246

43-
```js
44-
// .eslintrc.js
45-
46-
module.exports = {
47-
plugins: ['import-sorting'],
48-
rules: {
49-
'import-sorting/order': 'warn',
50-
},
51-
}
52-
```
47+
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
5348

54-
</details>
49+
| Name | Description | 🔧 |
50+
| :----------------------------------------------- | :------------------------------------------ | :- |
51+
| [order](docs/rules/order.md) | Consistently order `import` statements. | 🔧 |
52+
| [specifier-order](docs/rules/specifier-order.md) | Consistently order named import specifiers. | 🔧 |
5553

56-
See the [order](https://github.com/stormwarning/eslint-plugin-import-sorting/blob/main/docs/rules/order.md) rule docs for more configuration options.
54+
<!-- end auto-generated rules list -->

docs/rules/order.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# import-sorting/order
1+
# Consistently order `import` statements (`import-sorting/order`)
22

33
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
44

5-
Enforce a convention in the order of `import` statements.
5+
<!-- end auto-generated rule header -->
66

77
The grouping order is as follows:
88

@@ -24,13 +24,17 @@ constitutes an “internal” module.
2424
For example:
2525

2626
```js
27-
settings: {
28-
// Group official React packages together.
29-
'import-sorting/framework-patterns': /^react(\/|-dom|-router|$)/.source,
30-
// Group aliased imports together.
31-
'import-sorting/internal-patterns': /^~/.source,
32-
},
33-
rules: {
34-
'import-sorting/order': 'error',
35-
},
27+
export default [
28+
{
29+
settings: {
30+
// Group official React packages together.
31+
'import-sorting/framework-patterns': /^react(\/|-dom|-router|$)/.source,
32+
// Group aliased imports together.
33+
'import-sorting/internal-patterns': /^~/.source,
34+
},
35+
rules: {
36+
'import-sorting/order': 'error',
37+
},
38+
},
39+
]
3640
```

docs/rules/specifier-order.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Consistently order named import specifiers (`import-sorting/specifier-order`)
2+
3+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
4+
5+
<!-- end auto-generated rule header -->
6+
7+
Specifiers are sorted naturally, the same as imports within groups. `type`
8+
keywords are ignored during sorting.
9+
10+
```js
11+
export default [
12+
{
13+
rules: {
14+
'import-sorting/specifier-order': 'error',
15+
},
16+
},
17+
]
18+
```

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import order from './rules/order.js'
2+
import specifierOrder from './rules/specifier-order.js'
23

34
const plugin = {
4-
name: 'sorting-order',
5+
name: 'import-sorting',
56
rules: {
67
order,
8+
'specifier-order': specifierOrder,
79
},
810
}
911

src/rules/order.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default createRule<unknown[], MessageId>({
3838
type: 'suggestion',
3939
fixable: 'code',
4040
docs: {
41-
description: 'Enforce a convention in the order of `import` statements.',
41+
description: 'Consistently order `import` statements.',
4242
},
4343
messages: {
4444
'needs-newline':

0 commit comments

Comments
 (0)