Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stormwarning committed Aug 30, 2024
1 parent 99bf63f commit 18505fb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,53 @@ Enforce a convention in the order of `import` statements, inspired by [isort](ht

1. Node standard modules
2. Framework modules
3. Third-party modules
4. First-party 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.

## Usage

Install the plugin, and ESLint if 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.

```js
// eslint.config.js

import importSortingPlugin from 'eslint-plugin-import-sorting'

export default [
{
plugins: {
'import-sorting': importSortingPlugin,
},
rules: {
'import-sorting/order': 'warn',
},
},
]
```

<details>
<summary>Legacy config example</summary>

```js
rules: {
'import-sorting/order': 'error',
// .eslintrc.js

module.exports = {
plugins: ['import-sorting'],
rules: {
'import-sorting/order': 'warn',
},
}
```

</details>

See the [order](https://github.com/stormwarning/eslint-plugin-import-sorting/blob/main/docs/rules/order.md) rule docs for more configuration options.
10 changes: 10 additions & 0 deletions docs/rules/order.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

Enforce a convention in the order of `import` statements.

The grouping order is as follows:

1. Unassigned imports (only grouped, existing order is preserved)
2. Node/Bun standard modules (protocol is ignored when sorting)
3. Framework modules (see below)
4. External modules
5. Internal modules (see below)
6. Explicitly local modules (paths starting with a dot segment)
7. Style imports

## Settings

The framework and internal groups can be configured by passing a RegEx
Expand Down

0 comments on commit 18505fb

Please sign in to comment.