8000 chore: enable sonarjs/no-duplicated-branches (#9821) · abrahamguo/typescript-eslint@fd55358 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd55358

Browse files
authored
chore: enable sonarjs/no-duplicated-branches (typescript-eslint#9821)
1 parent 692a3f5 commit fd55358

File tree

8 files changed

+25
-45
lines changed

8 files changed

+25
-45
lines c 10000 hanged

eslint.config.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import perfectionistPlugin from 'eslint-plugin-perfectionist';
1616
import reactPlugin from 'eslint-plugin-react';
1717
import reactHooksPlugin from 'eslint-plugin-react-hooks';
1818
import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
19+
import sonarjsPlugin from 'eslint-plugin-sonarjs';
1920
import unicornPlugin from 'eslint-plugin-unicorn';
2021
import globals from 'globals';
2122
import tseslint from 'typescript-eslint';
@@ -43,6 +44,7 @@ export default tseslint.config(
4344
// https://github.com/jsx-eslint/eslint-plugin-react/issues/3699
4445
['react']: fixupPluginRules(reactPlugin),
4546
['simple-import-sort']: simpleImportSortPlugin,
47+
['sonarjs']: sonarjsPlugin,
4648
['unicorn']: unicornPlugin,
4749
},
4850
/* eslint-enable no-useless-computed-key */
@@ -304,18 +306,20 @@ export default tseslint.config(
304306
'jsdoc/check-tag-names': 'off',
305307
// https://github.com/gajus/eslint-plugin-jsdoc/issues/1169
306308
'jsdoc/check-param-names': 'off',
309+
'jsdoc/informative-docs': 'error',
307310
// https://github.com/gajus/eslint-plugin-jsdoc/issues/1175
308311
'jsdoc/require-jsdoc': 'off',
309312
'jsdoc/require-param': 'off',
310313
'jsdoc/require-returns': 'off',
311314
'jsdoc/require-yields': 'off',
312315
'jsdoc/tag-lines': 'off',
313316

317+
'sonarjs/no-duplicated-branches': 'error',
318+
314319
//
315320
// eslint-plugin-unicorn
316321
//
317322

318-
'jsdoc/informative-docs': 'error',
319323
'unicorn/no-lonely-if': 'error',
320324
'unicorn/no-typeof-undefined': 'error',
321325
'unicorn/no-useless-spread': 'error',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"eslint-plugin-react": "^7.34.1",
104104
"eslint-plugin-react-hooks": "^4.6.0",
105105
"eslint-plugin-simple-import-sort": "^10.0.0",
106+
"eslint-plugin-sonarjs": "^1.0.4",
106107
"eslint-plugin-unicorn": "^50.0.1",
107108
"execa": "7.2.0",
108109
"glob": "^10.3.12",

packages/ast-spec/tests/util/serializers/string.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,7 @@ const serializer: NewPlugin = {
1111
// refs,
1212
// printer,
1313
) {
14-
const characters: string[] = [];
15-
16-
characters.push("'");
17-
for (const character of str) {
18-
switch (character) {
19-
case "'":
20-
characters.push('\\');
21-
break;
22-
23-
case '\\':
24-
characters.push('\\');
25-
break;
26-
}
27-
characters.push(character);
28-
}
29-
characters.push("'");
30-
31-
return characters.join('');
14+
return `'${str.replaceAll(/'|\\/g, '\\$&')}'`;
3215
},
3316
test(val: unknown) {
3417
return typeof val === 'string';

packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default createRule({
7474
};
7575
}
7676
case AST_NODE_TYPES.TSMethodSignature:
77+
case AST_NODE_TYPES.MethodDefinition:
7778
return {
7879
...getNameFromMember(member, context.sourceCode),
7980
static: !!member.static,
@@ -91,12 +92,6 @@ export default createRule({
9192
callSignature: false,
9293
type: MemberNameType.Normal,
9394
};
94-
case AST_NODE_TYPES.MethodDefinition:
95-
return {
96-
...getNameFromMember(member, context.sourceCode),
97-
static: !!member.static,
98-
callSignature: false,
99-
};
10095
}
10196

10297
return null;

packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ export default createRule<Options, MessageIds>({
375375
return;
376376

377377
case AST_NODE_TYPES.PropertyDefinition:
378+
case AST_NODE_TYPES.MethodDefinition:
379+
case AST_NODE_TYPES.TSAbstractMethodDefinition:
378380
if (
379381
node.accessibility === 'private' ||
380382
node.key.type === AST_NODE_TYPES.PrivateIdentifier
@@ -395,16 +397,6 @@ export default createRule<Options, MessageIds>({
395397
return checkFunction({ node, returns });
396398
}
397399

398-
case AST_NODE_TYPES.MethodDefinition:
399-
case AST_NODE_TYPES.TSAbstractMethodDefinition:
400-
if (
401-
node.accessibility === 'private' ||
402-
node.key.type === AST_NODE_TYPES.PrivateIdentifier
403-
) {
404-
return;
405-
}
406-
return checkNode(node.value);
407-
408400
case AST_NODE_TYPES.Identifier:
409401
return followReference(node);
410402

packages/eslint-plugin/src/rules/no-non-null-assertion.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,8 @@ export default createRule<[], MessageIds>({
7979
},
8080
});
8181
}
82-
} else if (node.parent.computed) {
83-
// it is x!?.[y].z
84-
suggest.push({
85-
messageId: 'suggestOptionalChain',
86-
fix: removeToken(),
87-
});
8882
} else {
89-
// it is x!?.y.z
83+
// it is x!?.[y].z or x!?.y.z
9084
suggest.push({
9185
messageId: 'suggestOptionalChain',
9286
fix: removeToken(),

packages/scope-manager/src/referencer/Referencer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,10 @@ class Referencer extends Visitor {
529529
}
530530

531531
protected JSXMemberExpression(node: TSESTree.JSXMemberExpression): void {
532-
if (node.object.type !== AST_NODE_TYPES.JSXIdentifier) {
533-
this.visit(node.object);
534-
} else if (node.object.name !== 'this') {
532+
if (
533+
node.object.type !== AST_NODE_TYPES.JSXIdentifier ||
534+
node.object.name !== 'this'
535+
) {
535536
this.visit(node.object);
536537
}
537538
// we don't ever reference the property as it's always going to be a property on the thing

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5882,6 +5882,7 @@ __metadata:
58825882
eslint-plugin-react: ^7.34.1
58835883
eslint-plugin-react-hooks: ^4.6.0
58845884
eslint-plugin-simple-import-sort: ^10.0.0
5885+
eslint-plugin-sonarjs: ^1.0.4
58855886
eslint-plugin-unicorn: ^50.0.1
58865887
execa: 7.2.0
58875888
glob: ^10.3.12
@@ -9931,6 +9932,15 @@ __metadata:
99319932
languageName: node
99329933
linkType: hard
99339934

9935+
"eslint-plugin-sonarjs@npm:^1.0.4":
9936+
version: 1.0.4
9937+
resolution: "eslint-plugin-sonarjs@npm:1.0.4"
9938+
peerDependencies:
9939+
eslint: ^8.0.0 || ^9.0.0
9940+
checksum: d9572b3342e434bd2f09015bd3f429056e3b81261c7ff6e541d9a567f0279c27e334793ceb76866c845314076bdc9550be469c075e12915a1498d5fb06e265a0
9941+
languageName: node
9942+
linkType: hard
9943+
99349944
"eslint-plugin-unicorn@npm:^50.0.1":
99359945
version: 50.0.1
99369946
resolution: "eslint-plugin-unicorn@npm:50.0.1"

0 commit comments

Comments
 (0)
0