eslint-plugin-sonarjs 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cjs/S100/rule.js +7 -5
- package/cjs/S101/rule.js +2 -2
- package/cjs/S104/rule.js +2 -2
- package/cjs/S105/rule.js +2 -2
- package/cjs/S1066/rule.js +5 -4
- package/cjs/S1067/rule.js +8 -6
- package/cjs/S1110/rule.js +7 -5
- package/cjs/S1119/rule.js +2 -2
- package/cjs/S1121/rule.js +4 -3
- package/cjs/S1125/rule.js +9 -8
- package/cjs/S1126/rule.js +2 -2
- package/cjs/S1128/rule.js +8 -5
- package/cjs/S1134/rule.js +2 -2
- package/cjs/S1135/rule.js +2 -2
- package/cjs/S1154/rule.js +6 -4
- package/cjs/S117/rule.js +6 -5
- package/cjs/S1172/rule.js +2 -2
- package/cjs/S1192/rule.js +5 -4
- package/cjs/S1219/rule.js +4 -3
- package/cjs/S1226/rule.js +6 -4
- package/cjs/S124/rule.js +2 -2
- package/cjs/S125/rule.js +9 -7
- package/cjs/S126/rule.js +2 -2
- package/cjs/S1264/rule.js +2 -2
- package/cjs/S128/rule.js +4 -3
- package/cjs/S1291/rule.js +2 -2
- package/cjs/S1301/rule.js +2 -2
- package/cjs/S1313/rule.js +2 -2
- package/cjs/S134/rule.js +7 -5
- package/cjs/S135/rule.js +5 -4
- package/cjs/S138/rule.js +9 -6
- package/cjs/S1439/rule.js +2 -2
- package/cjs/S1444/rule.js +2 -2
- package/cjs/S1451/rule.js +2 -2
- package/cjs/S1472/rule.js +2 -2
- package/cjs/S1479/rule.js +2 -2
- package/cjs/S1481/rule.js +2 -2
- package/cjs/S1488/rule.js +11 -7
- package/cjs/S1515/rule.js +10 -8
- package/cjs/S1523/rule.js +5 -5
- package/cjs/S1526/rule.js +5 -4
- package/cjs/S1527/rule.js +2 -2
- package/cjs/S1528/rule.js +2 -2
- package/cjs/S1529/rule.js +4 -3
- package/cjs/S1530/rule.js +5 -3
- package/cjs/S1533/rule.js +2 -2
- package/cjs/S1535/rule.js +2 -2
- package/cjs/S1541/rule.js +10 -7
- package/cjs/S1607/rule.js +22 -20
- package/cjs/S1764/rule.js +10 -7
- package/cjs/S1821/rule.js +2 -2
- package/cjs/S1848/rule.js +10 -7
- package/cjs/S1854/rule.js +18 -14
- package/cjs/S1862/rule.js +10 -8
- package/cjs/S1871/rule.js +21 -16
- package/cjs/S1874/rule.js +4 -3
- package/cjs/S1940/rule.js +2 -2
- package/cjs/S1994/rule.js +10 -7
- package/cjs/S2004/rule.js +9 -7
- package/cjs/S2068/rule.js +75 -12
- package/cjs/S2077/rule.js +10 -6
- package/cjs/S2092/rule.js +2 -2
- package/cjs/S2123/rule.js +2 -2
- package/cjs/S2137/rule.js +2 -2
- package/cjs/S2138/rule.js +4 -3
- package/cjs/S2187/rule.js +2 -2
- package/cjs/S2201/rule.js +8 -5
- package/cjs/S2208/rule.js +2 -2
- package/cjs/S2234/rule.js +15 -11
- package/cjs/S2245/rule.js +4 -3
- package/cjs/S2251/rule.js +5 -4
- package/cjs/S2255/rule.js +6 -5
- package/cjs/S2259/rule.js +14 -9
- package/cjs/S2301/rule.js +14 -9
- package/cjs/S2310/rule.js +14 -11
- package/cjs/S2392/rule.js +7 -5
- package/cjs/S2424/rule.js +2 -2
- package/cjs/S2428/rule.js +8 -6
- package/cjs/S2486/rule.js +4 -3
- package/cjs/S2589/rule.js +12 -10
- package/cjs/S2598/rule.js +17 -14
- package/cjs/S2612/generated-meta.js +1 -1
- package/cjs/S2612/rule.js +8 -6
- package/cjs/S2639/rule.js +2 -2
- package/cjs/S2681/rule.js +2 -2
- package/cjs/S2692/rule.js +6 -4
- package/cjs/S2699/rule.js +40 -31
- package/cjs/S2703/rule.js +2 -2
- package/cjs/S2737/rule.js +6 -4
- package/cjs/S2755/rule.js +9 -6
- package/cjs/S2757/rule.js +2 -2
- package/cjs/S2817/rule.js +10 -7
- package/cjs/S2819/rule.js +16 -12
- package/cjs/S2870/rule.js +8 -5
- package/cjs/S2871/rule.js +12 -9
- package/cjs/S2970/rule.js +9 -8
- package/cjs/S2990/rule.js +2 -2
- package/cjs/S2999/rule.js +10 -7
- package/cjs/S3001/rule.js +2 -2
- package/cjs/S3003/rule.js +10 -7
- package/cjs/S3317/rule.js +4 -3
- package/cjs/S3330/rule.js +2 -2
- package/cjs/S3358/rule.js +2 -2
- package/cjs/S3402/rule.js +14 -10
- package/cjs/S3403/rule.js +10 -7
- package/cjs/S3415/rule.js +16 -13
- package/cjs/S3499/rule.js +5 -4
- package/cjs/S3500/rule.js +5 -4
- package/cjs/S3513/rule.js +5 -4
- package/cjs/S3514/rule.js +10 -7
- package/cjs/S3516/rule.js +10 -7
- package/cjs/S3524/rule.js +2 -2
- package/cjs/S3525/rule.js +6 -4
- package/cjs/S3531/rule.js +5 -3
- package/cjs/S3533/rule.js +8 -7
- package/cjs/S3579/rule.js +6 -4
- package/cjs/S3616/rule.js +6 -4
- package/cjs/S3626/rule.js +4 -3
- package/cjs/S3686/rule.js +7 -5
- package/cjs/S3699/rule.js +4 -3
- package/cjs/S3735/rule.js +8 -5
- package/cjs/S3757/rule.js +8 -6
- package/cjs/S3758/rule.js +9 -7
- package/cjs/S3760/rule.js +24 -21
- package/cjs/S3776/rule.js +26 -22
- package/cjs/S3782/rule.js +6 -4
- package/cjs/S3785/rule.js +9 -6
- package/cjs/S3796/rule.js +12 -8
- package/cjs/S3798/rule.js +4 -3
- package/cjs/S3800/rule.js +16 -11
- package/cjs/S3801/rule.js +15 -11
- package/cjs/S3827/rule.js +9 -6
- package/cjs/S3923/rule.js +9 -6
- package/cjs/S3972/rule.js +5 -4
- package/cjs/S3973/rule.js +7 -5
- package/cjs/S3981/rule.js +4 -3
- package/cjs/S3984/rule.js +4 -3
- package/cjs/S4030/rule.js +10 -7
- package/cjs/S4036/rule.js +7 -5
- package/cjs/S4043/rule.js +12 -8
- package/cjs/S4139/rule.js +7 -5
- package/cjs/S4143/rule.js +12 -9
- package/cjs/S4144/rule.js +12 -9
- package/cjs/S4158/rule.js +11 -8
- package/cjs/S4165/rule.js +14 -12
- package/cjs/S4322/rule.js +8 -5
- package/cjs/S4323/rule.js +4 -3
- package/cjs/S4324/rule.js +7 -5
- package/cjs/S4328/rule.js +2 -2
- package/cjs/S4335/rule.js +6 -4
- package/cjs/S4423/rule.js +4 -3
- package/cjs/S4423/rule.lib.js +8 -7
- package/cjs/S4426/rule.js +11 -10
- package/cjs/S4502/rule.js +16 -13
- package/cjs/S4507/rule.js +8 -6
- package/cjs/S4524/rule.js +2 -2
- package/cjs/S4619/rule.js +6 -4
- package/cjs/S4621/rule.js +5 -4
- package/cjs/S4622/rule.js +5 -3
- package/cjs/S4623/rule.js +8 -5
- package/cjs/S4624/rule.js +6 -4
- package/cjs/S4634/rule.js +4 -3
- package/cjs/S4721/rule.js +7 -5
- package/cjs/S4782/rule.js +7 -5
- package/cjs/S4784/rule.js +5 -4
- package/cjs/S4787/rule.js +9 -7
- package/cjs/S4790/rule.js +7 -5
- package/cjs/S4798/rule.js +2 -2
- package/cjs/S4817/rule.js +10 -8
- package/cjs/S4818/rule.js +4 -3
- package/cjs/S4822/rule.js +13 -9
- package/cjs/S4823/rule.js +4 -3
- package/cjs/S4829/rule.js +4 -3
- package/cjs/S4830/rule.js +11 -8
- package/cjs/S5042/rule.js +9 -7
- package/cjs/S5122/rule.js +40 -36
- package/cjs/S5148/rule.js +9 -8
- package/cjs/S5247/rule.js +22 -18
- package/cjs/S5256/rule.js +5 -4
- package/cjs/S5257/rule.js +4 -3
- package/cjs/S5260/rule.js +4 -3
- package/cjs/S5264/rule.js +4 -3
- package/cjs/S5332/rule.js +4 -3
- package/cjs/S5332/rule.lib.js +19 -17
- package/cjs/S5443/rule.js +2 -2
- package/cjs/S5527/rule.js +18 -14
- package/cjs/S5542/rule.js +6 -4
- package/cjs/S5547/rule.js +6 -4
- package/cjs/S5604/rule.js +15 -14
- package/cjs/S5659/rule.js +15 -12
- package/cjs/S5689/rule.js +11 -8
- package/cjs/S5691/rule.js +7 -5
- package/cjs/S5693/rule.js +14 -12
- package/cjs/S5725/rule.js +9 -6
- package/cjs/S5728/rule.js +7 -4
- package/cjs/S5730/rule.js +9 -6
- package/cjs/S5732/rule.js +8 -5
- package/cjs/S5734/rule.js +7 -4
- package/cjs/S5736/rule.js +8 -5
- package/cjs/S5739/rule.js +11 -8
- package/cjs/S5742/rule.js +7 -4
- package/cjs/S5743/rule.js +8 -6
- package/cjs/S5757/rule.js +13 -10
- package/cjs/S5759/rule.js +10 -7
- package/cjs/S5842/rule.js +2 -2
- package/cjs/S5843/rule.js +22 -19
- package/cjs/S5850/rule.js +4 -3
- package/cjs/S5852/rule.js +2 -2
- package/cjs/S5856/rule.js +10 -7
- package/cjs/S5860/rule.js +30 -26
- package/cjs/S5863/rule.js +15 -11
- package/cjs/S5867/rule.js +8 -7
- package/cjs/S5868/rule.js +7 -5
- package/cjs/S5869/rule.js +6 -5
- package/cjs/S5876/rule.js +12 -8
- package/cjs/S5958/rule.js +12 -9
- package/cjs/S5973/rule.js +10 -7
- package/cjs/S6019/rule.js +4 -3
- package/cjs/S6035/rule.js +2 -2
- package/cjs/S6079/rule.js +9 -6
- package/cjs/S6080/rule.js +13 -10
- package/cjs/S6092/rule.js +9 -7
- package/cjs/S6245/rule.js +14 -9
- package/cjs/S6249/rule.js +7 -5
- package/cjs/S6252/rule.js +12 -8
- package/cjs/S6265/rule.js +27 -20
- package/cjs/S6268/rule.js +5 -4
- package/cjs/S6270/rule.js +12 -9
- package/cjs/S6275/rule.js +2 -2
- package/cjs/S6281/rule.js +22 -17
- package/cjs/S6299/rule.js +2 -2
- package/cjs/S6302/rule.js +6 -5
- package/cjs/S6303/rule.js +12 -10
- package/cjs/S6304/rule.js +6 -5
- package/cjs/S6308/rule.js +7 -5
- package/cjs/S6317/rule.js +5 -4
- package/cjs/S6319/rule.js +2 -2
- package/cjs/S6321/rule.js +25 -23
- package/cjs/S6323/rule.js +4 -3
- package/cjs/S6324/rule.js +2 -2
- package/cjs/S6326/rule.js +2 -2
- package/cjs/S6327/rule.js +2 -2
- package/cjs/S6328/rule.js +4 -3
- package/cjs/S6329/rule.js +7 -5
- package/cjs/S6330/rule.js +2 -2
- package/cjs/S6332/rule.js +2 -2
- package/cjs/S6333/rule.js +8 -6
- package/cjs/S6351/rule.js +22 -19
- package/cjs/S6353/rule.js +2 -2
- package/cjs/S6397/rule.js +2 -2
- package/cjs/S6418/rule.js +9 -24
- package/cjs/S6426/rule.js +5 -4
- package/cjs/S6437/rule.js +10 -7
- package/cjs/S6439/rule.js +9 -7
- package/cjs/S6442/rule.js +11 -8
- package/cjs/S6443/rule.js +9 -7
- package/cjs/S6486/rule.js +5 -4
- package/cjs/S6564/rule.js +4 -3
- package/cjs/S6594/rule.js +12 -8
- package/cjs/S6627/rule.js +6 -4
- package/cjs/S6759/rule.js +10 -6
- package/cjs/S6958/rule.js +2 -2
- package/cjs/S6959/rule.js +9 -6
- package/cjs/S7059/rule.js +8 -5
- package/cjs/S7639/rule.js +5 -4
- package/cjs/S7790/rule.js +7 -5
- package/cjs/S8441/rule.js +13 -9
- package/cjs/S881/rule.js +2 -2
- package/cjs/S888/rule.js +4 -3
- package/cjs/S930/rule.js +14 -12
- package/cjs/helpers/ast.js +11 -8
- package/cjs/helpers/aws/s3.js +9 -6
- package/cjs/helpers/chai.js +41 -43
- package/cjs/helpers/cookie-flag-check.js +19 -17
- package/cjs/helpers/{decorators/index.js → entropy.js} +16 -17
- package/cjs/helpers/express.js +127 -128
- package/cjs/helpers/mocha.js +50 -54
- package/cjs/helpers/regex/ast.js +7 -6
- package/cjs/helpers/regex/extract.js +11 -11
- package/cjs/helpers/regex/group.js +2 -2
- package/cjs/helpers/regex/location.js +2 -2
- package/cjs/helpers/regex/range.js +5 -4
- package/cjs/helpers/regex/rule-template.js +4 -3
- package/cjs/helpers/sinon.js +33 -36
- package/cjs/helpers/supertest.js +34 -37
- package/cjs/helpers/vitest.js +29 -32
- package/docs/file-permissions.md +1 -1
- package/package.json +39 -1
- package/types/helpers/ancestor.d.ts +1 -1
- package/types/helpers/aws/s3.d.ts +1 -1
- package/types/helpers/chai.d.ts +3 -5
- package/types/helpers/entropy.d.ts +1 -0
- package/types/helpers/express.d.ts +38 -43
- package/types/helpers/mocha.d.ts +19 -21
- package/types/helpers/regex/ast.d.ts +1 -1
- package/types/helpers/regex/rule-template.d.ts +1 -1
- package/types/helpers/sinon.d.ts +3 -5
- package/types/helpers/supertest.d.ts +3 -5
- package/types/helpers/type.d.ts +1 -1
- package/types/helpers/vitest.d.ts +3 -5
- package/cjs/helpers/aws/index.js +0 -35
- package/cjs/helpers/decorators/interceptor.js +0 -88
- package/cjs/helpers/index.js +0 -60
- package/cjs/helpers/recognizers/index.js +0 -37
- package/cjs/helpers/rule-detect-react.js +0 -29
- package/cjs/helpers/validate-version.js +0 -94
- package/types/helpers/aws/index.d.ts +0 -3
- package/types/helpers/decorators/index.d.ts +0 -2
- package/types/helpers/decorators/interceptor.d.ts +0 -16
- package/types/helpers/index.d.ts +0 -28
- package/types/helpers/recognizers/index.d.ts +0 -2
- package/types/helpers/rule-detect-react.d.ts +0 -2
- package/types/helpers/validate-version.d.ts +0 -13
package/cjs/S1535/rule.js
CHANGED
|
@@ -51,10 +51,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
55
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
56
|
exports.rule = {
|
|
57
|
-
meta: (0,
|
|
57
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
58
58
|
messages: {
|
|
59
59
|
restrictLoop: 'Restrict what this loop acts on by testing each property.',
|
|
60
60
|
},
|
package/cjs/S1541/rule.js
CHANGED
|
@@ -51,11 +51,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const location_js_1 = require("../helpers/location.js");
|
|
55
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
56
|
+
const ancestor_js_1 = require("../helpers/ancestor.js");
|
|
57
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
59
|
const DEFAULT_THRESHOLD = 10;
|
|
57
60
|
exports.rule = {
|
|
58
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
59
62
|
create(context) {
|
|
60
63
|
const threshold = context.options[0]?.threshold ?? DEFAULT_THRESHOLD;
|
|
61
64
|
let functionsWithParent;
|
|
@@ -75,7 +78,7 @@ exports.rule = {
|
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
},
|
|
78
|
-
'FunctionDeclaration, FunctionExpression, ArrowFunctionExpression': (node) => functionsWithParent.set(node, (0,
|
|
81
|
+
'FunctionDeclaration, FunctionExpression, ArrowFunctionExpression': (node) => functionsWithParent.set(node, (0, ancestor_js_1.getParent)(context, node)),
|
|
79
82
|
"CallExpression[callee.type='Identifier'][callee.name='define'] FunctionExpression": (node) => functionsDefiningModule.push(node),
|
|
80
83
|
"NewExpression[callee.type='FunctionExpression'], CallExpression[callee.type='FunctionExpression']": (node) => functionsImmediatelyInvoked.push(node.callee),
|
|
81
84
|
};
|
|
@@ -87,7 +90,7 @@ function raiseOnUnauthorizedComplexity(node, parent, threshold, context) {
|
|
|
87
90
|
if (complexity > threshold) {
|
|
88
91
|
context.report({
|
|
89
92
|
message: toEncodedMessage(complexity, threshold, tokens),
|
|
90
|
-
loc: (0,
|
|
93
|
+
loc: (0, location_js_1.getMainFunctionTokenLocation)(node, parent, context),
|
|
91
94
|
});
|
|
92
95
|
}
|
|
93
96
|
}
|
|
@@ -124,10 +127,10 @@ class FunctionComplexityVisitor {
|
|
|
124
127
|
const visitNode = (node) => {
|
|
125
128
|
const { sourceCode } = this.context;
|
|
126
129
|
let token;
|
|
127
|
-
if ((0,
|
|
130
|
+
if ((0, ast_js_1.isFunctionNode)(node)) {
|
|
128
131
|
if (node === this.root) {
|
|
129
132
|
token = {
|
|
130
|
-
loc: (0,
|
|
133
|
+
loc: (0, location_js_1.getMainFunctionTokenLocation)(node, this.parent, this.context),
|
|
131
134
|
};
|
|
132
135
|
}
|
|
133
136
|
else {
|
|
@@ -160,7 +163,7 @@ class FunctionComplexityVisitor {
|
|
|
160
163
|
if (token) {
|
|
161
164
|
this.tokens.push(token);
|
|
162
165
|
}
|
|
163
|
-
for (const childNode of (0,
|
|
166
|
+
for (const childNode of (0, ancestor_js_1.childrenOf)(node, sourceCode.visitorKeys)) {
|
|
164
167
|
visitNode(childNode);
|
|
165
168
|
}
|
|
166
169
|
};
|
package/cjs/S1607/rule.js
CHANGED
|
@@ -51,12 +51,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
|
+
const module_js_1 = require("../helpers/module.js");
|
|
56
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
55
57
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
58
|
const dependencies_js_1 = require("../helpers/package-jsons/dependencies.js");
|
|
57
59
|
const all_in_parent_dirs_js_1 = require("../helpers/package-jsons/all-in-parent-dirs.js");
|
|
58
60
|
exports.rule = {
|
|
59
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
60
62
|
messages: {
|
|
61
63
|
removeOrExplainTest: 'Remove this unit test or explain why it is ignored.',
|
|
62
64
|
},
|
|
@@ -136,7 +138,7 @@ exports.rule = {
|
|
|
136
138
|
function nodejsListener() {
|
|
137
139
|
return {
|
|
138
140
|
CallExpression: (node) => {
|
|
139
|
-
const fqn = (0,
|
|
141
|
+
const fqn = (0, module_js_1.getFullyQualifiedName)(context, node.callee);
|
|
140
142
|
if (fqn !== 'test') {
|
|
141
143
|
return;
|
|
142
144
|
}
|
|
@@ -157,12 +159,12 @@ exports.rule = {
|
|
|
157
159
|
* Handle the pattern `test('name', t => { t.skip(); })`.
|
|
158
160
|
*/
|
|
159
161
|
function handleSkipMethod(node) {
|
|
160
|
-
const fn = (0,
|
|
162
|
+
const fn = (0, ast_js_1.resolveFunction)(context, node.arguments[1]);
|
|
161
163
|
if (!fn) {
|
|
162
164
|
return;
|
|
163
165
|
}
|
|
164
166
|
const testCtxParam = fn.params[0];
|
|
165
|
-
if (!testCtxParam || !(0,
|
|
167
|
+
if (!testCtxParam || !(0, ast_js_1.isIdentifier)(testCtxParam)) {
|
|
166
168
|
return;
|
|
167
169
|
}
|
|
168
170
|
const scopeVariables = context.sourceCode.scopeManager.getDeclaredVariables(fn);
|
|
@@ -177,11 +179,11 @@ exports.rule = {
|
|
|
177
179
|
continue;
|
|
178
180
|
}
|
|
179
181
|
const skipCall = maybeSkipCall;
|
|
180
|
-
if (!(0,
|
|
182
|
+
if (!(0, ast_js_1.isMethodInvocation)(skipCall, testCtxIden.name, 'skip', 0)) {
|
|
181
183
|
continue;
|
|
182
184
|
}
|
|
183
185
|
const skipArg = skipCall.arguments[0];
|
|
184
|
-
if (!skipArg || ((0,
|
|
186
|
+
if (!skipArg || ((0, ast_js_1.isLiteral)(skipArg) && skipArg.value === '')) {
|
|
185
187
|
context.report({
|
|
186
188
|
node: skipCall.callee,
|
|
187
189
|
messageId: 'removeOrExplainTest',
|
|
@@ -194,15 +196,15 @@ exports.rule = {
|
|
|
194
196
|
* Handle the pattern `test('name', { skip: true }, () => {})`.
|
|
195
197
|
*/
|
|
196
198
|
function handleSkipOption(node) {
|
|
197
|
-
const options = (0,
|
|
199
|
+
const options = (0, ast_js_1.getValueOfExpression)(context, node.arguments[1], 'ObjectExpression');
|
|
198
200
|
if (!options) {
|
|
199
201
|
return;
|
|
200
202
|
}
|
|
201
|
-
const skipProperty = (0,
|
|
203
|
+
const skipProperty = (0, ast_js_1.getProperty)(options, 'skip', context);
|
|
202
204
|
if (!skipProperty) {
|
|
203
205
|
return;
|
|
204
206
|
}
|
|
205
|
-
const skipValue = (0,
|
|
207
|
+
const skipValue = (0, ast_js_1.getValueOfExpression)(context, skipProperty.value, 'Literal');
|
|
206
208
|
if (!skipValue || (skipValue.value !== true && skipValue.value !== '')) {
|
|
207
209
|
return;
|
|
208
210
|
}
|
|
@@ -229,18 +231,18 @@ exports.rule = {
|
|
|
229
231
|
},
|
|
230
232
|
};
|
|
231
233
|
function isJasmineIgnoredTest(node) {
|
|
232
|
-
return (0,
|
|
234
|
+
return (0, ast_js_1.isIdentifier)(node.callee, 'xit', 'xdescribe', 'xcontext');
|
|
233
235
|
}
|
|
234
236
|
function isJestIgnoredTest(node) {
|
|
235
|
-
return ((0,
|
|
236
|
-
(0,
|
|
237
|
-
(0,
|
|
238
|
-
(0,
|
|
239
|
-
(0,
|
|
240
|
-
(0,
|
|
237
|
+
return ((0, ast_js_1.isMethodInvocation)(node, 'test', 'skip', 0) ||
|
|
238
|
+
(0, ast_js_1.isMethodInvocation)(node, 'it', 'skip', 0) ||
|
|
239
|
+
(0, ast_js_1.isMethodInvocation)(node, 'describe', 'skip', 0) ||
|
|
240
|
+
(0, ast_js_1.isFunctionInvocation)(node, 'xtest', 0) ||
|
|
241
|
+
(0, ast_js_1.isFunctionInvocation)(node, 'xit', 0) ||
|
|
242
|
+
(0, ast_js_1.isFunctionInvocation)(node, 'xdescribe', 0));
|
|
241
243
|
}
|
|
242
244
|
function isMochaIgnoredTest(node) {
|
|
243
|
-
return ((0,
|
|
244
|
-
(0,
|
|
245
|
-
(0,
|
|
245
|
+
return ((0, ast_js_1.isMethodInvocation)(node, 'it', 'skip', 0) ||
|
|
246
|
+
(0, ast_js_1.isMethodInvocation)(node, 'describe', 'skip', 0) ||
|
|
247
|
+
(0, ast_js_1.isMethodInvocation)(node, 'context', 'skip', 0));
|
|
246
248
|
}
|
package/cjs/S1764/rule.js
CHANGED
|
@@ -51,7 +51,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const location_js_1 = require("../helpers/location.js");
|
|
55
|
+
const equivalence_js_1 = require("../helpers/equivalence.js");
|
|
56
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
57
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
55
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
59
|
const sonar_runtime_js_1 = require("../helpers/sonar-runtime.js");
|
|
57
60
|
const EQUALITY_OPERATOR_TOKEN_KINDS = new Set(['==', '===', '!=', '!==']);
|
|
@@ -73,16 +76,16 @@ function hasRelevantOperator(node) {
|
|
|
73
76
|
(EQUALITY_OPERATOR_TOKEN_KINDS.has(node.operator) && !hasIdentifierOperands(node)));
|
|
74
77
|
}
|
|
75
78
|
function hasIdentifierOperands(node) {
|
|
76
|
-
return (0,
|
|
79
|
+
return (0, ast_js_1.isIdentifier)(node.left) && (0, ast_js_1.isIdentifier)(node.right);
|
|
77
80
|
}
|
|
78
81
|
function isOneOntoOneShifting(node) {
|
|
79
82
|
return (node.operator === '<<' &&
|
|
80
|
-
(0,
|
|
83
|
+
(0, ast_js_1.isLiteral)(node.left) &&
|
|
81
84
|
(node.left.value === 1 || node.left.value === 1n));
|
|
82
85
|
}
|
|
83
86
|
const message = 'Correct one of the identical sub-expressions on both sides of operator "{{operator}}"';
|
|
84
87
|
exports.rule = {
|
|
85
|
-
meta: (0,
|
|
88
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
86
89
|
messages: {
|
|
87
90
|
correctIdenticalSubExpressions: message,
|
|
88
91
|
},
|
|
@@ -99,12 +102,12 @@ exports.rule = {
|
|
|
99
102
|
function check(expr) {
|
|
100
103
|
if (hasRelevantOperator(expr) &&
|
|
101
104
|
!isOneOntoOneShifting(expr) &&
|
|
102
|
-
(0,
|
|
105
|
+
(0, equivalence_js_1.areEquivalent)(expr.left, expr.right, context.sourceCode)) {
|
|
103
106
|
const secondaryLocations = [];
|
|
104
107
|
if (expr.left.loc) {
|
|
105
|
-
secondaryLocations.push((0,
|
|
108
|
+
secondaryLocations.push((0, location_js_1.toSecondaryLocation)(expr.left));
|
|
106
109
|
}
|
|
107
|
-
(0,
|
|
110
|
+
(0, location_js_1.report)(context, {
|
|
108
111
|
message,
|
|
109
112
|
messageId: 'correctIdenticalSubExpressions',
|
|
110
113
|
data: {
|
package/cjs/S1821/rule.js
CHANGED
|
@@ -51,10 +51,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
55
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
56
|
exports.rule = {
|
|
57
|
-
meta: (0,
|
|
57
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
58
58
|
messages: {
|
|
59
59
|
removeNestedSwitch: 'Refactor the code to eliminate this nested "switch".',
|
|
60
60
|
},
|
package/cjs/S1848/rule.js
CHANGED
|
@@ -51,7 +51,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
|
+
const module_js_1 = require("../helpers/module.js");
|
|
56
|
+
const reaching_definitions_js_1 = require("../helpers/reaching-definitions.js");
|
|
57
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
55
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
59
|
/** DOM selection method names commonly used for element selection */
|
|
57
60
|
const DOM_SELECTION_METHODS = [
|
|
@@ -65,7 +68,7 @@ const DOM_SELECTION_METHODS = [
|
|
|
65
68
|
/** jQuery/$ function names */
|
|
66
69
|
const JQUERY_IDENTIFIERS = ['$', 'jQuery'];
|
|
67
70
|
exports.rule = {
|
|
68
|
-
meta: (0,
|
|
71
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
69
72
|
messages: {
|
|
70
73
|
removeInstantiationOf: 'Either remove this useless object instantiation of "{{constructor}}" or use it.',
|
|
71
74
|
removeInstantiation: 'Either remove this useless object instantiation or use it.',
|
|
@@ -130,7 +133,7 @@ function isException(context, node, name) {
|
|
|
130
133
|
if (name === 'Notification') {
|
|
131
134
|
return true;
|
|
132
135
|
}
|
|
133
|
-
const fqn = (0,
|
|
136
|
+
const fqn = (0, module_js_1.getFullyQualifiedName)(context, node);
|
|
134
137
|
if (!fqn) {
|
|
135
138
|
return false;
|
|
136
139
|
}
|
|
@@ -185,7 +188,7 @@ function containsDomSelection(node, scope) {
|
|
|
185
188
|
* Checks if a variable was initialized from a DOM selection call.
|
|
186
189
|
*/
|
|
187
190
|
function isVariableFromDomSelection(node, scope) {
|
|
188
|
-
const variable = (0,
|
|
191
|
+
const variable = (0, reaching_definitions_js_1.getVariableFromIdentifier)(node, scope);
|
|
189
192
|
if (!variable) {
|
|
190
193
|
return false;
|
|
191
194
|
}
|
|
@@ -222,19 +225,19 @@ function unwrapTypeAssertion(node) {
|
|
|
222
225
|
function isDomSelectionCall(node) {
|
|
223
226
|
const { callee } = node;
|
|
224
227
|
// Check for $() or jQuery()
|
|
225
|
-
if ((0,
|
|
228
|
+
if ((0, ast_js_1.isIdentifier)(callee, ...JQUERY_IDENTIFIERS)) {
|
|
226
229
|
return true;
|
|
227
230
|
}
|
|
228
231
|
// Check for *.querySelector, *.getElementById, etc. on any object
|
|
229
232
|
// This covers document.querySelector, myDocument.querySelector, this.document.querySelector, etc.
|
|
230
233
|
if (callee.type === 'MemberExpression' &&
|
|
231
|
-
(0,
|
|
234
|
+
(0, ast_js_1.isIdentifier)(callee.property, ...DOM_SELECTION_METHODS)) {
|
|
232
235
|
return true;
|
|
233
236
|
}
|
|
234
237
|
// Check for this.$() - common in Backbone/Marionette views
|
|
235
238
|
if (callee.type === 'MemberExpression' &&
|
|
236
239
|
callee.object.type === 'ThisExpression' &&
|
|
237
|
-
(0,
|
|
240
|
+
(0, ast_js_1.isIdentifier)(callee.property, ...JQUERY_IDENTIFIERS)) {
|
|
238
241
|
return true;
|
|
239
242
|
}
|
|
240
243
|
return false;
|
package/cjs/S1854/rule.js
CHANGED
|
@@ -51,10 +51,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const lva_js_1 = require("../helpers/lva.js");
|
|
55
|
+
const ancestor_js_1 = require("../helpers/ancestor.js");
|
|
56
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
57
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
58
|
+
const collection_js_1 = require("../helpers/collection.js");
|
|
55
59
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
60
|
exports.rule = {
|
|
57
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
58
62
|
messages: {
|
|
59
63
|
removeAssignment: 'Remove this useless assignment to variable "{{variable}}".',
|
|
60
64
|
},
|
|
@@ -92,14 +96,14 @@ exports.rule = {
|
|
|
92
96
|
destructuringStack.push(new DestructuringContext());
|
|
93
97
|
},
|
|
94
98
|
'ObjectPattern > Property > Identifier': (node) => {
|
|
95
|
-
const destructuring = (0,
|
|
99
|
+
const destructuring = (0, collection_js_1.last)(destructuringStack);
|
|
96
100
|
const { ref } = resolveReference(node);
|
|
97
101
|
if (ref) {
|
|
98
102
|
destructuring.references.push(ref);
|
|
99
103
|
}
|
|
100
104
|
},
|
|
101
105
|
'ObjectPattern > :matches(RestElement, ExperimentalRestProperty)': () => {
|
|
102
|
-
(0,
|
|
106
|
+
(0, collection_js_1.last)(destructuringStack).hasRest = true;
|
|
103
107
|
},
|
|
104
108
|
'ObjectPattern:exit': () => {
|
|
105
109
|
const destructuring = destructuringStack.pop();
|
|
@@ -114,7 +118,7 @@ exports.rule = {
|
|
|
114
118
|
collectVariablesReadInCatchOrFinally(tryStmt, context);
|
|
115
119
|
},
|
|
116
120
|
'Program:exit': () => {
|
|
117
|
-
(0,
|
|
121
|
+
(0, lva_js_1.lva)(liveVariablesMap);
|
|
118
122
|
for (const lva of liveVariablesMap.values()) {
|
|
119
123
|
checkSegment(lva);
|
|
120
124
|
reportNeverReadVariables(lva);
|
|
@@ -122,7 +126,7 @@ exports.rule = {
|
|
|
122
126
|
},
|
|
123
127
|
// CodePath events
|
|
124
128
|
onCodePathSegmentStart: (segment) => {
|
|
125
|
-
liveVariablesMap.set(segment.id, new
|
|
129
|
+
liveVariablesMap.set(segment.id, new lva_js_1.LiveVariables(segment));
|
|
126
130
|
currentCodePathSegments.push(segment);
|
|
127
131
|
},
|
|
128
132
|
onCodePathStart: codePath => {
|
|
@@ -139,10 +143,10 @@ exports.rule = {
|
|
|
139
143
|
},
|
|
140
144
|
};
|
|
141
145
|
function pushAssignmentContext(node) {
|
|
142
|
-
(0,
|
|
146
|
+
(0, collection_js_1.last)(codePathStack).assignmentStack.push(new AssignmentContext(node));
|
|
143
147
|
}
|
|
144
148
|
function popAssignmentContext() {
|
|
145
|
-
const assignment = (0,
|
|
149
|
+
const assignment = (0, collection_js_1.last)(codePathStack).assignmentStack.pop();
|
|
146
150
|
for (const r of assignment.rhs) {
|
|
147
151
|
processReference(r);
|
|
148
152
|
}
|
|
@@ -201,7 +205,7 @@ exports.rule = {
|
|
|
201
205
|
}
|
|
202
206
|
function isNullAssignment(ref) {
|
|
203
207
|
const parent = ref.identifier.parent;
|
|
204
|
-
return parent?.type === 'AssignmentExpression' && (0,
|
|
208
|
+
return parent?.type === 'AssignmentExpression' && (0, ast_js_1.isNullLiteral)(parent.right);
|
|
205
209
|
}
|
|
206
210
|
function isEnumConstant(node) {
|
|
207
211
|
return context.sourceCode.getAncestors(node).some(n => n.type === 'TSEnumDeclaration');
|
|
@@ -254,9 +258,9 @@ exports.rule = {
|
|
|
254
258
|
return { ref: jsxReference, variable: jsxReference.resolved };
|
|
255
259
|
}
|
|
256
260
|
function processReference(ref) {
|
|
257
|
-
const assignmentStack = (0,
|
|
261
|
+
const assignmentStack = (0, collection_js_1.last)(codePathStack).assignmentStack;
|
|
258
262
|
if (assignmentStack.length > 0) {
|
|
259
|
-
const assignment = (0,
|
|
263
|
+
const assignment = (0, collection_js_1.last)(assignmentStack);
|
|
260
264
|
assignment.add(ref);
|
|
261
265
|
}
|
|
262
266
|
else {
|
|
@@ -271,7 +275,7 @@ exports.rule = {
|
|
|
271
275
|
lva = liveVariablesMap.get(segment.id);
|
|
272
276
|
}
|
|
273
277
|
else {
|
|
274
|
-
lva = new
|
|
278
|
+
lva = new lva_js_1.LiveVariables(segment);
|
|
275
279
|
liveVariablesMap.set(segment.id, lva);
|
|
276
280
|
}
|
|
277
281
|
return lva;
|
|
@@ -283,7 +287,7 @@ exports.rule = {
|
|
|
283
287
|
}
|
|
284
288
|
}
|
|
285
289
|
function updateVariableUsages(variable) {
|
|
286
|
-
const codePathId = (0,
|
|
290
|
+
const codePathId = (0, collection_js_1.last)(codePathStack).codePath.id;
|
|
287
291
|
if (variableUsages.has(variable)) {
|
|
288
292
|
variableUsages.get(variable).add(codePathId);
|
|
289
293
|
}
|
|
@@ -352,7 +356,7 @@ exports.rule = {
|
|
|
352
356
|
callback(node);
|
|
353
357
|
return;
|
|
354
358
|
}
|
|
355
|
-
for (const child of (0,
|
|
359
|
+
for (const child of (0, ancestor_js_1.childrenOf)(node, context.sourceCode.visitorKeys)) {
|
|
356
360
|
visitIdentifiers(child, callback, visited);
|
|
357
361
|
}
|
|
358
362
|
}
|
package/cjs/S1862/rule.js
CHANGED
|
@@ -51,12 +51,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const equivalence_js_1 = require("../helpers/equivalence.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
56
|
+
const location_js_1 = require("../helpers/location.js");
|
|
55
57
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
58
|
const duplicatedConditionMessage = 'This condition is covered by the one on line {{line}}';
|
|
57
59
|
const duplicatedCaseMessage = 'This case duplicates the one on line {{line}}';
|
|
58
60
|
exports.rule = {
|
|
59
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
60
62
|
messages: {
|
|
61
63
|
duplicatedCondition: duplicatedConditionMessage,
|
|
62
64
|
duplicatedCase: duplicatedCaseMessage,
|
|
@@ -77,12 +79,12 @@ exports.rule = {
|
|
|
77
79
|
const currentOrOperands = splitByOr(current.test).map(splitByAnd);
|
|
78
80
|
operandsToCheck = operandsToCheck.map(orOperands => orOperands.filter(orOperand => !currentOrOperands.some(currentOrOperand => isSubset(currentOrOperand, orOperand, sourceCode))));
|
|
79
81
|
if (operandsToCheck.some(orOperands => orOperands.length === 0)) {
|
|
80
|
-
(0,
|
|
82
|
+
(0, location_js_1.report)(context, {
|
|
81
83
|
message: duplicatedConditionMessage,
|
|
82
84
|
messageId: 'duplicatedCondition',
|
|
83
85
|
data: { line: current.test.loc.start.line },
|
|
84
86
|
node: test,
|
|
85
|
-
}, [(0,
|
|
87
|
+
}, [(0, location_js_1.toSecondaryLocation)({ loc: current.test.loc }, 'Covering')]);
|
|
86
88
|
break;
|
|
87
89
|
}
|
|
88
90
|
}
|
|
@@ -92,16 +94,16 @@ exports.rule = {
|
|
|
92
94
|
for (const switchCase of switchStmt.cases) {
|
|
93
95
|
if (switchCase.test) {
|
|
94
96
|
const { test } = switchCase;
|
|
95
|
-
const duplicateTest = previousTests.find(previousTest => (0,
|
|
97
|
+
const duplicateTest = previousTests.find(previousTest => (0, equivalence_js_1.areEquivalent)(test, previousTest, sourceCode));
|
|
96
98
|
if (duplicateTest) {
|
|
97
|
-
(0,
|
|
99
|
+
(0, location_js_1.report)(context, {
|
|
98
100
|
messageId: 'duplicatedCase',
|
|
99
101
|
message: duplicatedCaseMessage,
|
|
100
102
|
data: {
|
|
101
103
|
line: duplicateTest.loc.start.line,
|
|
102
104
|
},
|
|
103
105
|
node: test,
|
|
104
|
-
}, [(0,
|
|
106
|
+
}, [(0, location_js_1.toSecondaryLocation)({ loc: duplicateTest.loc }, 'Original')]);
|
|
105
107
|
}
|
|
106
108
|
else {
|
|
107
109
|
previousTests.push(test);
|
|
@@ -139,6 +141,6 @@ function isSubset(first, second, sourceCode) {
|
|
|
139
141
|
isSubsetOf(first.right, second1.left, sourceCode)));
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
|
-
return (0,
|
|
144
|
+
return (0, equivalence_js_1.areEquivalent)(first, second, sourceCode);
|
|
143
145
|
}
|
|
144
146
|
}
|
package/cjs/S1871/rule.js
CHANGED
|
@@ -51,11 +51,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const equivalence_js_1 = require("../helpers/equivalence.js");
|
|
55
|
+
const conditions_js_1 = require("../helpers/conditions.js");
|
|
56
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
57
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
58
|
+
const collection_js_1 = require("../helpers/collection.js");
|
|
59
|
+
const location_js_1 = require("../helpers/location.js");
|
|
55
60
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
61
|
const message = "This {{type}}'s code block is the same as the block for the {{type}} on line {{line}}.";
|
|
57
62
|
exports.rule = {
|
|
58
|
-
meta: (0,
|
|
63
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
59
64
|
messages: {
|
|
60
65
|
sameConditionalBlock: message,
|
|
61
66
|
},
|
|
@@ -70,10 +75,10 @@ exports.rule = {
|
|
|
70
75
|
},
|
|
71
76
|
};
|
|
72
77
|
function visitIfStatement(ifStmt) {
|
|
73
|
-
if ((0,
|
|
78
|
+
if ((0, ast_js_1.isIfStatement)(ifStmt.parent)) {
|
|
74
79
|
return;
|
|
75
80
|
}
|
|
76
|
-
const { branches, endsWithElse } = (0,
|
|
81
|
+
const { branches, endsWithElse } = (0, conditions_js_1.collectIfBranches)(ifStmt);
|
|
77
82
|
if (allEquivalentWithoutDefault(branches, endsWithElse)) {
|
|
78
83
|
for (const [i, branch] of branches.slice(1).entries()) {
|
|
79
84
|
reportIssue(branch, branches[i], 'branch');
|
|
@@ -92,9 +97,9 @@ exports.rule = {
|
|
|
92
97
|
}
|
|
93
98
|
function visitSwitchStatement(switchStmt) {
|
|
94
99
|
const { cases } = switchStmt;
|
|
95
|
-
const { endsWithDefault } = (0,
|
|
96
|
-
const nonEmptyCases = cases.filter(c => (0,
|
|
97
|
-
const casesWithoutBreak = nonEmptyCases.map(c => (0,
|
|
100
|
+
const { endsWithDefault } = (0, conditions_js_1.collectSwitchBranches)(switchStmt);
|
|
101
|
+
const nonEmptyCases = cases.filter(c => (0, conditions_js_1.takeWithoutBreak)(expandSingleBlockStatement(c.consequent)).length > 0);
|
|
102
|
+
const casesWithoutBreak = nonEmptyCases.map(c => (0, conditions_js_1.takeWithoutBreak)(expandSingleBlockStatement(c.consequent)));
|
|
98
103
|
if (allEquivalentWithoutDefault(casesWithoutBreak, endsWithDefault)) {
|
|
99
104
|
for (const [i, caseStmt] of nonEmptyCases.slice(1).entries()) {
|
|
100
105
|
reportIssue(caseStmt, nonEmptyCases[i], 'case');
|
|
@@ -102,11 +107,11 @@ exports.rule = {
|
|
|
102
107
|
return;
|
|
103
108
|
}
|
|
104
109
|
for (let i = 1; i < cases.length; i++) {
|
|
105
|
-
const firstClauseWithoutBreak = (0,
|
|
110
|
+
const firstClauseWithoutBreak = (0, conditions_js_1.takeWithoutBreak)(expandSingleBlockStatement(cases[i].consequent));
|
|
106
111
|
if (hasRequiredSize(firstClauseWithoutBreak)) {
|
|
107
112
|
for (let j = 0; j < i; j++) {
|
|
108
|
-
const secondClauseWithoutBreak = (0,
|
|
109
|
-
if ((0,
|
|
113
|
+
const secondClauseWithoutBreak = (0, conditions_js_1.takeWithoutBreak)(expandSingleBlockStatement(cases[j].consequent));
|
|
114
|
+
if ((0, equivalence_js_1.areEquivalent)(firstClauseWithoutBreak, secondClauseWithoutBreak, context.sourceCode)) {
|
|
110
115
|
reportIssue(cases[i], cases[j], 'case');
|
|
111
116
|
break;
|
|
112
117
|
}
|
|
@@ -118,14 +123,14 @@ exports.rule = {
|
|
|
118
123
|
if (nodes.length > 0) {
|
|
119
124
|
const tokens = [
|
|
120
125
|
...context.sourceCode.getTokens(nodes[0]),
|
|
121
|
-
...context.sourceCode.getTokens((0,
|
|
126
|
+
...context.sourceCode.getTokens((0, collection_js_1.last)(nodes)),
|
|
122
127
|
].filter(token => token.value !== '{' && token.value !== '}');
|
|
123
|
-
return tokens.length > 0 && (0,
|
|
128
|
+
return tokens.length > 0 && (0, collection_js_1.last)(tokens).loc.end.line > tokens[0].loc.start.line;
|
|
124
129
|
}
|
|
125
130
|
return false;
|
|
126
131
|
}
|
|
127
132
|
function compareIfBranches(a, b) {
|
|
128
|
-
const equivalent = (0,
|
|
133
|
+
const equivalent = (0, equivalence_js_1.areEquivalent)(a, b, context.sourceCode);
|
|
129
134
|
if (equivalent && b.loc) {
|
|
130
135
|
reportIssue(a, b, 'branch');
|
|
131
136
|
}
|
|
@@ -136,16 +141,16 @@ exports.rule = {
|
|
|
136
141
|
branches.length > 1 &&
|
|
137
142
|
branches
|
|
138
143
|
.slice(1)
|
|
139
|
-
.every((branch, index) => (0,
|
|
144
|
+
.every((branch, index) => (0, equivalence_js_1.areEquivalent)(branch, branches[index], context.sourceCode)));
|
|
140
145
|
}
|
|
141
146
|
function reportIssue(node, equivalentNode, type) {
|
|
142
147
|
const equivalentNodeLoc = equivalentNode.loc;
|
|
143
|
-
(0,
|
|
148
|
+
(0, location_js_1.report)(context, {
|
|
144
149
|
message,
|
|
145
150
|
messageId: 'sameConditionalBlock',
|
|
146
151
|
data: { type, line: String(equivalentNodeLoc.start.line) },
|
|
147
152
|
node,
|
|
148
|
-
}, [(0,
|
|
153
|
+
}, [(0, location_js_1.toSecondaryLocation)(equivalentNode, 'Original')]);
|
|
149
154
|
}
|
|
150
155
|
},
|
|
151
156
|
};
|
package/cjs/S1874/rule.js
CHANGED
|
@@ -51,17 +51,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
55
56
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
57
|
exports.rule = {
|
|
57
|
-
meta: (0,
|
|
58
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
58
59
|
messages: {
|
|
59
60
|
deprecation: '{{deprecation}}',
|
|
60
61
|
},
|
|
61
62
|
}),
|
|
62
63
|
create(context) {
|
|
63
64
|
const services = context.sourceCode.parserServices;
|
|
64
|
-
if (!(0,
|
|
65
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
65
66
|
return {};
|
|
66
67
|
}
|
|
67
68
|
return {
|
package/cjs/S1940/rule.js
CHANGED
|
@@ -51,7 +51,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
55
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
56
|
const invertedOperators = {
|
|
57
57
|
'==': '!=',
|
|
@@ -64,7 +64,7 @@ const invertedOperators = {
|
|
|
64
64
|
'<=': '>',
|
|
65
65
|
};
|
|
66
66
|
exports.rule = {
|
|
67
|
-
meta: (0,
|
|
67
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
68
68
|
messages: {
|
|
69
69
|
useOppositeOperator: 'Use the opposite operator ({{invertedOperator}}) instead.',
|
|
70
70
|
suggestOperationInversion: 'Invert inner operation (apply if NaN is not expected)',
|