8000 Eslint plugin sonarjs by abrahamguo · Pull Request #4 · abrahamguo/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Eslint plugin sonarjs #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d48d8b7
WIP
abrahamguo Apr 7, 2024
a475419
enable plugin
abrahamguo Aug 16, 2024
78f9906
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Aug 19, 2024
ab534a5
WIP
abrahamguo Aug 19, 2024
60ebb72
WIP
abrahamguo Aug 19, 2024
849c53c
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Aug 19, 2024
cba1e00
WIP
abrahamguo Aug 19, 2024
9c388d3
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Aug 27, 2024
782e99d
upgrade to v2
abrahamguo Aug 27, 2024
e65b510
WIP
abrahamguo Aug 27, 2024
48c590a
enable all sonar
abrahamguo Aug 27, 2024
a3f8cea
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Aug 27, 2024
8026f3f
WIP
abrahamguo Aug 27, 2024
42fd94d
lint everything
abrahamguo Aug 27, 2024
63c1145
WIP
abrahamguo Aug 28, 2024
1d675f2
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Sep 2, 2024
4e5922b
update eslint-plugin-sonarjs
abrahamguo Sep 2, 2024
8484144
upgrade unicorn
abrahamguo Sep 2, 2024
708facd
name more generally
abrahamguo Sep 2, 2024
63b64fb
begin turning off rules
abrahamguo Sep 2, 2024
777a608
disable more
abrahamguo Sep 2, 2024
0a3bd71
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Sep 3, 2024
ce4a666
WIP
abrahamguo Sep 3, 2024
a548138
WIP
abrahamguo Sep 3, 2024
e72cd3a
WIP
abrahamguo Sep 3, 2024
8492eec
WIP
abrahamguo Sep 3, 2024
7eda55f
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Sep 5, 2024
3f08367
Merge branch 'eslint-plugin-regexp' of github.com:abrahamguo/typescri…
abrahamguo Sep 5, 2024
3a77a15
disable
abrahamguo Sep 5, 2024
27a3ec8
WIP
abrahamguo Sep 5, 2024
1428944
WIP
abrahamguo Sep 5, 2024
097b0ce
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Sep 6, 2024
58a29b9
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Sep 6, 2024
505eed4
disable some more stuff
abrahamguo Sep 6, 2024
4f8c56c
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Sep 9, 2024
dbac149
WIP
abrahamguo Sep 9, 2024
de3fef2
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Sep 16, 2024
4db8300
allow showing individual rule reports
abrahamguo Sep 16, 2024
86b0fb0
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into e…
abrahamguo Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export default tseslint.config(
['regexp']: regexpPlugin,
['simple-import-sort']: simpleImportSortPlugin,
['sonarjs']: sonarjsPlugin,
['unicorn']: unicornPlugin,
},
/* eslint-enable no-useless-computed-key */
},
unicornPlugin.configs['flat/all'],
{
// config with just ignores is the replacement for `.eslintignore`
ignores: [
Expand Down Expand Up @@ -80,6 +80,7 @@ export default tseslint.config(
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
jsdocPlugin.configs['flat/recommended-typescript-error'],
regexpPlugin.configs['flat/all'],

// base config
{
Expand Down Expand Up @@ -330,6 +331,18 @@ export default tseslint.config(
'regexp/prefer-w': 'error',

'sonarjs/no-duplicated-branches': 'error',
...Object.fromEntries(
Object.entries(sonarjsPlugin.rules).flatMap(([name, { meta }]) =>
/^S\d{3,4}$/.test(name) ||
meta.deprecated ||
eslint.configs.all.rules[name] ||
/^(no-inconsistent-returns|pluginRules-of-hooks|prefer-enum-initializers|sonar-no-fallthrough)$/.test(
name,
)
? []
: [[`sonarjs/${name}`, 'error']],
),
),

//
// eslint-plugin-unicorn
Expand Down Expand Up @@ -407,6 +420,7 @@ export default tseslint.config(
'jest/prefer-spy-on': 'error',
'jest/valid-expect': 'error',
'jest/no-deprecated-functions': 'error',
'sonarjs/no-duplicate-string': 'off',
},
},
// plugin rule tests
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-sonarjs": "^1.0.4",
"eslint-plugin-unicorn": "^55.0.0",
"eslint-plugin-sonarjs": "latest",
"eslint-plugin-unicorn": "latest",
"execa": "7.2.0",
"glob": "^10.3.12",
"globals": "^15.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/TSLINT_RULE_ALTERNATIVES.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ It lists all TSLint rules along side rules from the ESLint ecosystem that are th
| [`no-shadowed-variable`] | 🌟 | [`no-shadow`][no-shadow] |
| [`no-sparse-arrays`] | 🌟 | [`no-sparse-arrays`][no-sparse-arrays] |
| [`no-string-literal`] | 🌟 | [`dot-notation`][dot-notation] |
| [`no-string-throw`] | ✅ | [`@typescript-eslint/only-throw-error`] |
| [`no-string-throw`] | ✅ | [`@typescript-eslint/only-throw-error`] |
| [`no-submodule-imports`] | 🌓 | [`import/no-internal-modules`] (slightly different) |
| [`no-switch-case-fall-through`] | 🌟 | [`no-fallthrough`][no-fallthrough] |
| [`no-tautology-expression`] | 🛑 | N/A |
Expand Down
34 changes: 34 additions & 0 deletions tools/eslint-plugins/index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable unicorn/prevent-abbreviations */
const messagesByRuleId = Object.entries(
(
Object as typeof Object & {
groupBy: <T>(arr: T[], fn: (item: T) => string) => Record<string, T[]>;
}
).groupBy(
(
(await import(`../../.nx/cache/eslint-plugins.json`)) as {
default: { messages: { ruleId: string }[] }[];
}
).default.flatMap(({ messages }) => messages),
({ ruleId }) => ruleId,
),
).map(([ruleId, messages]) => ({ ruleId, messages }));
console.log(
Object.fromEntries(
messagesByRuleId
.filter(({ ruleId }) =>
[
/* eslint-disable sonarjs/regex-complexity,regexp/require-unicode-regexp,regexp/require-unicode-sets-regexp,regexp/prefer-named-capture-group */
/^regexp\/(prefer-character-class|require-unicode-(sets-)?regexp)$/,
/^(sonarjs\/(bool-param-default|c(ognitive|yclomatic)-complexity|elseif-without-else|expression-complexity|file-header|fixme-tag|for-in|function-return-type|max-(switch-cases|union-size)|nested-control-flow|no-(alphabetical-sort|array-index-key|empty-interface|nested-(assignment|conditional|functions|incdec|switch|template-literals))|regex-complexity|sonar-max-lines(-per-function)?|switch-without-default|too-many-break-or-continue-in-loop))$/,
/^(unicorn\/(better-regex|catch-error-name|numeric-separators-style|no-(array-(callback-reference|for-each|length-as-slice-end|method-this-argument|push-push|reduce)|await-expression-member|for-loop|keyword-prefix|negated-condition|nested-ternary|null|process-exit|static-only-class|useless-switch-case)|prefer-(native-coercion-functions|set-has|str(ing-raw|uctured-clone)|switch|ternary)|prevent-abbreviations|set-has|switch-case-braces))$/,
/* eslint-enable sonarjs/regex-complexity,regexp/require-unicode-regexp,regexp/require-unicode-sets-regexp,regexp/prefer-named-capture-group */
].every(regexp => !regexp.test(ruleId)),
)
.sort((a, b) => a.ruleId.localeCompare(b.ruleId))
.map(({ ruleId, messages }) => [ruleId, messages.length]),
),
messagesByRuleId.flatMap(({ ruleId, messages }) =>
ruleId.split('/').at(-1) === process.argv[2] ? messages : [],
),
);
Loading
0