Avoid assignment when you could just return.
You'll first need to install ESLint:
$ npm i eslint --save-dev
Next, install eslint-plugin-return-early-dont-assign
:
$ npm install eslint-plugin-return-early-dont-assign --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-return-early-dont-assign
globally.
Add return-early-dont-assign
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": [
"return-early-dont-assign"
]
}
Then configure the rules you want to use under the rules section. eg.
{
"rules": {
"return-early-dont-assign/return-early-dont-assign": 2
}
}
- return-early-dont-assign
Check docs for synopsis.
This is my first ESLint plugin/rule and the following links helped make it happen: