eslint-plugin-jsort
v1.1.3
Published
Sort imports effortlessly.
Downloads
57
Maintainers
Readme
eslint-plugin-jsort
ESLint plugin with rules to sort imports effortlessly.
$ npm install eslint-plugin-jsort
This rule sorts & formats import declaration with a lot of flexibility using eslint --fix
.
JavaScript imports are frustrating and this tries to make them a bit easier to work with. Feel free to post any issues/suggestions you might have with the plugin on the issue tracker.
Capabilities
- Sort import declarations into distinct groups by type
- Sort import declarations by "global" packages vs "local" packages
- Sort import declarations by source
- Sort imported modules (aka specifiers)
- Combine import declarations that can be combined
- Force explicit default imports
- Force single line imports
- Force explicit type imports
- Normalize import source
Supported Parsers
Installation
- Install ESLint:
$ npm i eslint --save-dev
- Install the plugin
eslint-plugin-jsort
:
$ npm install eslint-plugin-jsort --save-dev
Usage
- Add
jsort
to the plugins section of your.eslintrc
configuration file. You can omit theeslint-plugin-
prefix:
{
"plugins": ["jsort"]
}
- Then configure the rules you want to use under the rules section.
{
"rules": {
"jsort/sort-imports": [
"error",
{
/* `sort-imports` Additional Configuration */
}
],
"jsort/normalize-import-source": [
"error",
{
/* `normalize-import-source` Additional Configuration */
}
]
}
}
- For "
sort-imports
Additional Configuration" seejsort/sort-imports
docs. - For "
normalize-import-source
Additional Configuration" seejsort/normalize-import-source
docs
Available Rules
Other Alternatives
- ESLint Builtin
sort-imports
Rule - eslint-plugin-simple-import-sort
- eslint-plugin-sort-imports-es6-autofix
- prettier-plugin-sort-imports
- eslint-plugin-import