eslint configuration to ensure SonarJS rules are met, following the 'Sonar way' preset.
npm install eslint-config-sonar --save-dev
Then add the following to your .eslintrc:
{
"extends": [
"sonar",
]
}
This package is in development. The intention is for it to eventually include:
- Documentation of all SonarJS rules and their equivalent in eslint.
- Ports of any rules not covered by existing eslint rules.
- eslint configs for Sonar way (eslint-config-sonar) and Sonar way Recommended (eslint-config-sonar:recommended) profiles.
PRs are welcomed and I'd also encourage @SonarSource to take over ownership of this.
Initially I am only aiming to include those listed in the Sonar way preset, rather than every rule supported by SonarJS, purely because this is the preset I'm currently using.
Where I have found an equivalent in eslint, it has been listed here and included in the config.
Where no equivalent is listed, it is listed in the next section and has not yet been implemented in the eslint config.
no-delete-var
eslint throws a parsing error in strict mode.
use-isnan
constructor-super
no-this-before-super
no-new-symbol
no-with
eslint throws a parsing error in strict mode.
eslint throws a parsing error:
Parsing error: yield is a reserved word (Fatal)
for-direction
sonarjs/no-all-duplicated-branches
no-const-assign
no-bitwise
array-callback-return
sonarjs/no-element-overwrite
Partially covered by no-sequences
.
no-empty-pattern
no-dupe-args
eslint throws a parsing error in strict mode.
Parsing error: Argument name clash in strict mode (Fatal)
sonarjs/no-extra-arguments
require-yield
Partially covered by no-self-compare
.
sonarjs/no-identical-expressions
no-unreachable
no-unsafe-finally
Partially covered by no-unreachable
.
no-unused-expressions
space-unary-ops
space-infix-ops
no-dupe-keys
sonarjs/no-identical-conditions
no-unsafe-negation
eslint throws a parsing error in strict mode:
Parsing error: eval is a reserved word in strict mode (Fatal)
sonarjs/no-use-of-empty-return-value
no-self-assign
sonarjs/no-useless-catch
All of these are picked up as parsing errors when in strict mode.
sonarjs/no-small-switch
no-restricted-syntax
no-labels
sonarjs/max-switch-cases
sonarjs/prefer-while
sonarjs/no-inverted-boolean-check
Partial coverage from no-constant-condition
no-sequences
no-unused-vars
filenames/match-exported
no-extra-semi
no-unexpected-multiline
Partial coverage with new-cap
.
no-loop-func
Partial coverage with no-continue
.
no-restricted-syntax
no-labels
no-multi-str
no-empty
eslint will throw a parsing error (Invalid number)
sonarjs/prefer-single-boolean-return
no-fallthrough
sonarjs/no-duplicated-branches
no-unused-vars
no-redeclare
no-undef
no-new-wrappers
no-alert
no-wildcard-postmessage
from eslint-plugin-no-wildcard-postmessage
no-debugger
Please open an issue if you know of an equivalent eslint rule.