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/S4158/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 ancestor_js_1 = require("../helpers/ancestor.js");
|
|
55
|
+
const collection_js_1 = require("../helpers/collection.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
|
// Methods that mutate the collection but can't add elements
|
|
57
60
|
const nonAdditiveMutatorMethods = [
|
|
@@ -102,7 +105,7 @@ const strictlyReadingMethods = new Set([
|
|
|
102
105
|
...iterationMethods,
|
|
103
106
|
]);
|
|
104
107
|
exports.rule = {
|
|
105
|
-
meta: (0,
|
|
108
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
106
109
|
messages: {
|
|
107
110
|
reviewUsageOfIdentifier: 'Review this usage of "{{identifierName}}" as it can only be empty here.',
|
|
108
111
|
},
|
|
@@ -168,7 +171,7 @@ function reportEmptyCollectionUsage(variable, context) {
|
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
173
|
function isReferenceAssigningEmptyCollection(ref) {
|
|
171
|
-
const declOrExprStmt = (0,
|
|
174
|
+
const declOrExprStmt = (0, ancestor_js_1.findFirstMatchingAncestor)(ref.identifier, n => n.type === 'VariableDeclarator' || n.type === 'ExpressionStatement');
|
|
172
175
|
if (declOrExprStmt) {
|
|
173
176
|
if (declOrExprStmt.type === 'VariableDeclarator' && declOrExprStmt.init) {
|
|
174
177
|
return isEmptyCollectionType(declOrExprStmt.init);
|
|
@@ -176,7 +179,7 @@ function isReferenceAssigningEmptyCollection(ref) {
|
|
|
176
179
|
if (declOrExprStmt.type === 'ExpressionStatement') {
|
|
177
180
|
const { expression } = declOrExprStmt;
|
|
178
181
|
return (expression.type === 'AssignmentExpression' &&
|
|
179
|
-
(0,
|
|
182
|
+
(0, ast_js_1.isReferenceTo)(ref, expression.left) &&
|
|
180
183
|
isEmptyCollectionType(expression.right));
|
|
181
184
|
}
|
|
182
185
|
}
|
|
@@ -187,7 +190,7 @@ function isEmptyCollectionType(node) {
|
|
|
187
190
|
return node.elements.length === 0;
|
|
188
191
|
}
|
|
189
192
|
else if (node?.type === 'CallExpression' || node?.type === 'NewExpression') {
|
|
190
|
-
return (0,
|
|
193
|
+
return (0, ast_js_1.isIdentifier)(node.callee, ...collection_js_1.collectionConstructor) && node.arguments.length === 0;
|
|
191
194
|
}
|
|
192
195
|
return false;
|
|
193
196
|
}
|
|
@@ -199,13 +202,13 @@ function isStrictlyReadingMethodCall(usage) {
|
|
|
199
202
|
if (parent?.type === 'MemberExpression') {
|
|
200
203
|
const memberExpressionParent = parent.parent;
|
|
201
204
|
if (memberExpressionParent?.type === 'CallExpression') {
|
|
202
|
-
return (0,
|
|
205
|
+
return (0, ast_js_1.isIdentifier)(parent.property, ...strictlyReadingMethods);
|
|
203
206
|
}
|
|
204
207
|
}
|
|
205
208
|
return false;
|
|
206
209
|
}
|
|
207
210
|
function isForIterationPattern(ref) {
|
|
208
|
-
const forInOrOfStatement = (0,
|
|
211
|
+
const forInOrOfStatement = (0, ancestor_js_1.findFirstMatchingAncestor)(ref.identifier, n => n.type === 'ForOfStatement' || n.type === 'ForInStatement');
|
|
209
212
|
return forInOrOfStatement && forInOrOfStatement.right === ref.identifier;
|
|
210
213
|
}
|
|
211
214
|
function isElementRead(ref) {
|
|
@@ -216,7 +219,7 @@ function isElementRead(ref) {
|
|
|
216
219
|
}
|
|
217
220
|
const writingAssignmentOperators = new Set(['=', '||=', '&&=', '??=']);
|
|
218
221
|
function isElementWrite(memberExpression) {
|
|
219
|
-
const ancestors = (0,
|
|
222
|
+
const ancestors = (0, ancestor_js_1.ancestorsChain)(memberExpression, new Set());
|
|
220
223
|
const assignment = ancestors.find(n => n.type === 'AssignmentExpression');
|
|
221
224
|
if (assignment && writingAssignmentOperators.has(assignment.operator)) {
|
|
222
225
|
return [memberExpression, ...ancestors].includes(assignment.left);
|
package/cjs/S4165/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 reaching_definitions_js_1 = require("../helpers/reaching-definitions.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
56
|
+
const collection_js_1 = require("../helpers/collection.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
|
reviewAssignment: 'Review this redundant assignment: "{{symbol}}" already holds the assigned value along all execution paths.',
|
|
60
62
|
},
|
|
@@ -80,7 +82,7 @@ exports.rule = {
|
|
|
80
82
|
checkIdentifierUsage(node);
|
|
81
83
|
},
|
|
82
84
|
'Program:exit': () => {
|
|
83
|
-
(0,
|
|
85
|
+
(0, reaching_definitions_js_1.reachingDefinitions)(reachingDefsMap);
|
|
84
86
|
for (const defs of reachingDefsMap.values()) {
|
|
85
87
|
checkSegment(defs);
|
|
86
88
|
}
|
|
@@ -92,7 +94,7 @@ exports.rule = {
|
|
|
92
94
|
},
|
|
93
95
|
// CodePath events
|
|
94
96
|
onCodePathSegmentStart: (segment) => {
|
|
95
|
-
reachingDefsMap.set(segment.id, new
|
|
97
|
+
reachingDefsMap.set(segment.id, new reaching_definitions_js_1.ReachingDefinitions(segment));
|
|
96
98
|
currentCodePathSegments.push(segment);
|
|
97
99
|
},
|
|
98
100
|
onCodePathStart: codePath => {
|
|
@@ -109,7 +111,7 @@ exports.rule = {
|
|
|
109
111
|
},
|
|
110
112
|
};
|
|
111
113
|
function popAssignmentContext() {
|
|
112
|
-
const assignment = (0,
|
|
114
|
+
const assignment = (0, collection_js_1.last)(codePathStack).assignmentStack.pop();
|
|
113
115
|
for (const r of assignment.rhs) {
|
|
114
116
|
processReference(r);
|
|
115
117
|
}
|
|
@@ -118,7 +120,7 @@ exports.rule = {
|
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
function pushAssignmentContext(node) {
|
|
121
|
-
(0,
|
|
123
|
+
(0, collection_js_1.last)(codePathStack).assignmentStack.push(new AssignmentContext(node));
|
|
122
124
|
}
|
|
123
125
|
function checkSegment(reachingDefs) {
|
|
124
126
|
const assignedValuesMap = new Map(reachingDefs.in);
|
|
@@ -128,7 +130,7 @@ exports.rule = {
|
|
|
128
130
|
continue;
|
|
129
131
|
}
|
|
130
132
|
const lhsValues = assignedValuesMap.get(variable);
|
|
131
|
-
const rhsValues = (0,
|
|
133
|
+
const rhsValues = (0, reaching_definitions_js_1.resolveAssignedValues)(variable, ref.writeExpr, assignedValuesMap, ref.from);
|
|
132
134
|
if (lhsValues?.type === 'AssignedValues' && lhsValues?.size === 1) {
|
|
133
135
|
const [lhsVal] = [...lhsValues];
|
|
134
136
|
checkRedundantAssignement(ref, ref.writeExpr, lhsVal, rhsValues, variable.name);
|
|
@@ -187,9 +189,9 @@ exports.rule = {
|
|
|
187
189
|
}
|
|
188
190
|
}
|
|
189
191
|
function processReference(ref) {
|
|
190
|
-
const assignmentStack = (0,
|
|
192
|
+
const assignmentStack = (0, collection_js_1.last)(codePathStack).assignmentStack;
|
|
191
193
|
if (assignmentStack.length > 0) {
|
|
192
|
-
const assignment = (0,
|
|
194
|
+
const assignment = (0, collection_js_1.last)(assignmentStack);
|
|
193
195
|
assignment.add(ref);
|
|
194
196
|
}
|
|
195
197
|
else {
|
|
@@ -205,13 +207,13 @@ exports.rule = {
|
|
|
205
207
|
defs = reachingDefsMap.get(segment.id);
|
|
206
208
|
}
|
|
207
209
|
else {
|
|
208
|
-
defs = new
|
|
210
|
+
defs = new reaching_definitions_js_1.ReachingDefinitions(segment);
|
|
209
211
|
reachingDefsMap.set(segment.id, defs);
|
|
210
212
|
}
|
|
211
213
|
return defs;
|
|
212
214
|
}
|
|
213
215
|
function updateVariableUsages(variable) {
|
|
214
|
-
const codePathId = (0,
|
|
216
|
+
const codePathId = (0, collection_js_1.last)(codePathStack).codePath.id;
|
|
215
217
|
if (variableUsages.has(variable)) {
|
|
216
218
|
variableUsages.get(variable).add(codePathId);
|
|
217
219
|
}
|
|
@@ -295,7 +297,7 @@ class AssignmentContext {
|
|
|
295
297
|
function isSelfAssignement(ref) {
|
|
296
298
|
const lhs = ref.resolved;
|
|
297
299
|
if (ref.writeExpr?.type === 'Identifier') {
|
|
298
|
-
const rhs = (0,
|
|
300
|
+
const rhs = (0, reaching_definitions_js_1.getVariableFromIdentifier)(ref.writeExpr, ref.from);
|
|
299
301
|
return lhs === rhs;
|
|
300
302
|
}
|
|
301
303
|
return false;
|
package/cjs/S4322/rule.js
CHANGED
|
@@ -51,10 +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 location_js_1 = require("../helpers/location.js");
|
|
56
|
+
const ancestor_js_1 = require("../helpers/ancestor.js");
|
|
57
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
55
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
59
|
exports.rule = {
|
|
57
|
-
meta: (0,
|
|
60
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
58
61
|
hasSuggestions: true,
|
|
59
62
|
messages: {
|
|
60
63
|
useTypePredicate: 'Declare this function return type using type predicate "{{castedExpressionText}} is {{castedTypeText}}".',
|
|
@@ -83,10 +86,10 @@ function checkFunctionLikeDeclaration(functionDeclaration, context) {
|
|
|
83
86
|
}
|
|
84
87
|
if (isInequalityBinaryExpression(returnedExpression)) {
|
|
85
88
|
const { left, right } = returnedExpression;
|
|
86
|
-
if ((0,
|
|
89
|
+
if ((0, ast_js_1.isUndefined)(right)) {
|
|
87
90
|
checkCastedType(functionDeclaration, left, context);
|
|
88
91
|
}
|
|
89
|
-
else if ((0,
|
|
92
|
+
else if ((0, ast_js_1.isUndefined)(left)) {
|
|
90
93
|
checkCastedType(functionDeclaration, right, context);
|
|
91
94
|
}
|
|
92
95
|
}
|
|
@@ -126,7 +129,7 @@ function checkCastedType(node, expression, context) {
|
|
|
126
129
|
castedExpressionText,
|
|
127
130
|
castedTypeText,
|
|
128
131
|
},
|
|
129
|
-
loc: (0,
|
|
132
|
+
loc: (0, location_js_1.getMainFunctionTokenLocation)(node, (0, ancestor_js_1.getParent)(context, node), context),
|
|
130
133
|
suggest,
|
|
131
134
|
});
|
|
132
135
|
}
|
package/cjs/S4323/rule.js
CHANGED
|
@@ -51,12 +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 location_js_1 = require("../helpers/location.js");
|
|
55
56
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
57
|
const TYPE_THRESHOLD = 2;
|
|
57
58
|
const USAGE_THRESHOLD = 2;
|
|
58
59
|
exports.rule = {
|
|
59
|
-
meta: (0,
|
|
60
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
60
61
|
create(context) {
|
|
61
62
|
let usage;
|
|
62
63
|
return {
|
|
@@ -67,7 +68,7 @@ exports.rule = {
|
|
|
67
68
|
const [node, ...rest] = nodes;
|
|
68
69
|
const kind = node.type === 'TSUnionType' ? 'union' : 'intersection';
|
|
69
70
|
const message = `Replace this ${kind} type with a type alias.`;
|
|
70
|
-
(0,
|
|
71
|
+
(0, location_js_1.report)(context, { message, loc: node.loc }, rest.map(node => (0, location_js_1.toSecondaryLocation)(node, 'Following occurrence.')));
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
},
|
package/cjs/S4324/rule.js
CHANGED
|
@@ -54,23 +54,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
54
54
|
};
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.rule = void 0;
|
|
57
|
-
const
|
|
57
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
58
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
59
|
+
const collection_js_1 = require("../helpers/collection.js");
|
|
58
60
|
const typescript_1 = __importDefault(require("typescript"));
|
|
59
61
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
62
|
exports.rule = {
|
|
61
|
-
meta: (0,
|
|
63
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
62
64
|
messages: {
|
|
63
65
|
removeOrChangeType: 'Remove this return type or change it to a more specific.',
|
|
64
66
|
},
|
|
65
67
|
}),
|
|
66
68
|
create(context) {
|
|
67
69
|
const services = context.sourceCode.parserServices;
|
|
68
|
-
if ((0,
|
|
70
|
+
if ((0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
69
71
|
const returnedExpressions = [];
|
|
70
72
|
return {
|
|
71
73
|
ReturnStatement(node) {
|
|
72
74
|
if (returnedExpressions.length > 0) {
|
|
73
|
-
(0,
|
|
75
|
+
(0, collection_js_1.last)(returnedExpressions).push(node.argument);
|
|
74
76
|
}
|
|
75
77
|
},
|
|
76
78
|
FunctionDeclaration() {
|
|
@@ -80,7 +82,7 @@ exports.rule = {
|
|
|
80
82
|
const returnType = node.returnType;
|
|
81
83
|
if (returnType?.typeAnnotation.type === 'TSAnyKeyword' &&
|
|
82
84
|
returnedExpressions.length > 0 &&
|
|
83
|
-
allReturnTypesEqual((0,
|
|
85
|
+
allReturnTypesEqual((0, collection_js_1.last)(returnedExpressions), services)) {
|
|
84
86
|
context.report({
|
|
85
87
|
messageId: 'removeOrChangeType',
|
|
86
88
|
loc: returnType.loc,
|
package/cjs/S4328/rule.js
CHANGED
|
@@ -56,14 +56,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
56
56
|
exports.rule = void 0;
|
|
57
57
|
const builtin_modules_1 = __importDefault(require("builtin-modules"));
|
|
58
58
|
const typescript_1 = __importDefault(require("typescript"));
|
|
59
|
-
const
|
|
59
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
60
60
|
const meta = __importStar(require("./generated-meta.js"));
|
|
61
61
|
const dependencies_js_1 = require("../helpers/package-jsons/dependencies.js");
|
|
62
62
|
const messages = {
|
|
63
63
|
removeOrAddDependency: 'Either remove this import or add it as a dependency.',
|
|
64
64
|
};
|
|
65
65
|
exports.rule = {
|
|
66
|
-
meta: (0,
|
|
66
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, { messages }),
|
|
67
67
|
create(context) {
|
|
68
68
|
// we need to find all the npm manifests from the directory of the analyzed file to the context working directory
|
|
69
69
|
const dependencies = (0, dependencies_js_1.getDependenciesSanitizePaths)(context);
|
package/cjs/S4335/rule.js
CHANGED
|
@@ -55,10 +55,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.rule = void 0;
|
|
57
57
|
const typescript_1 = __importDefault(require("typescript"));
|
|
58
|
-
const
|
|
58
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
59
|
+
const ancestor_js_1 = require("../helpers/ancestor.js");
|
|
60
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
59
61
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
62
|
exports.rule = {
|
|
61
|
-
meta: (0,
|
|
63
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
62
64
|
messages: {
|
|
63
65
|
removeIntersection: 'Remove this type without members or change this type intersection.',
|
|
64
66
|
simplifyIntersection: 'Simplify this intersection as it always has type "{{type}}".',
|
|
@@ -66,7 +68,7 @@ exports.rule = {
|
|
|
66
68
|
}),
|
|
67
69
|
create(context) {
|
|
68
70
|
const services = context.sourceCode.parserServices;
|
|
69
|
-
if (!(0,
|
|
71
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
70
72
|
return {};
|
|
71
73
|
}
|
|
72
74
|
function checkIntersectionType(node) {
|
|
@@ -146,7 +148,7 @@ function isLiteralUnionPattern(intersection) {
|
|
|
146
148
|
if (intersection.types.length !== 2) {
|
|
147
149
|
return false;
|
|
148
150
|
}
|
|
149
|
-
const parent = (0,
|
|
151
|
+
const parent = (0, ancestor_js_1.getNodeParent)(intersection);
|
|
150
152
|
if (!parent || parent.type !== 'TSUnionType') {
|
|
151
153
|
return false;
|
|
152
154
|
}
|
package/cjs/S4423/rule.js
CHANGED
|
@@ -53,13 +53,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
53
53
|
exports.rule = void 0;
|
|
54
54
|
const rule_lib_js_1 = require("./rule.lib.js");
|
|
55
55
|
const rule_aws_js_1 = require("./rule.aws.js");
|
|
56
|
-
const
|
|
56
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
57
|
+
const merger_js_1 = require("../helpers/decorators/merger.js");
|
|
57
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
58
59
|
exports.rule = {
|
|
59
|
-
meta: (0,
|
|
60
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
60
61
|
messages: { ...rule_lib_js_1.rule.meta.messages, ...rule_aws_js_1.rule.meta.messages },
|
|
61
62
|
}),
|
|
62
63
|
create(context) {
|
|
63
|
-
return (0,
|
|
64
|
+
return (0, merger_js_1.mergeRules)(rule_lib_js_1.rule.create(context), rule_aws_js_1.rule.create(context));
|
|
64
65
|
},
|
|
65
66
|
};
|
package/cjs/S4423/rule.lib.js
CHANGED
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
// https://sonarsource.github.io/rspec/#/rspec/S4423/javascript
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.rule = void 0;
|
|
21
|
-
const
|
|
21
|
+
const module_js_1 = require("../helpers/module.js");
|
|
22
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
22
23
|
const SECURE_PROTOCOL_ALLOWED_VALUES = new Set([
|
|
23
24
|
'TLSv1_2_method',
|
|
24
25
|
'TLSv1_2_client_method',
|
|
@@ -38,9 +39,9 @@ exports.rule = {
|
|
|
38
39
|
},
|
|
39
40
|
create(context) {
|
|
40
41
|
function getValueOfProperty(objectExpression, propertyName) {
|
|
41
|
-
const unsafeProperty = objectExpression && (0,
|
|
42
|
+
const unsafeProperty = objectExpression && (0, ast_js_1.getProperty)(objectExpression, propertyName, context);
|
|
42
43
|
if (unsafeProperty) {
|
|
43
|
-
return (0,
|
|
44
|
+
return (0, ast_js_1.getValueOfExpression)(context, unsafeProperty.value, 'Literal');
|
|
44
45
|
}
|
|
45
46
|
return undefined;
|
|
46
47
|
}
|
|
@@ -56,7 +57,7 @@ exports.rule = {
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
function checkSslOptions(optionsNode) {
|
|
59
|
-
const options = (0,
|
|
60
|
+
const options = (0, ast_js_1.getValueOfExpression)(context, optionsNode, 'ObjectExpression');
|
|
60
61
|
const minVersion = getValueOfProperty(options, 'minVersion');
|
|
61
62
|
const maxVersion = getValueOfProperty(options, 'maxVersion');
|
|
62
63
|
checkMinMaxVersion('minVersion', minVersion);
|
|
@@ -72,7 +73,7 @@ exports.rule = {
|
|
|
72
73
|
},
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
|
-
const secureOptions = (0,
|
|
76
|
+
const secureOptions = (0, ast_js_1.getProperty)(options, 'secureOptions', context);
|
|
76
77
|
if (secureOptions && !isValidSecureOptions(secureOptions.value)) {
|
|
77
78
|
context.report({
|
|
78
79
|
node: secureOptions,
|
|
@@ -95,7 +96,7 @@ exports.rule = {
|
|
|
95
96
|
collectIdentifiersFromBinary(node.right, acc);
|
|
96
97
|
}
|
|
97
98
|
else if (node.type === 'MemberExpression' &&
|
|
98
|
-
(0,
|
|
99
|
+
(0, module_js_1.getFullyQualifiedName)(context, node.object) === 'constants' &&
|
|
99
100
|
node.property.type === 'Identifier') {
|
|
100
101
|
acc.push(node.property.name);
|
|
101
102
|
}
|
|
@@ -107,7 +108,7 @@ exports.rule = {
|
|
|
107
108
|
return {
|
|
108
109
|
CallExpression: (node) => {
|
|
109
110
|
const callExpression = node;
|
|
110
|
-
const fqn = (0,
|
|
111
|
+
const fqn = (0, module_js_1.getFullyQualifiedName)(context, callExpression);
|
|
111
112
|
// https://nodejs.org/api/https.html#https_https_get_options_callback
|
|
112
113
|
if (fqn === 'https.request') {
|
|
113
114
|
checkSslOptions(callExpression.arguments[0]);
|
package/cjs/S4426/rule.js
CHANGED
|
@@ -51,7 +51,8 @@ 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
|
const MINIMAL_MODULUS_LENGTH = 2048;
|
|
57
58
|
const MINIMAL_DIVISOR_LENGTH = 224;
|
|
@@ -82,7 +83,7 @@ const WEAK_CURVES = new Set([
|
|
|
82
83
|
'c2tnb191v3',
|
|
83
84
|
]);
|
|
84
85
|
exports.rule = {
|
|
85
|
-
meta: (0,
|
|
86
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
86
87
|
messages: {
|
|
87
88
|
modulusLength: 'Use a modulus length of at least {{minimalLength}} bits for {{algorithm}} cipher algorithm.',
|
|
88
89
|
divisorLength: 'Use a divisor length of at least {{minimalLength}} bits for {{algorithm}} cipher algorithm.',
|
|
@@ -91,14 +92,14 @@ exports.rule = {
|
|
|
91
92
|
}),
|
|
92
93
|
create(context) {
|
|
93
94
|
function getNumericValue(node) {
|
|
94
|
-
const literal = (0,
|
|
95
|
+
const literal = (0, ast_js_1.getValueOfExpression)(context, node, 'Literal');
|
|
95
96
|
if (literal && typeof literal.value === 'number') {
|
|
96
97
|
return literal.value;
|
|
97
98
|
}
|
|
98
99
|
return undefined;
|
|
99
100
|
}
|
|
100
101
|
function checkRsaAndDsaOptions(algorithm, options) {
|
|
101
|
-
const modulusProperty = (0,
|
|
102
|
+
const modulusProperty = (0, ast_js_1.getProperty)(options, 'modulusLength', context);
|
|
102
103
|
const modulusLength = getNumericValue(modulusProperty?.value);
|
|
103
104
|
if (modulusProperty && modulusLength && modulusLength < MINIMAL_MODULUS_LENGTH) {
|
|
104
105
|
context.report({
|
|
@@ -110,7 +111,7 @@ exports.rule = {
|
|
|
110
111
|
},
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
|
-
const divisorProperty = (0,
|
|
114
|
+
const divisorProperty = (0, ast_js_1.getProperty)(options, 'divisorLength', context);
|
|
114
115
|
const divisorLength = getNumericValue(divisorProperty?.value);
|
|
115
116
|
if (divisorProperty && divisorLength && divisorLength < MINIMAL_DIVISOR_LENGTH) {
|
|
116
117
|
context.report({
|
|
@@ -124,8 +125,8 @@ exports.rule = {
|
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
function checkEcCurve(options) {
|
|
127
|
-
const namedCurveProperty = (0,
|
|
128
|
-
const namedCurve = (0,
|
|
128
|
+
const namedCurveProperty = (0, ast_js_1.getProperty)(options, 'namedCurve', context);
|
|
129
|
+
const namedCurve = (0, ast_js_1.getValueOfExpression)(context, namedCurveProperty?.value, 'Literal')?.value?.toString();
|
|
129
130
|
if (namedCurveProperty && namedCurve && WEAK_CURVES.has(namedCurve)) {
|
|
130
131
|
context.report({
|
|
131
132
|
node: namedCurveProperty,
|
|
@@ -141,16 +142,16 @@ exports.rule = {
|
|
|
141
142
|
const callExpression = node;
|
|
142
143
|
const { callee } = callExpression;
|
|
143
144
|
if (callee.type === 'MemberExpression' &&
|
|
144
|
-
(0,
|
|
145
|
+
(0, ast_js_1.isIdentifier)(callee.property, 'generateKeyPair', 'generateKeyPairSync')) {
|
|
145
146
|
if (callExpression.arguments.length < 2) {
|
|
146
147
|
return;
|
|
147
148
|
}
|
|
148
149
|
const [algorithmArg, options] = callExpression.arguments;
|
|
149
|
-
const optionsArg = (0,
|
|
150
|
+
const optionsArg = (0, ast_js_1.getValueOfExpression)(context, options, 'ObjectExpression');
|
|
150
151
|
if (!optionsArg) {
|
|
151
152
|
return;
|
|
152
153
|
}
|
|
153
|
-
const algorithm = (0,
|
|
154
|
+
const algorithm = (0, ast_js_1.getValueOfExpression)(context, algorithmArg, 'Literal')?.value;
|
|
154
155
|
if (algorithm === 'rsa' || algorithm === 'dsa') {
|
|
155
156
|
checkRsaAndDsaOptions(algorithm, optionsArg);
|
|
156
157
|
}
|
package/cjs/S4502/rule.js
CHANGED
|
@@ -51,12 +51,15 @@ 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 ast_js_1 = require("../helpers/ast.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
56
|
+
const module_js_1 = require("../helpers/module.js");
|
|
57
|
+
const location_js_1 = require("../helpers/location.js");
|
|
55
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
59
|
const CSURF_MODULE = 'csurf';
|
|
57
60
|
const SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
|
|
58
61
|
exports.rule = {
|
|
59
|
-
meta: (0,
|
|
62
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
60
63
|
create(context) {
|
|
61
64
|
let globalCsrfProtection = false;
|
|
62
65
|
let importedCsrfMiddleware = false;
|
|
@@ -64,45 +67,45 @@ exports.rule = {
|
|
|
64
67
|
if (node.value.type === 'ArrayExpression') {
|
|
65
68
|
const arrayExpr = node.value;
|
|
66
69
|
const unsafeMethods = arrayExpr.elements
|
|
67
|
-
.filter(
|
|
70
|
+
.filter(ast_js_1.isLiteral)
|
|
68
71
|
.filter(e => typeof e.value === 'string' && !SAFE_METHODS.has(e.value));
|
|
69
72
|
if (unsafeMethods.length > 0) {
|
|
70
73
|
const [first, ...rest] = unsafeMethods;
|
|
71
|
-
(0,
|
|
74
|
+
(0, location_js_1.report)(context, {
|
|
72
75
|
message: 'Make sure disabling CSRF protection is safe here.',
|
|
73
76
|
node: first,
|
|
74
|
-
}, rest.map(node => (0,
|
|
77
|
+
}, rest.map(node => (0, location_js_1.toSecondaryLocation)(node)));
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
function isCsurfMiddleware(node) {
|
|
79
|
-
return node && (0,
|
|
82
|
+
return node && (0, module_js_1.getFullyQualifiedName)(context, node) === CSURF_MODULE;
|
|
80
83
|
}
|
|
81
84
|
function checkCallExpression(callExpression) {
|
|
82
85
|
const { callee } = callExpression;
|
|
83
86
|
// require('csurf')
|
|
84
|
-
if ((0,
|
|
87
|
+
if ((0, ast_js_1.isRequireModule)(callExpression, CSURF_MODULE)) {
|
|
85
88
|
importedCsrfMiddleware = true;
|
|
86
89
|
}
|
|
87
90
|
// csurf(...)
|
|
88
|
-
if ((0,
|
|
91
|
+
if ((0, module_js_1.getFullyQualifiedName)(context, callee) === CSURF_MODULE) {
|
|
89
92
|
const [args] = callExpression.arguments;
|
|
90
|
-
const ignoredMethods = (0,
|
|
93
|
+
const ignoredMethods = (0, ast_js_1.getProperty)(args, 'ignoreMethods', context);
|
|
91
94
|
if (ignoredMethods) {
|
|
92
95
|
checkIgnoredMethods(ignoredMethods);
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
// app.use(csurf(...))
|
|
96
99
|
if (callee.type === 'MemberExpression') {
|
|
97
|
-
if ((0,
|
|
98
|
-
(0,
|
|
100
|
+
if ((0, ast_js_1.isIdentifier)(callee.property, 'use') &&
|
|
101
|
+
(0, ast_js_1.flattenArgs)(context, callExpression.arguments).some(isCsurfMiddleware)) {
|
|
99
102
|
globalCsrfProtection = true;
|
|
100
103
|
}
|
|
101
|
-
if ((0,
|
|
104
|
+
if ((0, ast_js_1.isIdentifier)(callee.property, 'post', 'put', 'delete', 'patch') &&
|
|
102
105
|
!globalCsrfProtection &&
|
|
103
106
|
importedCsrfMiddleware &&
|
|
104
107
|
!callExpression.arguments.some(arg => isCsurfMiddleware(arg))) {
|
|
105
|
-
(0,
|
|
108
|
+
(0, location_js_1.report)(context, {
|
|
106
109
|
message: 'Make sure not using CSRF protection is safe here.',
|
|
107
110
|
node: callee,
|
|
108
111
|
});
|
package/cjs/S4507/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 ast_js_1 = require("../helpers/ast.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
56
|
+
const module_js_1 = require("../helpers/module.js");
|
|
55
57
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
58
|
const ERRORHANDLER_MODULE = 'errorhandler';
|
|
57
59
|
exports.rule = {
|
|
58
|
-
meta: (0,
|
|
60
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
59
61
|
messages: {
|
|
60
62
|
deactivateDebug: 'Make sure this debug feature is deactivated before delivering the code in production.',
|
|
61
63
|
},
|
|
@@ -72,13 +74,13 @@ exports.rule = {
|
|
|
72
74
|
};
|
|
73
75
|
function checkErrorHandlerMiddleware(context, callExpression) {
|
|
74
76
|
const { callee, arguments: args } = callExpression;
|
|
75
|
-
if ((0,
|
|
77
|
+
if ((0, ast_js_1.isMemberWithProperty)(callee, 'use') &&
|
|
76
78
|
args.length > 0 &&
|
|
77
79
|
!isInsideConditional(context, callExpression)) {
|
|
78
|
-
for (const m of (0,
|
|
79
|
-
const middleware = (0,
|
|
80
|
+
for (const m of (0, ast_js_1.flattenArgs)(context, args)) {
|
|
81
|
+
const middleware = (0, ast_js_1.getUniqueWriteUsageOrNode)(context, m);
|
|
80
82
|
if (middleware.type === 'CallExpression' &&
|
|
81
|
-
(0,
|
|
83
|
+
(0, module_js_1.getFullyQualifiedName)(context, middleware) === ERRORHANDLER_MODULE) {
|
|
82
84
|
context.report({
|
|
83
85
|
node: middleware,
|
|
84
86
|
messageId: 'deactivateDebug',
|
package/cjs/S4524/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
|
defaultLast: 'Move this "default" clause to the end of this "switch" statement.',
|
|
60
60
|
},
|
package/cjs/S4619/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 type_js_1 = require("../helpers/type.js");
|
|
56
|
+
const parser_services_js_1 = require("../helpers/parser-services.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
|
hasSuggestions: true,
|
|
59
61
|
messages: {
|
|
60
62
|
inMisuse: 'Use "indexOf" or "includes" (available from ES2016) instead.',
|
|
@@ -64,13 +66,13 @@ exports.rule = {
|
|
|
64
66
|
}),
|
|
65
67
|
create(context) {
|
|
66
68
|
const services = context.sourceCode.parserServices;
|
|
67
|
-
if (!(0,
|
|
69
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
68
70
|
return {};
|
|
69
71
|
}
|
|
70
72
|
return {
|
|
71
73
|
"BinaryExpression[operator='in']": (node) => {
|
|
72
74
|
const { left, right } = node;
|
|
73
|
-
if ((0,
|
|
75
|
+
if ((0, type_js_1.isArray)(right, services) && !prototypeProperty(left) && !(0, type_js_1.isNumber)(left, services)) {
|
|
74
76
|
const leftText = context.sourceCode.getText(left);
|
|
75
77
|
const rightText = context.sourceCode.getText(right);
|
|
76
78
|
context.report({
|