chore: eslint add sonar (#17989)

This commit is contained in:
Joel
2025-04-14 15:28:20 +08:00
committed by GitHub
parent 8f9cbe1c49
commit d80f4c7d3b
38 changed files with 157 additions and 180 deletions

View File

@@ -7,6 +7,8 @@ import storybook from 'eslint-plugin-storybook'
// import { fixupConfigRules } from '@eslint/compat'
import tailwind from 'eslint-plugin-tailwindcss'
import reactHooks from 'eslint-plugin-react-hooks'
import sonar from 'eslint-plugin-sonarjs'
// import reactRefresh from 'eslint-plugin-react-refresh'
export default combine(
@@ -138,7 +140,48 @@ export default combine(
'react-hooks': reactHooks,
},
},
// need futher research
// sonar
{
rules: {
...sonar.configs.recommended.rules,
// code complexity
'sonarjs/cognitive-complexity': 'off',
'sonarjs/no-nested-functions': 'warn',
'sonarjs/no-nested-conditional': 'warn',
'sonarjs/nested-control-flow': 'warn', // 3 levels of nesting
'sonarjs/no-small-switch': 'off',
'sonarjs/no-nested-template-literals': 'warn',
'sonarjs/redundant-type-aliases': 'off',
'sonarjs/regex-complexity': 'warn',
// maintainability
'sonarjs/no-ignored-exceptions': 'off',
'sonarjs/no-commented-code': 'warn',
'sonarjs/no-unused-vars': 'warn',
'sonarjs/prefer-single-boolean-return': 'warn',
'sonarjs/duplicates-in-character-class': 'off',
'sonarjs/single-char-in-character-classes': 'off',
'sonarjs/anchor-precedence': 'warn',
'sonarjs/updated-loop-counter': 'off',
'sonarjs/no-dead-store': 'warn',
'sonarjs/no-duplicated-branches': 'warn',
'sonarjs/max-lines': 'warn', // max 1000 lines
'sonarjs/no-variable-usage-before-declaration': 'error',
// security
// eslint-disable-next-line sonarjs/no-hardcoded-passwords
'sonarjs/no-hardcoded-passwords': 'off', // detect the wrong code that is not password.
'sonarjs/no-hardcoded-secrets': 'off',
'sonarjs/pseudo-random': 'off',
// performance
'sonarjs/slow-regex': 'warn',
// others
'sonarjs/todo-tag': 'warn',
'sonarjs/table-header': 'off',
},
plugins: {
sonarjs: sonar,
},
},
// need further research
{
rules: {
// not exist in old version
@@ -150,6 +193,7 @@ export default combine(
// useful, but big change
'unicorn/prefer-number-properties': 'warn',
'unicorn/no-new-array': 'warn',
'style/indent': 'off',
},
},
// suppress error for `no-undef` rule