Skip to content

Commit

Permalink
Update SonarJS to v2 (#2)
Browse files Browse the repository at this point in the history
* more (probably required) globals

* implement new SonarJS rules

* moved html rules and jsx rules to their own files

* disallow variable name "_"

* added react version to shut up a warn in the eslint logs
  • Loading branch information
Mephisto5558 authored Oct 20, 2024
1 parent 395032d commit daee38f
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 29 deletions.
7 changes: 3 additions & 4 deletions configs/@typescript-eslint.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
// [TYPESCRIPT-ESLINT] https://typescript-eslint.io/rules | Using "warn" wherever applicable
"adjacent-overload-signatures": "warn",
"array-type": [
"error",
{
Expand Down Expand Up @@ -163,9 +162,9 @@
"vars": "all",
"args": "all",
"caughtErrors": "all",
"argsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_",
"varsIgnorePattern": "^_"
"argsIgnorePattern": "^_.+",
"destructuredArrayIgnorePattern": "^_.+",
"varsIgnorePattern": "^_.+"
}
],
"no-use-before-define": [
Expand Down
30 changes: 15 additions & 15 deletions configs/eslint.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// [ESLint] https://eslint.org/docs/latest/rules/ | Using "warn" wherever applicable
// Possible Problems
"array-callback-return": "error",
"constructor-super": "error",
"constructor-super": "off", // Handled by `sonarjs/super-invocation`
"for-direction": "error",
"getter-return": "error",
"no-async-promise-executor": "error",
Expand Down Expand Up @@ -56,7 +56,7 @@
"no-setter-return": "warn",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "warn",
"no-this-before-super": "error",
"no-this-before-super": "off", // Handled by `sonarjs/super-invocation`
"no-undef": [
"error",
{
Expand Down Expand Up @@ -135,7 +135,7 @@
}
],
"id-match": "off", // Handled by `camelcase`
"init-declarations": "off", // Handeled by `@typescript-eslint/init-declarations`
"init-declarations": "off", // Handled by `@typescript-eslint/init-declarations`
"logical-assignment-operators": [
"error",
"always",
Expand All @@ -161,11 +161,11 @@
"warn",
2
], // promises are to use whenever possible
"max-params": "off", // Handeled by `@typescript-eslint/max-params`
"max-params": "off", // Handled by `@typescript-eslint/max-params`
"max-statements": "off",
"new-cap": "error",
"no-alert": "error",
"no-array-constructor": "off", // Handeled by `@typescript-eslint/no-array-constructor`
"no-array-constructor": "off", // Handled by `@typescript-eslint/no-array-constructor`
"no-bitwise": "off",
"no-caller": "error",
"no-case-declarations": "error",
Expand All @@ -175,7 +175,7 @@
"no-div-regex": "warn",
"no-else-return": "error",
"no-empty": "error",
"no-empty-function": "off", // Handeled by `@typescript-eslint/no-empty-function`
"no-empty-function": "off", // Handled by `@typescript-eslint/no-empty-function`
"no-empty-static-block": "error",
"no-eq-null": "off", // Handled by `unicorn/no-null`
"no-eval": "error",
Expand All @@ -188,14 +188,14 @@
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-invalid-this": "off", // Handeled by `@typescript-eslint/no-invalid-this`
"no-invalid-this": "off", // Handled by `@typescript-eslint/no-invalid-this`
"no-iterator": "error",
"no-label-var": "warn",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "error",
"no-loop-func": "off", // Handeled by `@typescript-eslint/no-loop-func`
"no-magic-numbers": "off", // Handeled by `@typescript-eslint/no-magic-numbers`
"no-loop-func": "off", // Handled by `@typescript-eslint/no-loop-func`
"no-magic-numbers": "off", // Handled by `@typescript-eslint/no-magic-numbers`
"no-multi-assign": "error",
"no-multi-str": "error",
"no-negated-condition": "off", // Handled by `unicorn/no-negated-condition` because unicorn has an autofix option for it
Expand All @@ -210,11 +210,11 @@
"no-param-reassign": "off",
"no-plusplus": "off",
"no-proto": "error",
"no-redeclare": "off", // Handeled by `@typescript-eslint/no-redeclare`
"no-regex-spaces": "error",
"no-redeclare": "off", // Handled by `@typescript-eslint/no-redeclare`
"no-regex-spaces": "off", // Handled by `regexp/prefer-quantifier`
"no-restricted-exports": "off",
"no-restricted-globals": "off",
"no-restricted-imports": "off", // Handeled by `@typescript-eslint/no-restricted-imports`
"no-restricted-imports": "off", // Handled by `@typescript-eslint/no-restricted-imports`
"no-restricted-properties": "off",
"no-restricted-syntax": "off",
"no-return-assign": "error",
Expand All @@ -223,21 +223,21 @@
"no-shadow": "off", // Handled by `@typescript-eslint/no-shadow`
"no-shadow-restricted-names": "error",
"no-ternary": "off",
"no-throw-literal": "error",
"no-throw-literal": "off", // Handled by `@typescript-eslint/only-throw-error
"no-undef-init": "error",
"no-undefined": "off",
"no-underscore-dangle": "off",
"no-unneeded-ternary": "error",
"no-unused-expressions": "off", // Handled by `@typescript-eslint/no-unused-expressions`
"no-unused-labels": "error",
"no-useless-call": "error",
"no-useless-call": "warn",
"no-useless-catch": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "off", // Handled by `@typescript-eslint/no-useless-constructor`
"no-useless-escape": "off", // Handled by `regexp/no-useless-escape`
"no-useless-rename": "error",
"no-useless-return": "error",
"no-useless-return": "off", // Handled by `sonarjs/no-redundant-jump`
"no-var": "error",
"no-void": "off",
"no-warning-comments": "off",
Expand Down
2 changes: 1 addition & 1 deletion configs/regexp.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"target": "alphanumeric"
}
],
"prefer-regexp-exec": "off", // Handled by `regexp/prefer-regexp-test`
"prefer-regexp-exec": "off", // Handled by `sonarjs/sonar-prefer-regexp-exec` until this one is auto-fixable.
"prefer-regexp-test": "warn",
"prefer-set-operation": "off", // I have no idea how they work, and regex101 doesn't support them.
"require-unicode-regexp": "off", // No real need to
Expand Down
11 changes: 11 additions & 0 deletions configs/sonarjs-html.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"alt-text": "warn",
"anchor-has-content": "warn", // Seems to not work
"anchor-is-valid": "error",
"label-has-associated-control": "warn",
"media-has-caption": "warn",
"mouse-events-a11y": "warn",
"object-alt-content": "warn",
"table-header": "warn",
"table-header-reference": "warn"
}
18 changes: 18 additions & 0 deletions configs/sonarjs-react.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"jsx-key": "",
"jsx-no-constructed-context-values": "",
"jsx-no-useless-fragment": "",
"no-array-index-key": "",
"no-deprecated-react": "",
"no-find-dom-node": "",
"no-hook-setter-in-body": "",
"no-uniq-key": "",
"no-unknown-property": "",
"no-unsafe": "",
"no-unstable-nested-components": "",
"no-useless-react-setstate": "",
"rules-of-hooks": "",
"sonar-jsx-no-leaked-render": "",
"sonar-no-unused-class-component-methods": "",
"sonar-prefer-read-only-props": ""
}
Loading

0 comments on commit daee38f

Please sign in to comment.