Eslint plugin for FSD best practices
You'll first need to install ESLint:
$ npm i eslint --save-dev
Next, install eslint-plugin-fsd
:
$ npm install eslint-plugin-fsd --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-fsd
globally.
Add fsd
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": ["fsd"]
}
You can configure rules in 2 ways:
- Configure each rule you want to use under the rules section.
{
"rules": {
"fsd/hof-name-prefix": "error",
"fsd/no-heavy-constructor": "error",
"fsd/jq-cache-dom-elements": "error",
"fsd/jq-use-js-prefix-in-selector": "error",
"fsd/no-function-declaration-in-event-listener": "error",
"fsd/split-conditionals": "error"
}
}
- Use shared config from this plugin.
{
"extends": ["plugin:fsd/all"]
}
- hof-name-prefix - enforce
make
prefix in higher order function names - jq-use-js-prefix-in-selector - enforce
js-
prefix in classes that are used to search the DOM - jq-cache-dom-elements - enforce caching of all found DOM elements
- split-conditionals - disallow complex conditions
- no-heavy-constructor - disallow searching the DOM tree and defining handlers in the constructor
- no-function-declaration-in-event-listener - enforce moving event handlers to separate functions
If you want to contribute, check out readme-dev.