eslint-plugin-sonarjs 4.0.0 → 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 +269 -268
- 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 +85 -7
- 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/generated-meta.js +1 -1
- package/cjs/S1488/rule.js +11 -7
- package/cjs/S1515/rule.js +10 -8
- package/cjs/{helpers/aws/index.js → S1523/generated-meta.js} +34 -18
- package/cjs/S1523/index.js +21 -0
- package/cjs/S1523/meta.js +21 -0
- package/cjs/S1523/rule.js +143 -0
- package/cjs/S1526/rule.js +5 -4
- package/cjs/S1527/rule.js +2 -2
- package/cjs/S1528/rule.js +2 -2
- package/cjs/S1529/generated-meta.js +1 -1
- 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/generated-meta.js +1 -1
- 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 +47 -5
- package/cjs/S2208/rule.js +2 -2
- package/cjs/S2234/rule.js +58 -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 +80 -9
- 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/generated-meta.js +1 -1
- 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 +22 -11
- package/cjs/S3801/generated-meta.js +1 -1
- 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/config.js +1 -1
- 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/generated-meta.js +1 -1
- package/cjs/S7059/rule.js +8 -5
- package/cjs/S7639/generated-meta.js +1 -1
- package/cjs/S7639/rule.js +5 -4
- package/cjs/S7790/generated-meta.js +1 -1
- package/cjs/S7790/rule.js +7 -5
- package/cjs/S8441/generated-meta.js +1 -1
- 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/configs.js +92 -0
- 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/find-up/all-in-parent-dirs.js +0 -16
- 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/cjs/plugin-rules.js +452 -450
- package/docs/assertions-in-tests.md +2 -0
- package/docs/bitwise-operators.md +2 -0
- package/docs/code-eval.md +7 -0
- package/docs/file-permissions.md +1 -1
- package/docs/no-async-constructor.md +2 -0
- package/docs/no-inconsistent-returns.md +2 -0
- package/docs/prefer-immediate-return.md +2 -0
- package/docs/sql-queries.md +2 -0
- package/package.json +39 -1
- package/types/S1067/rule.d.ts +1 -1
- package/types/S1110/rule.d.ts +1 -1
- package/types/S1128/rule.d.ts +1 -1
- package/types/S1172/rule.d.ts +1 -1
- package/types/S1226/rule.d.ts +1 -1
- package/types/S134/rule.d.ts +1 -1
- package/types/S1472/rule.d.ts +1 -1
- package/types/S1481/rule.d.ts +1 -1
- package/types/S1488/generated-meta.d.ts +1 -1
- package/types/S1515/rule.d.ts +1 -1
- package/types/S1523/generated-meta.d.ts +17 -0
- package/types/S1523/index.d.ts +1 -0
- package/types/S1523/meta.d.ts +2 -0
- package/types/S1523/rule.d.ts +2 -0
- package/types/S1527/rule.d.ts +1 -1
- package/types/S1529/generated-meta.d.ts +1 -1
- package/types/S1541/rule.d.ts +1 -1
- package/types/S1862/rule.d.ts +1 -1
- package/types/S2077/generated-meta.d.ts +1 -1
- package/types/S2123/rule.d.ts +1 -1
- package/types/S2259/rule.d.ts +1 -1
- package/types/S2428/rule.d.ts +1 -1
- package/types/S2589/rule.d.ts +1 -1
- package/types/S2598/rule.d.ts +1 -1
- package/types/S2699/generated-meta.d.ts +1 -1
- package/types/S2699/rule.d.ts +1 -1
- package/types/S2737/rule.d.ts +1 -1
- package/types/S2757/rule.d.ts +1 -1
- package/types/S2819/rule.d.ts +1 -1
- package/types/S3001/rule.d.ts +1 -1
- package/types/S3317/rule.d.ts +1 -1
- package/types/S3500/rule.d.ts +1 -1
- package/types/S3513/rule.d.ts +1 -1
- package/types/S3686/rule.d.ts +1 -1
- package/types/S3801/generated-meta.d.ts +1 -1
- package/types/S3972/rule.d.ts +1 -1
- package/types/S3973/rule.d.ts +1 -1
- package/types/S4030/rule.d.ts +1 -1
- package/types/S4143/rule.d.ts +1 -1
- package/types/S4158/rule.d.ts +1 -1
- package/types/S4621/rule.d.ts +1 -1
- package/types/S4782/rule.d.ts +1 -1
- package/types/S5693/rule.d.ts +1 -1
- package/types/S5725/rule.d.ts +1 -1
- package/types/S5860/rule.d.ts +1 -1
- package/types/S5868/rule.d.ts +1 -1
- package/types/S5869/rule.d.ts +1 -1
- package/types/S6079/rule.d.ts +1 -1
- package/types/S6326/rule.d.ts +1 -1
- package/types/S6351/rule.d.ts +1 -1
- package/types/S6418/config.d.ts +1 -1
- package/types/S6443/rule.d.ts +1 -1
- package/types/S7059/generated-meta.d.ts +1 -1
- package/types/S7639/generated-meta.d.ts +1 -1
- package/types/S7790/generated-meta.d.ts +1 -1
- package/types/S8441/generated-meta.d.ts +1 -1
- package/types/S930/rule.d.ts +1 -1
- package/types/helpers/ancestor.d.ts +3 -3
- package/types/helpers/ast.d.ts +1 -1
- package/types/helpers/aws/iam.d.ts +2 -2
- package/types/helpers/aws/s3.d.ts +1 -1
- package/types/helpers/chai.d.ts +3 -5
- package/types/helpers/configs.d.ts +39 -1
- package/types/helpers/entropy.d.ts +1 -0
- package/types/helpers/equivalence.d.ts +1 -1
- package/types/helpers/express.d.ts +38 -43
- package/types/helpers/find-up/all-in-parent-dirs.d.ts +1 -1
- package/types/helpers/find-up/closest.d.ts +1 -1
- package/types/helpers/find-up/find-minimatch.d.ts +1 -1
- package/types/helpers/generate-meta.d.ts +1 -1
- package/types/helpers/mocha.d.ts +19 -21
- package/types/helpers/module.d.ts +1 -1
- package/types/helpers/package-jsons/all-in-parent-dirs.d.ts +1 -1
- package/types/helpers/package-jsons/dependencies.d.ts +1 -1
- package/types/helpers/recognizers/CodeRecognizer.d.ts +1 -1
- package/types/helpers/recognizers/JavaScriptFootPrint.d.ts +2 -2
- package/types/helpers/recognizers/LanguageFootprint.d.ts +1 -1
- package/types/helpers/regex/alternation.d.ts +1 -1
- package/types/helpers/regex/ast.d.ts +1 -1
- package/types/helpers/regex/location.d.ts +2 -2
- package/types/helpers/regex/range.d.ts +2 -2
- package/types/helpers/regex/rule-template.d.ts +1 -1
- package/types/helpers/result.d.ts +1 -1
- package/types/helpers/sinon.d.ts +4 -6
- package/types/helpers/sonar-runtime.d.ts +1 -1
- package/types/helpers/supertest.d.ts +4 -6
- package/types/helpers/type.d.ts +1 -1
- package/types/helpers/vitest.d.ts +4 -6
- package/types/plugin-rules.d.ts +1 -0
- 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/S2392/rule.js
CHANGED
|
@@ -51,10 +51,12 @@ 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 collection_js_1 = require("../helpers/collection.js");
|
|
56
|
+
const location_js_1 = require("../helpers/location.js");
|
|
55
57
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
58
|
exports.rule = {
|
|
57
|
-
meta: (0,
|
|
59
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
58
60
|
create(context) {
|
|
59
61
|
let scopeRanges = [];
|
|
60
62
|
let reported = [];
|
|
@@ -84,7 +86,7 @@ exports.rule = {
|
|
|
84
86
|
if (varDeclaration.kind !== 'var') {
|
|
85
87
|
return;
|
|
86
88
|
}
|
|
87
|
-
const scopeRange = (0,
|
|
89
|
+
const scopeRange = (0, collection_js_1.last)(scopeRanges);
|
|
88
90
|
function isOutsideOfScope(reference) {
|
|
89
91
|
const idRange = reference.range;
|
|
90
92
|
return idRange[0] < scopeRange[0] || idRange[1] > scopeRange[1];
|
|
@@ -98,11 +100,11 @@ exports.rule = {
|
|
|
98
100
|
}
|
|
99
101
|
const definition = variable.defs.find(def => varDeclaration.declarations.includes(def.node));
|
|
100
102
|
if (definition && !reported.includes(definition.name)) {
|
|
101
|
-
(0,
|
|
103
|
+
(0, location_js_1.report)(context, {
|
|
102
104
|
node: definition.name,
|
|
103
105
|
message: `Consider moving declaration of '${variable.name}' ` +
|
|
104
106
|
`as it is referenced outside current binding context.`,
|
|
105
|
-
}, referencesOutside.map(node => (0,
|
|
107
|
+
}, referencesOutside.map(node => (0, location_js_1.toSecondaryLocation)(node, 'Outside reference.')));
|
|
106
108
|
for (const defId of variable.defs.map(def => def.name)) {
|
|
107
109
|
reported.push(defId);
|
|
108
110
|
}
|
package/cjs/S2424/rule.js
CHANGED
|
@@ -55,10 +55,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.rule = void 0;
|
|
57
57
|
const globals_1 = __importDefault(require("globals"));
|
|
58
|
-
const
|
|
58
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
59
59
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
60
|
exports.rule = {
|
|
61
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
62
62
|
messages: {
|
|
63
63
|
removeOverride: 'Remove this override of "{{overridden}}".',
|
|
64
64
|
},
|
package/cjs/S2428/rule.js
CHANGED
|
@@ -51,10 +51,12 @@ 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 ast_js_1 = require("../helpers/ast.js");
|
|
55
57
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
58
|
exports.rule = {
|
|
57
|
-
meta: (0,
|
|
59
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
58
60
|
messages: {
|
|
59
61
|
declarePropertiesInsideObject: 'Declare one or more properties of this object inside of the object literal syntax instead of using separate statements.',
|
|
60
62
|
},
|
|
@@ -63,7 +65,7 @@ exports.rule = {
|
|
|
63
65
|
return {
|
|
64
66
|
BlockStatement: (node) => checkObjectInitialization(node.body, context),
|
|
65
67
|
Program: (node) => {
|
|
66
|
-
checkObjectInitialization((0,
|
|
68
|
+
checkObjectInitialization((0, ast_js_1.getProgramStatements)(node), context);
|
|
67
69
|
},
|
|
68
70
|
};
|
|
69
71
|
},
|
|
@@ -72,7 +74,7 @@ function checkObjectInitialization(statements, context) {
|
|
|
72
74
|
let index = 0;
|
|
73
75
|
while (index < statements.length - 1) {
|
|
74
76
|
const objectDeclaration = getObjectDeclaration(statements[index]);
|
|
75
|
-
if (objectDeclaration && (0,
|
|
77
|
+
if (objectDeclaration && (0, ast_js_1.isIdentifier)(objectDeclaration.id)) {
|
|
76
78
|
const nextStmt = statements[index + 1];
|
|
77
79
|
if (isPropertyAssignment(nextStmt, objectDeclaration.id, context.sourceCode)) {
|
|
78
80
|
context.report({ messageId: 'declarePropertiesInsideObject', node: objectDeclaration });
|
|
@@ -97,8 +99,8 @@ function isPropertyAssignment(statement, objectIdentifier, sourceCode) {
|
|
|
97
99
|
if (left.type === 'MemberExpression') {
|
|
98
100
|
return (!left.computed &&
|
|
99
101
|
isSingleLineExpression(right, sourceCode) &&
|
|
100
|
-
(0,
|
|
101
|
-
!(0,
|
|
102
|
+
(0, equivalence_js_1.areEquivalent)(left.object, objectIdentifier, sourceCode) &&
|
|
103
|
+
!(0, equivalence_js_1.areEquivalent)(left.object, right, sourceCode));
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
return false;
|
package/cjs/S2486/rule.js
CHANGED
|
@@ -51,10 +51,11 @@ 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 ast_js_1 = require("../helpers/ast.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
|
handleException: "Handle this exception or don't catch it at all.",
|
|
60
61
|
},
|
|
@@ -64,7 +65,7 @@ exports.rule = {
|
|
|
64
65
|
'CatchClause[param.type="Identifier"]'(node) {
|
|
65
66
|
const param = node.param;
|
|
66
67
|
const scope = context.sourceCode.getScope(node);
|
|
67
|
-
const variable = (0,
|
|
68
|
+
const variable = (0, ast_js_1.getVariableFromScope)(scope, param.name);
|
|
68
69
|
if (variable?.references.length === 0) {
|
|
69
70
|
context.report({
|
|
70
71
|
messageId: 'handleException',
|
package/cjs/S2589/rule.js
CHANGED
|
@@ -51,11 +51,13 @@ 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 ast_js_1 = require("../helpers/ast.js");
|
|
56
|
+
const location_js_1 = require("../helpers/location.js");
|
|
55
57
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
58
|
const message = 'This always evaluates to {{value}}. Consider refactoring this code.';
|
|
57
59
|
exports.rule = {
|
|
58
|
-
meta: (0,
|
|
60
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
59
61
|
messages: {
|
|
60
62
|
refactorBooleanExpression: message,
|
|
61
63
|
},
|
|
@@ -76,7 +78,7 @@ exports.rule = {
|
|
|
76
78
|
},
|
|
77
79
|
':statement': (node) => {
|
|
78
80
|
const { parent } = node;
|
|
79
|
-
if ((0,
|
|
81
|
+
if ((0, ast_js_1.isIfStatement)(parent)) {
|
|
80
82
|
// we visit 'consequent' and 'alternate' and not if-statement directly in order to get scope for 'consequent'
|
|
81
83
|
const currentScope = context.sourceCode.getScope(node);
|
|
82
84
|
if (parent.consequent === node) {
|
|
@@ -84,7 +86,7 @@ exports.rule = {
|
|
|
84
86
|
truthyMap.set(parent.consequent, transformAndFilter(truthy, currentScope));
|
|
85
87
|
falsyMap.set(parent.consequent, transformAndFilter(falsy, currentScope));
|
|
86
88
|
}
|
|
87
|
-
else if (parent.alternate === node && (0,
|
|
89
|
+
else if (parent.alternate === node && (0, ast_js_1.isIdentifier)(parent.test)) {
|
|
88
90
|
falsyMap.set(parent.alternate, transformAndFilter([parent.test], currentScope));
|
|
89
91
|
}
|
|
90
92
|
}
|
|
@@ -103,7 +105,7 @@ exports.rule = {
|
|
|
103
105
|
}
|
|
104
106
|
if (!isLogicalAnd(parent) &&
|
|
105
107
|
!isLogicalOrLhs(id, parent) &&
|
|
106
|
-
!(0,
|
|
108
|
+
!(0, ast_js_1.isIfStatement)(parent) &&
|
|
107
109
|
!isLogicalNegation(parent)) {
|
|
108
110
|
return;
|
|
109
111
|
}
|
|
@@ -129,14 +131,14 @@ function collectKnownIdentifiers(expression) {
|
|
|
129
131
|
const truthy = [];
|
|
130
132
|
const falsy = [];
|
|
131
133
|
const checkExpr = (expr) => {
|
|
132
|
-
if ((0,
|
|
134
|
+
if ((0, ast_js_1.isIdentifier)(expr)) {
|
|
133
135
|
truthy.push(expr);
|
|
134
136
|
}
|
|
135
137
|
else if (isLogicalNegation(expr)) {
|
|
136
|
-
if ((0,
|
|
138
|
+
if ((0, ast_js_1.isIdentifier)(expr.argument)) {
|
|
137
139
|
falsy.push(expr.argument);
|
|
138
140
|
}
|
|
139
|
-
else if (isLogicalNegation(expr.argument) && (0,
|
|
141
|
+
else if (isLogicalNegation(expr.argument) && (0, ast_js_1.isIdentifier)(expr.argument.argument)) {
|
|
140
142
|
truthy.push(expr.argument.argument);
|
|
141
143
|
}
|
|
142
144
|
}
|
|
@@ -212,11 +214,11 @@ function transformAndFilter(ids, currentScope) {
|
|
|
212
214
|
}
|
|
213
215
|
function reportIssue(id, ref, context, truthy) {
|
|
214
216
|
const value = truthy ? 'truthy' : 'falsy';
|
|
215
|
-
(0,
|
|
217
|
+
(0, location_js_1.report)(context, {
|
|
216
218
|
message,
|
|
217
219
|
data: {
|
|
218
220
|
value,
|
|
219
221
|
},
|
|
220
222
|
node: id,
|
|
221
|
-
}, ref?.identifier ? [(0,
|
|
223
|
+
}, ref?.identifier ? [(0, location_js_1.toSecondaryLocation)(ref.identifier, `Evaluated here to be ${value}`)] : []);
|
|
222
224
|
}
|
package/cjs/S2598/rule.js
CHANGED
|
@@ -52,7 +52,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
54
|
exports.getVariablePropertyFromAssignment = getVariablePropertyFromAssignment;
|
|
55
|
-
const
|
|
55
|
+
const location_js_1 = require("../helpers/location.js");
|
|
56
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
57
|
+
const module_js_1 = require("../helpers/module.js");
|
|
58
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
56
59
|
const meta = __importStar(require("./generated-meta.js"));
|
|
57
60
|
const FORMIDABLE_MODULE = 'formidable';
|
|
58
61
|
const KEEP_EXTENSIONS = 'keepExtensions';
|
|
@@ -62,7 +65,7 @@ const STORAGE_OPTION = 'storage';
|
|
|
62
65
|
const DESTINATION_OPTION = 'destination';
|
|
63
66
|
const formidableObjects = new Map();
|
|
64
67
|
exports.rule = {
|
|
65
|
-
meta: (0,
|
|
68
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
66
69
|
create(context) {
|
|
67
70
|
return {
|
|
68
71
|
NewExpression(node) {
|
|
@@ -90,7 +93,7 @@ function checkCallExpression(context, callExpression) {
|
|
|
90
93
|
if (callee.type !== 'Identifier') {
|
|
91
94
|
return;
|
|
92
95
|
}
|
|
93
|
-
const fqn = (0,
|
|
96
|
+
const fqn = (0, module_js_1.getFullyQualifiedName)(context, callee);
|
|
94
97
|
if (!fqn) {
|
|
95
98
|
return;
|
|
96
99
|
}
|
|
@@ -104,7 +107,7 @@ function checkCallExpression(context, callExpression) {
|
|
|
104
107
|
}
|
|
105
108
|
function checkFormidable(context, callExpression) {
|
|
106
109
|
if (callExpression.arguments.length === 0) {
|
|
107
|
-
const formVariable = (0,
|
|
110
|
+
const formVariable = (0, ast_js_1.getLhsVariable)(context, callExpression);
|
|
108
111
|
if (formVariable) {
|
|
109
112
|
formidableObjects.set(formVariable, {
|
|
110
113
|
uploadDirSet: false,
|
|
@@ -114,26 +117,26 @@ function checkFormidable(context, callExpression) {
|
|
|
114
117
|
}
|
|
115
118
|
return;
|
|
116
119
|
}
|
|
117
|
-
const options = (0,
|
|
120
|
+
const options = (0, ast_js_1.getValueOfExpression)(context, callExpression.arguments[0], 'ObjectExpression');
|
|
118
121
|
if (options) {
|
|
119
|
-
report(context, !!(0,
|
|
122
|
+
report(context, !!(0, ast_js_1.getProperty)(options, UPLOAD_DIR, context), keepExtensionsValue((0, ast_js_1.getProperty)(options, KEEP_EXTENSIONS, context)?.value), callExpression);
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
125
|
function checkMulter(context, callExpression) {
|
|
123
126
|
if (callExpression.arguments.length === 0) {
|
|
124
127
|
return;
|
|
125
128
|
}
|
|
126
|
-
const multerOptions = (0,
|
|
129
|
+
const multerOptions = (0, ast_js_1.getValueOfExpression)(context, callExpression.arguments[0], 'ObjectExpression');
|
|
127
130
|
if (!multerOptions) {
|
|
128
131
|
return;
|
|
129
132
|
}
|
|
130
|
-
const storagePropertyValue = (0,
|
|
133
|
+
const storagePropertyValue = (0, ast_js_1.getProperty)(multerOptions, STORAGE_OPTION, context)?.value;
|
|
131
134
|
if (storagePropertyValue) {
|
|
132
|
-
const storageValue = (0,
|
|
135
|
+
const storageValue = (0, ast_js_1.getValueOfExpression)(context, storagePropertyValue, 'CallExpression');
|
|
133
136
|
if (storageValue) {
|
|
134
137
|
const diskStorageCallee = getDiskStorageCalleeIfUnsafeStorage(context, storageValue);
|
|
135
138
|
if (diskStorageCallee) {
|
|
136
|
-
report(context, false, false, callExpression, (0,
|
|
139
|
+
report(context, false, false, callExpression, (0, location_js_1.toSecondaryLocation)(diskStorageCallee, 'no destination specified'));
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
142
|
}
|
|
@@ -141,8 +144,8 @@ function checkMulter(context, callExpression) {
|
|
|
141
144
|
function getDiskStorageCalleeIfUnsafeStorage(context, storageCreation) {
|
|
142
145
|
const { arguments: args, callee } = storageCreation;
|
|
143
146
|
if (args.length > 0 && isMemberWithProperty(callee, 'diskStorage')) {
|
|
144
|
-
const storageOptions = (0,
|
|
145
|
-
if (storageOptions && !(0,
|
|
147
|
+
const storageOptions = (0, ast_js_1.getValueOfExpression)(context, args[0], 'ObjectExpression');
|
|
148
|
+
if (storageOptions && !(0, ast_js_1.getProperty)(storageOptions, DESTINATION_OPTION, context)) {
|
|
146
149
|
return callee;
|
|
147
150
|
}
|
|
148
151
|
}
|
|
@@ -184,7 +187,7 @@ function getVariablePropertyFromAssignment(context, assignment) {
|
|
|
184
187
|
}
|
|
185
188
|
const memberExpr = assignment.left;
|
|
186
189
|
if (memberExpr.object.type === 'Identifier' && memberExpr.property.type === 'Identifier') {
|
|
187
|
-
const objectVariable = (0,
|
|
190
|
+
const objectVariable = (0, ast_js_1.getVariableFromName)(context, memberExpr.object.name, memberExpr);
|
|
188
191
|
if (objectVariable) {
|
|
189
192
|
return { objectVariable, property: memberExpr.property.name };
|
|
190
193
|
}
|
|
@@ -203,7 +206,7 @@ function report(context, uploadDirSet, keepExtensions, callExpression, secondary
|
|
|
203
206
|
message = 'Restrict the extension and folder destination of uploaded files.';
|
|
204
207
|
}
|
|
205
208
|
if (message) {
|
|
206
|
-
(0,
|
|
209
|
+
(0, location_js_1.report)(context, {
|
|
207
210
|
message,
|
|
208
211
|
node: callExpression.callee,
|
|
209
212
|
}, secondaryLocation ? [secondaryLocation] : []);
|
|
@@ -36,7 +36,7 @@ __exportStar(require("./meta.js"), exports);
|
|
|
36
36
|
exports.meta = {
|
|
37
37
|
type: 'problem',
|
|
38
38
|
docs: {
|
|
39
|
-
description: '
|
|
39
|
+
description: 'File permissions should not be set to world-accessible values',
|
|
40
40
|
recommended: true,
|
|
41
41
|
url: 'https://sonarsource.github.io/rspec/#/rspec/S2612/javascript',
|
|
42
42
|
requiresTypeChecking: false,
|
package/cjs/S2612/rule.js
CHANGED
|
@@ -51,11 +51,13 @@ 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 chmodLikeFunction = ['chmod', 'chmodSync', 'fchmod', 'fchmodSync', 'lchmod', 'lchmodSync'];
|
|
57
59
|
exports.rule = {
|
|
58
|
-
meta: (0,
|
|
60
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
59
61
|
messages: {
|
|
60
62
|
safePermission: 'Make sure this permission is safe.',
|
|
61
63
|
},
|
|
@@ -78,7 +80,7 @@ exports.rule = {
|
|
|
78
80
|
};
|
|
79
81
|
function modeFromMemberExpression(modeExpr) {
|
|
80
82
|
const { object, property } = modeExpr;
|
|
81
|
-
if ((0,
|
|
83
|
+
if ((0, ast_js_1.isMemberExpression)(object, 'fs', 'constants') && property.type === 'Identifier') {
|
|
82
84
|
return FS_CONST[property.name];
|
|
83
85
|
}
|
|
84
86
|
return null;
|
|
@@ -94,7 +96,7 @@ exports.rule = {
|
|
|
94
96
|
return modeFromLiteral(expr);
|
|
95
97
|
}
|
|
96
98
|
else if (expr.type === 'Identifier') {
|
|
97
|
-
const usage = (0,
|
|
99
|
+
const usage = (0, ast_js_1.getUniqueWriteUsage)(context, expr.name, expr);
|
|
98
100
|
if (usage && !visited.has(usage)) {
|
|
99
101
|
visited.add(usage);
|
|
100
102
|
return modeFromExpression(usage, visited);
|
|
@@ -129,7 +131,7 @@ exports.rule = {
|
|
|
129
131
|
checkModeArgument(callExpression.arguments[0], 0);
|
|
130
132
|
checkModeArgument(callExpression.arguments[1], 0);
|
|
131
133
|
}
|
|
132
|
-
else if ((0,
|
|
134
|
+
else if ((0, module_js_1.getFullyQualifiedName)(context, callExpression) === 'process.umask') {
|
|
133
135
|
checkModeArgument(callExpression.arguments[0], 7);
|
|
134
136
|
}
|
|
135
137
|
},
|
|
@@ -142,7 +144,7 @@ function isChmodLikeFunction(node) {
|
|
|
142
144
|
return false;
|
|
143
145
|
}
|
|
144
146
|
// to support fs promises we are only checking the name of the function
|
|
145
|
-
return (0,
|
|
147
|
+
return (0, ast_js_1.isIdentifier)(callee.property, ...chmodLikeFunction);
|
|
146
148
|
}
|
|
147
149
|
function modeFromLiteral(modeExpr) {
|
|
148
150
|
const modeValue = modeExpr.value;
|
package/cjs/S2639/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 rule_template_js_1 = require("../helpers/regex/rule-template.js");
|
|
57
57
|
exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
@@ -66,7 +66,7 @@ exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
};
|
|
69
|
-
}, (0,
|
|
69
|
+
}, (0, generate_meta_js_1.generateMeta)(meta, {
|
|
70
70
|
messages: {
|
|
71
71
|
issue: "Rework this empty character class that doesn't match anything.",
|
|
72
72
|
},
|
package/cjs/S2681/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 NestingStatementLike = new Set([
|
|
57
57
|
'IfStatement',
|
|
@@ -61,7 +61,7 @@ const NestingStatementLike = new Set([
|
|
|
61
61
|
'WhileStatement',
|
|
62
62
|
]);
|
|
63
63
|
exports.rule = {
|
|
64
|
-
meta: (0,
|
|
64
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
65
65
|
create(context) {
|
|
66
66
|
return {
|
|
67
67
|
Program: (node) => checkStatements(node.body, context),
|
package/cjs/S2692/rule.js
CHANGED
|
@@ -51,17 +51,19 @@ 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 parser_services_js_1 = require("../helpers/parser-services.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
56
|
+
const type_js_1 = require("../helpers/type.js");
|
|
55
57
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
58
|
exports.rule = {
|
|
57
|
-
meta: (0,
|
|
59
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
58
60
|
messages: {
|
|
59
61
|
considerIncludes: "This check ignores index 0; consider using 'includes' method to make this check safe and explicit.",
|
|
60
62
|
},
|
|
61
63
|
}),
|
|
62
64
|
create(context) {
|
|
63
65
|
const services = context.sourceCode.parserServices;
|
|
64
|
-
if (!(0,
|
|
66
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
65
67
|
return {};
|
|
66
68
|
}
|
|
67
69
|
return {
|
|
@@ -85,5 +87,5 @@ function isArrayIndexOfCall(node, services) {
|
|
|
85
87
|
node.callee.type === 'MemberExpression' &&
|
|
86
88
|
node.callee.property.type === 'Identifier' &&
|
|
87
89
|
node.callee.property.name === 'indexOf' &&
|
|
88
|
-
(0,
|
|
90
|
+
(0, type_js_1.isArray)(node.callee.object, services));
|
|
89
91
|
}
|
|
@@ -39,7 +39,7 @@ exports.meta = {
|
|
|
39
39
|
description: 'Tests should include assertions',
|
|
40
40
|
recommended: true,
|
|
41
41
|
url: 'https://sonarsource.github.io/rspec/#/rspec/S2699/javascript',
|
|
42
|
-
requiresTypeChecking:
|
|
42
|
+
requiresTypeChecking: true,
|
|
43
43
|
},
|
|
44
44
|
fixable: undefined,
|
|
45
45
|
deprecated: false,
|
package/cjs/S2699/rule.js
CHANGED
|
@@ -37,8 +37,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.rule = void 0;
|
|
40
|
-
const
|
|
41
|
-
const
|
|
40
|
+
const Chai = __importStar(require("../helpers/chai.js"));
|
|
41
|
+
const ancestor_js_1 = require("../helpers/ancestor.js");
|
|
42
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
43
|
+
const module_js_1 = require("../helpers/module.js");
|
|
44
|
+
const module_ts_js_1 = require("../helpers/module-ts.js");
|
|
45
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
46
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
47
|
+
const Mocha = __importStar(require("../helpers/mocha.js"));
|
|
48
|
+
const Sinon = __importStar(require("../helpers/sinon.js"));
|
|
49
|
+
const Vitest = __importStar(require("../helpers/vitest.js"));
|
|
50
|
+
const Supertest = __importStar(require("../helpers/supertest.js"));
|
|
42
51
|
const meta = __importStar(require("./generated-meta.js"));
|
|
43
52
|
const typescript_1 = __importDefault(require("typescript"));
|
|
44
53
|
/**
|
|
@@ -47,19 +56,19 @@ const typescript_1 = __importDefault(require("typescript"));
|
|
|
47
56
|
* libX and the imported library was libY.
|
|
48
57
|
*/
|
|
49
58
|
exports.rule = {
|
|
50
|
-
meta: (0,
|
|
59
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
51
60
|
create(context) {
|
|
52
|
-
if (!(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
if (!(Chai.isImported(context) ||
|
|
62
|
+
Sinon.isImported(context) ||
|
|
63
|
+
Vitest.isImported(context) ||
|
|
64
|
+
Supertest.isImported(context))) {
|
|
56
65
|
return {};
|
|
57
66
|
}
|
|
58
67
|
const visitedNodes = new Map();
|
|
59
68
|
const visitedTSNodes = new Map();
|
|
60
69
|
return {
|
|
61
70
|
'CallExpression:exit': (node) => {
|
|
62
|
-
const testCase =
|
|
71
|
+
const testCase = Mocha.extractTestCase(node);
|
|
63
72
|
if (testCase !== null) {
|
|
64
73
|
checkAssertions(testCase, context, visitedNodes, visitedTSNodes);
|
|
65
74
|
}
|
|
@@ -90,7 +99,7 @@ function hasDoneCallbackAssertion(callback, context) {
|
|
|
90
99
|
return false;
|
|
91
100
|
}
|
|
92
101
|
const firstParam = callback.params[0];
|
|
93
|
-
if (!(0,
|
|
102
|
+
if (!(0, ast_js_1.isIdentifier)(firstParam)) {
|
|
94
103
|
return false;
|
|
95
104
|
}
|
|
96
105
|
const doneParamName = firstParam.name;
|
|
@@ -106,27 +115,27 @@ function isValidDoneMethodCallPattern(node, doneParamName, context) {
|
|
|
106
115
|
// Pattern 2: .catch(done) - done receives rejection error
|
|
107
116
|
if (methodName === 'catch' &&
|
|
108
117
|
node.arguments.length === 1 &&
|
|
109
|
-
(0,
|
|
118
|
+
(0, ast_js_1.isIdentifier)(node.arguments[0], doneParamName)) {
|
|
110
119
|
return true;
|
|
111
120
|
}
|
|
112
121
|
// Pattern 3: .then(_, done) - done as second argument
|
|
113
122
|
if (methodName === 'then' &&
|
|
114
123
|
node.arguments.length >= 2 &&
|
|
115
|
-
(0,
|
|
124
|
+
(0, ast_js_1.isIdentifier)(node.arguments[1], doneParamName)) {
|
|
116
125
|
return true;
|
|
117
126
|
}
|
|
118
127
|
// Pattern 4: .subscribe(_, done) - done as second argument (error position)
|
|
119
128
|
if (methodName === 'subscribe' &&
|
|
120
129
|
node.arguments.length >= 2 &&
|
|
121
|
-
(0,
|
|
130
|
+
(0, ast_js_1.isIdentifier)(node.arguments[1], doneParamName)) {
|
|
122
131
|
return true;
|
|
123
132
|
}
|
|
124
133
|
// Pattern 5: .subscribe({ error: done }) - done in error property
|
|
125
134
|
if (methodName === 'subscribe' &&
|
|
126
135
|
node.arguments.length === 1 &&
|
|
127
136
|
node.arguments[0].type === 'ObjectExpression') {
|
|
128
|
-
const errorProp = (0,
|
|
129
|
-
return errorProp != null && (0,
|
|
137
|
+
const errorProp = (0, ast_js_1.getProperty)(node.arguments[0], 'error', context);
|
|
138
|
+
return errorProp != null && (0, ast_js_1.isIdentifier)(errorProp.value, doneParamName);
|
|
130
139
|
}
|
|
131
140
|
return false;
|
|
132
141
|
}
|
|
@@ -136,16 +145,16 @@ function isValidDoneMethodCallPattern(node, doneParamName, context) {
|
|
|
136
145
|
function containsValidDoneAssertion(node, doneParamName, visitorKeys, context) {
|
|
137
146
|
if (node.type === 'CallExpression') {
|
|
138
147
|
// Pattern 1: done(arg) - direct call with at least one argument
|
|
139
|
-
if ((0,
|
|
148
|
+
if ((0, ast_js_1.isIdentifier)(node.callee, doneParamName) && node.arguments.length > 0) {
|
|
140
149
|
return true;
|
|
141
150
|
}
|
|
142
151
|
// Check method call patterns
|
|
143
|
-
if ((0,
|
|
152
|
+
if ((0, ast_js_1.isMethodCall)(node) && isValidDoneMethodCallPattern(node, doneParamName, context)) {
|
|
144
153
|
return true;
|
|
145
154
|
}
|
|
146
155
|
}
|
|
147
156
|
// Recurse through children
|
|
148
|
-
for (const child of (0,
|
|
157
|
+
for (const child of (0, ancestor_js_1.childrenOf)(node, visitorKeys)) {
|
|
149
158
|
if (containsValidDoneAssertion(child, doneParamName, visitorKeys, context)) {
|
|
150
159
|
return true;
|
|
151
160
|
}
|
|
@@ -161,7 +170,7 @@ function checkAssertions(testCase, context, visitedNodes, visitedTSNodes) {
|
|
|
161
170
|
const visitor = new TestCaseAssertionVisitor(context);
|
|
162
171
|
const parserServices = context.sourceCode.parserServices;
|
|
163
172
|
let hasAssertions = false;
|
|
164
|
-
if ((0,
|
|
173
|
+
if ((0, parser_services_js_1.isRequiredParserServices)(parserServices)) {
|
|
165
174
|
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(callback);
|
|
166
175
|
hasAssertions = visitor.visitTSNode(parserServices, tsNode, visitedTSNodes);
|
|
167
176
|
}
|
|
@@ -183,10 +192,10 @@ class TestCaseAssertionVisitor {
|
|
|
183
192
|
}
|
|
184
193
|
visitedTSNodes.set(node, false);
|
|
185
194
|
if (isGlobalTSAssertion(services, node) ||
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
195
|
+
Chai.isTSAssertion(services, node) ||
|
|
196
|
+
Sinon.isTSAssertion(services, node) ||
|
|
197
|
+
Supertest.isTSAssertion(services, node) ||
|
|
198
|
+
Vitest.isTSAssertion(services, node)) {
|
|
190
199
|
visitedTSNodes.set(node, true);
|
|
191
200
|
return true;
|
|
192
201
|
}
|
|
@@ -210,23 +219,23 @@ class TestCaseAssertionVisitor {
|
|
|
210
219
|
return visitedNodes.get(node);
|
|
211
220
|
}
|
|
212
221
|
visitedNodes.set(node, false);
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
222
|
+
if (Chai.isAssertion(context, node) ||
|
|
223
|
+
Sinon.isAssertion(context, node) ||
|
|
224
|
+
Vitest.isAssertion(context, node) ||
|
|
225
|
+
Supertest.isAssertion(context, node) ||
|
|
217
226
|
isGlobalAssertion(context, node)) {
|
|
218
227
|
visitedNodes.set(node, true);
|
|
219
228
|
return true;
|
|
220
229
|
}
|
|
221
230
|
let nodeHasAssertions = false;
|
|
222
|
-
if ((0,
|
|
231
|
+
if ((0, ast_js_1.isFunctionCall)(node)) {
|
|
223
232
|
const { callee } = node;
|
|
224
|
-
const functionDef = (0,
|
|
233
|
+
const functionDef = (0, ast_js_1.resolveFunction)(this.context, callee);
|
|
225
234
|
if (functionDef) {
|
|
226
235
|
nodeHasAssertions ||= this.visit(context, functionDef.body, visitedNodes);
|
|
227
236
|
}
|
|
228
237
|
}
|
|
229
|
-
for (const child of (0,
|
|
238
|
+
for (const child of (0, ancestor_js_1.childrenOf)(node, this.visitorKeys)) {
|
|
230
239
|
nodeHasAssertions ||= this.visit(context, child, visitedNodes);
|
|
231
240
|
}
|
|
232
241
|
visitedNodes.set(node, nodeHasAssertions);
|
|
@@ -263,7 +272,7 @@ function isGlobalExpectExpression(node) {
|
|
|
263
272
|
innerCallExpression.expression.text.startsWith('expect'));
|
|
264
273
|
}
|
|
265
274
|
function isFunctionCallFromNodeAssertTS(services, node) {
|
|
266
|
-
const fqn = (0,
|
|
275
|
+
const fqn = (0, module_ts_js_1.getFullyQualifiedNameTS)(services, node);
|
|
267
276
|
return fqn ? fqn?.startsWith('assert') : false;
|
|
268
277
|
}
|
|
269
278
|
function isGlobalAssertion(context, node) {
|
|
@@ -301,6 +310,6 @@ function isGlobalExpectExpressionJS(node) {
|
|
|
301
310
|
return innerCall.callee.type === 'Identifier' && innerCall.callee.name.startsWith('expect');
|
|
302
311
|
}
|
|
303
312
|
function isFunctionCallFromNodeAssert(context, node) {
|
|
304
|
-
const fullyQualifiedName = (0,
|
|
313
|
+
const fullyQualifiedName = (0, module_js_1.getFullyQualifiedName)(context, node);
|
|
305
314
|
return fullyQualifiedName?.split('.')[0] === 'assert';
|
|
306
315
|
}
|
package/cjs/S2703/rule.js
CHANGED
|
@@ -55,11 +55,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.rule = void 0;
|
|
57
57
|
const globals_1 = __importDefault(require("globals"));
|
|
58
|
-
const
|
|
58
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
59
59
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
60
|
const excludedNames = new Set(Object.values(globals_1.default).flatMap(env => Object.keys(env)));
|
|
61
61
|
exports.rule = {
|
|
62
|
-
meta: (0,
|
|
62
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
63
63
|
messages: {
|
|
64
64
|
explicitModifier: 'Add the "let", "const" or "var" keyword to this declaration of "{{variable}}" to make it explicit.',
|
|
65
65
|
},
|