eslint-plugin-group-sort-decorators
v1.1.2
Published
An ESLint plugin to enforce grouping and sorting of decorators by import source, with optional alphabetical sorting within groups.
Downloads
26
Maintainers
Readme
eslint-plugin-group-sort-decorators
An ESLint plugin to enforce consistent grouping and ordering of decorators based on their import source, with optional alphabetical sorting within groups.
Installation
npm install --save-dev eslint-plugin-group-sort-decoratorsUsage
Add group-sort-decorators to your ESLint plugins and configure the rule in your ESLint config:
{
"plugins": ["group-sort-decorators"],
"rules": {
"group-sort-decorators/group-sort": ["warn", {
"groups": {
"first": ["lib-a"],
"last": ["lib-b"]
},
"alphabeticalWithinGroups": true
}]
}
}Rule: group-sort
This rule enforces that decorators are grouped and ordered according to the import source, and optionally sorted alphabetically within each group.
Options
groups.first(array): List of import sources whose decorators should always come first, in order.groups.last(array): List of import sources whose decorators should always come last, in order.- Decorators from sources not listed in
firstorlastwill be placed in the middle, sorted alphabetically by import source. alphabeticalWithinGroups(boolean, default:true): Whether to sort decorators alphabetically within each group.
Example
Given this config:
"groups": {
"first": ["lib-a"],
"last": ["lib-b"]
}Valid:
import { A } from 'lib-a';
import { C } from 'lib-c';
import { B } from 'lib-b';
@A()
@C()
@B()
class Test {}Invalid:
import { A } from 'lib-a';
import { C } from 'lib-c';
import { B } from 'lib-b';
@B()
@C()
@A()
class Test {}Will be auto-fixed to:
@A()
@C()
@B()
class Test {}Supports both import and require statements.
Contributing
PRs and issues welcome!
License
MIT
