diff --git a/README.md b/README.md index 4275f64..0904675 100644 --- a/README.md +++ b/README.md @@ -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', + }, + }, +] +``` + +
+ Legacy config example + ```js -rules: { - 'import-sorting/order': 'error', +// .eslintrc.js + +module.exports = { + plugins: ['import-sorting'], + rules: { + 'import-sorting/order': 'warn', + }, } ``` +
+ See the [order](https://github.com/stormwarning/eslint-plugin-import-sorting/blob/main/docs/rules/order.md) rule docs for more configuration options. diff --git a/docs/rules/order.md b/docs/rules/order.md index d65c855..2d8d305 100644 --- a/docs/rules/order.md +++ b/docs/rules/order.md @@ -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