An ESLint plugin focused on consistent import / export declaration order and
structure.
This plugin defines rules for sorting and structuring import and export
declarations.
All rules are automatically fixable.
See docs.
You'll first need to install ESLint v8.45.0 or greater:
npm install --save-dev eslintNext, install @omnicajs/eslint-plugin-dependencies:
npm install --save-dev @omnicajs/eslint-plugin-dependenciesAdd @omnicajs/eslint-plugin-dependencies to the plugins section of the ESLint
configuration file and define the list of rules you will use.
Flat Config (eslint.config.js)
import dependencies from '@omnicajs/eslint-plugin-dependencies'
export default [
{
plugins: {
dependencies,
},
rules: {
'dependencies/sort-imports': [
'error',
{
type: 'natural',
order: 'asc',
},
],
},
},
]Legacy Config (.eslintrc.js)
module.exports = {
plugins: [
'dependencies',
],
rules: {
'dependencies/sort-imports': [
'error',
{
type: 'natural',
order: 'asc',
}
]
}
}The easiest way to use @omnicajs/eslint-plugin-dependencies is to use
ready-made configs. Config files use import/export rules from the plugin, but
you can override them.
Flat Config (eslint.config.js)
import dependencies from '@omnicajs/eslint-plugin-dependencies'
export default [
dependencies.configs['recommended-natural'],
]Legacy Config (.eslintrc.js)
module.exports = {
extends: [
'plugin:dependencies/recommended-natural-legacy',
],
}| Name | Description |
|---|---|
| recommended-alphabetical | Import/export rules with alphabetical sorting in ascending order |
| recommended-natural | Import/export rules with natural sorting in ascending order |
| recommended-line-length | Import/export rules with sorting by line length in descending order |
| recommended-custom | Import/export rules with sorting by your own custom order |
π§ Automatically fixable by the
--fix CLI option.
| Name | Description | π§ |
|---|---|---|
| sort-export-attributes | Enforce sorted export attributes | π§ |
| sort-exports | Enforce sorted exports | π§ |
| sort-import-attributes | Enforce sorted import attributes | π§ |
| sort-imports | Enforce sorted imports | π§ |
| sort-named-exports | Enforce sorted named exports | π§ |
| sort-named-imports | Enforce sorted named imports | π§ |
| import-style | Enforce explicit module import style | π§ |
| separate-type-imports | Enforce dedicated type import declarations | π§ |
| separate-type-partitions | Enforce partitions for type-only imports | π§ |
This plugin is following Semantic Versioning and ESLint's Semantic Versioning Policy.
See Contributing Guide.