eslint-plugin-sonarjs-6
v0.6.0
Published
SonarJS rules for ESLint (especially version 6)
Downloads
7
Readme
eslint-plugin-sonarjs
THIS PACKAGE IS FORK: SO IT SUPPORTS ESLINT V6
SonarJS rules for ESLint to detect bugs and suspicious patterns in your code.
We also have a plugin for TSLint
Rules
Bug Detection :bug:
Rules in this category aim to find places in code which have a high chance of being bugs, i.e. don't work as intended.
- All branches in a conditional structure should not have exactly the same implementation (
no-all-duplicated-branches
) - Collection elements should not be replaced unconditionally (
no-element-overwrite
) - Function calls should not pass extra arguments (
no-extra-arguments
) - Related "if/else if" statements should not have the same condition (
no-identical-conditions
) - Identical expressions should not be used on both sides of a binary operator (
no-identical-expressions
) - Loops with at most one iteration should be refactored (
no-one-iteration-loop
) - The output of functions that don't return anything should not be used (
no-use-of-empty-return-value
)
Code Smell Detection :pig:
Code Smells, or maintainability issues, are raised for places of code which might be costly to change in the future. These rules also help to keep the high code quality and readability. And finally some rules report issues on different suspicious code patters.
- Cognitive Complexity of functions should not be too high (
cognitive-complexity
) - "switch" statements should not have too many "case" clauses (
max-switch-cases
) - Collapsible "if" statements should be merged (
no-collapsible-if
) - String literals should not be duplicated (
no-duplicate-string
) - Two branches in a conditional structure should not have exactly the same implementation (
no-duplicated-branches
) - Functions should not have identical implementations (
no-identical-functions
) - Boolean checks should not be inverted (
no-inverted-boolean-check
) - Boolean literals should not be redundant (
no-redundant-boolean
) - "switch" statements should have at least 3 "case" clauses (
no-small-switch
) - "catch" clauses should do more than rethrow (
no-useless-catch
) - Local variables should not be declared and then immediately returned or thrown (
prefer-immediate-return
) (:wrench: fixable) - Object literal syntax should be used (
prefer-object-literal
) - Return of boolean expressions should not be wrapped into an "if-then-else" statement (
prefer-single-boolean-return
) - A "while" loop should be used instead of a "for" loop (
prefer-while
) (:wrench: fixable)
Prerequisites
Node.js (>=6.x).
Usage
- If you don't have ESLint yet configured for your project, follow these instructions.
- Install
eslint-plugin-sonarjs
usingnpm
(oryarn
) for you project or globally:
npm install eslint-plugin-sonarjs --save-dev # install for your project
npm install eslint-plugin-sonarjs -g # or install globally
- Add
eslint-plugin-sonarjs
to theplugins
option of your.eslintrc
:
{
"plugins": ["sonarjs"]
}
- Add
plugin:sonarjs/recommended
to theextends
option to enable all recommended rules:
{
"extends": ["plugin:sonarjs/recommended"]
}
- or enable only some rules manually:
{
"rules": {
"sonarjs/cognitive-complexity": "error",
"sonarjs/no-identical-expressions": "error"
// etc
}
}
Contributing
You want to participate in the development of the project? Have a look at our contributing guide!