Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stormwarning committed Dec 13, 2024
1 parent 1fd182c commit 5d14f7f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 33 deletions.
38 changes: 18 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
## eslint-plugin-import-sorting
# eslint-plugin-import-sorting

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

1. Node standard modules
2. Framework modules
3. External modules
4. Internal modules
5. Explicitly local modules

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.
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.

## Usage

Install the plugin, and ESLint if is not already.
Install the plugin, and ESLint if it is not already.

```sh
npm install --save-dev eslint eslint-plugin-import-sorting
```

Include the plugin in the `plugins` key of your ESLint config and enable the rule.
Include the plugin in the `plugins` key of your ESLint config and enable the
rules.

```js
// eslint.config.js
Expand All @@ -31,26 +36,19 @@ export default [
'import-sorting': importSortingPlugin,
},
rules: {
'import-sorting/order': 'warn',
'import-sorting/order': 'error',
},
},
]
```

<details>
<summary>Legacy config example</summary>
<!-- begin auto-generated rules list -->

```js
// .eslintrc.js

module.exports = {
plugins: ['import-sorting'],
rules: {
'import-sorting/order': 'warn',
},
}
```
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).

</details>
| Name | Description | 🔧 |
| :----------------------------------------------- | :------------------------------------------ | :- |
| [order](docs/rules/order.md) | Consistently order `import` statements. | 🔧 |
| [specifier-order](docs/rules/specifier-order.md) | Consistently order named import specifiers. | 🔧 |

See the [order](https://github.com/stormwarning/eslint-plugin-import-sorting/blob/main/docs/rules/order.md) rule docs for more configuration options.
<!-- end auto-generated rules list -->
26 changes: 15 additions & 11 deletions docs/rules/order.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# import-sorting/order
# Consistently order `import` statements (`import-sorting/order`)

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

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

The grouping order is as follows:

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

```js
settings: {
// Group official React packages together.
'import-sorting/framework-patterns': /^react(\/|-dom|-router|$)/.source,
// Group aliased imports together.
'import-sorting/internal-patterns': /^~/.source,
},
rules: {
'import-sorting/order': 'error',
},
export default [
{
settings: {
// Group official React packages together.
'import-sorting/framework-patterns': /^react(\/|-dom|-router|$)/.source,
// Group aliased imports together.
'import-sorting/internal-patterns': /^~/.source,
},
rules: {
'import-sorting/order': 'error',
},
},
]
```
18 changes: 18 additions & 0 deletions docs/rules/specifier-order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Consistently order named import specifiers (`import-sorting/specifier-order`)

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

<!-- end auto-generated rule header -->

Specifiers are sorted naturally, the same as imports within groups. `type`
keywords are ignored during sorting.

```js
export default [
{
rules: {
'import-sorting/specifier-order': 'error',
},
},
]
```
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import order from './rules/order.js'
import specifierOrder from './rules/specifier-order.js'

const plugin = {
name: 'sorting-order',
name: 'import-sorting',
rules: {
order,
'specifier-order': specifierOrder,
},
}

Expand Down
2 changes: 1 addition & 1 deletion src/rules/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default createRule<unknown[], MessageId>({
type: 'suggestion',
fixable: 'code',
docs: {
description: 'Enforce a convention in the order of `import` statements.',
description: 'Consistently order `import` statements.',
},
messages: {
'needs-newline':
Expand Down

0 comments on commit 5d14f7f

Please sign in to comment.