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/S6759/rule.js
CHANGED
|
@@ -54,12 +54,16 @@ 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 type_js_1 = require("../helpers/type.js");
|
|
60
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
61
|
+
const collection_js_1 = require("../helpers/collection.js");
|
|
58
62
|
const ts_api_utils_1 = require("ts-api-utils");
|
|
59
63
|
const typescript_1 = __importDefault(require("typescript"));
|
|
60
64
|
const meta = __importStar(require("./generated-meta.js"));
|
|
61
65
|
exports.rule = {
|
|
62
|
-
meta: (0,
|
|
66
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
63
67
|
hasSuggestions: true,
|
|
64
68
|
messages: {
|
|
65
69
|
readOnlyProps: 'Mark the props of the component as read-only.',
|
|
@@ -68,7 +72,7 @@ exports.rule = {
|
|
|
68
72
|
}),
|
|
69
73
|
create(context) {
|
|
70
74
|
const services = context.sourceCode.parserServices;
|
|
71
|
-
if (!(0,
|
|
75
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
72
76
|
return {};
|
|
73
77
|
}
|
|
74
78
|
const functionInfo = [];
|
|
@@ -112,7 +116,7 @@ exports.rule = {
|
|
|
112
116
|
}
|
|
113
117
|
},
|
|
114
118
|
ReturnStatement(node) {
|
|
115
|
-
const current = (0,
|
|
119
|
+
const current = (0, collection_js_1.last)(functionInfo);
|
|
116
120
|
if (current) {
|
|
117
121
|
current.returns.push(node);
|
|
118
122
|
}
|
|
@@ -144,7 +148,7 @@ exports.rule = {
|
|
|
144
148
|
if (!ret.argument) {
|
|
145
149
|
continue;
|
|
146
150
|
}
|
|
147
|
-
const value = (0,
|
|
151
|
+
const value = (0, ast_js_1.getUniqueWriteUsageOrNode)(context, ret.argument);
|
|
148
152
|
if (value.type.startsWith('JSX')) {
|
|
149
153
|
return true;
|
|
150
154
|
}
|
|
@@ -159,7 +163,7 @@ exports.rule = {
|
|
|
159
163
|
* resolved properties are read-only (regardless of how the type was constructed).
|
|
160
164
|
*/
|
|
161
165
|
function isReadOnly(props, services) {
|
|
162
|
-
const type = (0,
|
|
166
|
+
const type = (0, type_js_1.getTypeFromTreeNode)(props, services);
|
|
163
167
|
const checker = services.program.getTypeChecker();
|
|
164
168
|
/* Readonly utility type */
|
|
165
169
|
if (type.aliasSymbol?.escapedName === 'Readonly') {
|
package/cjs/S6958/rule.js
CHANGED
|
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.rule = void 0;
|
|
37
|
-
const
|
|
37
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
38
38
|
const meta = __importStar(require("./generated-meta.js"));
|
|
39
39
|
const NODES = new Set([
|
|
40
40
|
'ArrayExpression',
|
|
@@ -44,7 +44,7 @@ const NODES = new Set([
|
|
|
44
44
|
'TemplateLiteral',
|
|
45
45
|
]);
|
|
46
46
|
exports.rule = {
|
|
47
|
-
meta: (0,
|
|
47
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
48
48
|
messages: {
|
|
49
49
|
asFunction: 'Literal should not be used as function.',
|
|
50
50
|
asTagFunction: 'Literal should not be used as tag function.',
|
package/cjs/S6959/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 ast_js_1 = require("../helpers/ast.js");
|
|
56
|
+
const type_js_1 = require("../helpers/type.js");
|
|
57
|
+
const parser_services_js_1 = require("../helpers/parser-services.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
|
messages: {
|
|
59
62
|
message: 'Add an initial value to this "reduce()" call.',
|
|
60
63
|
},
|
|
@@ -62,16 +65,16 @@ exports.rule = {
|
|
|
62
65
|
create(context) {
|
|
63
66
|
const services = context.sourceCode.parserServices;
|
|
64
67
|
function isArray(node) {
|
|
65
|
-
if ((0,
|
|
66
|
-
return (0,
|
|
68
|
+
if ((0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
69
|
+
return (0, type_js_1.isArray)(node, services);
|
|
67
70
|
}
|
|
68
71
|
else {
|
|
69
|
-
return (0,
|
|
72
|
+
return (0, ast_js_1.isArrayExpression)((0, ast_js_1.getUniqueWriteUsageOrNode)(context, node));
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
return {
|
|
73
76
|
CallExpression(node) {
|
|
74
|
-
if ((0,
|
|
77
|
+
if ((0, ast_js_1.isCallingMethod)(node, 1, 'reduce') && isArray(node.callee.object)) {
|
|
75
78
|
context.report({
|
|
76
79
|
node: node.callee.property,
|
|
77
80
|
messageId: 'message',
|
|
@@ -39,7 +39,7 @@ exports.meta = {
|
|
|
39
39
|
description: 'Constructors should not contain asynchronous operations',
|
|
40
40
|
recommended: true,
|
|
41
41
|
url: 'https://sonarsource.github.io/rspec/#/rspec/S7059/javascript',
|
|
42
|
-
requiresTypeChecking:
|
|
42
|
+
requiresTypeChecking: true,
|
|
43
43
|
},
|
|
44
44
|
fixable: undefined,
|
|
45
45
|
deprecated: false,
|
package/cjs/S7059/rule.js
CHANGED
|
@@ -51,18 +51,21 @@ 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");
|
|
57
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
55
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
59
|
const flaggedStatements = new Set();
|
|
57
60
|
exports.rule = {
|
|
58
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
59
62
|
messages: {
|
|
60
63
|
noAsyncConstructor: 'Refactor this asynchronous operation outside of the constructor.',
|
|
61
64
|
},
|
|
62
65
|
}),
|
|
63
66
|
create(context) {
|
|
64
67
|
const services = context.sourceCode.parserServices;
|
|
65
|
-
if (!(0,
|
|
68
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
66
69
|
return {};
|
|
67
70
|
}
|
|
68
71
|
/**
|
|
@@ -88,7 +91,7 @@ exports.rule = {
|
|
|
88
91
|
statement = ancestor;
|
|
89
92
|
}
|
|
90
93
|
// If we find a function declaration it should not be considered as part of the constructor
|
|
91
|
-
if (classConstructor && statement && (0,
|
|
94
|
+
if (classConstructor && statement && (0, ast_js_1.isFunctionNode)(ancestor)) {
|
|
92
95
|
statement = undefined;
|
|
93
96
|
classConstructor = undefined;
|
|
94
97
|
}
|
|
@@ -97,7 +100,7 @@ exports.rule = {
|
|
|
97
100
|
}
|
|
98
101
|
return {
|
|
99
102
|
CallExpression(node) {
|
|
100
|
-
if (!(0,
|
|
103
|
+
if (!(0, type_js_1.isThenable)(node, services)) {
|
|
101
104
|
return;
|
|
102
105
|
}
|
|
103
106
|
// we want to raise on the parent statement
|
package/cjs/S7639/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 ast_js_1 = require("../helpers/ast.js");
|
|
55
56
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
57
|
const BLOCKCHAIN_MODULES = ['ethers', 'viem/accounts', 'tronweb'];
|
|
57
58
|
const MNEMONIC_FUNCTIONS = ['fromPhrase', 'mnemonicToAccount', 'fromMnemonic'];
|
|
58
59
|
exports.rule = {
|
|
59
|
-
meta: (0,
|
|
60
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
60
61
|
messages: {
|
|
61
62
|
reviewBlockchainSeedPhrase: `Revoke and change this seed phrase, as it is compromised.`,
|
|
62
63
|
},
|
|
@@ -87,7 +88,7 @@ exports.rule = {
|
|
|
87
88
|
return expr;
|
|
88
89
|
}
|
|
89
90
|
function isMnemonicFunction(callee) {
|
|
90
|
-
return MNEMONIC_FUNCTIONS.some(func => (0,
|
|
91
|
+
return MNEMONIC_FUNCTIONS.some(func => (0, ast_js_1.isMemberWithProperty)(callee, func) || (0, ast_js_1.isIdentifier)(callee, func));
|
|
91
92
|
}
|
|
92
93
|
return {
|
|
93
94
|
Program() {
|
|
@@ -109,7 +110,7 @@ exports.rule = {
|
|
|
109
110
|
}
|
|
110
111
|
},
|
|
111
112
|
CallExpression(node) {
|
|
112
|
-
if ((0,
|
|
113
|
+
if ((0, ast_js_1.isRequireModule)(node, ...BLOCKCHAIN_MODULES)) {
|
|
113
114
|
isBlockchainModuleImported = true;
|
|
114
115
|
return;
|
|
115
116
|
}
|
package/cjs/S7790/rule.js
CHANGED
|
@@ -51,7 +51,9 @@ 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 templatingFqns = new Set([
|
|
57
59
|
'pug.compile',
|
|
@@ -60,7 +62,7 @@ const templatingFqns = new Set([
|
|
|
60
62
|
'ejs.render',
|
|
61
63
|
]);
|
|
62
64
|
exports.rule = {
|
|
63
|
-
meta: (0,
|
|
65
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
64
66
|
messages: {
|
|
65
67
|
reviewDynamicTemplate: `Make sure this dynamically formatted template is safe here.`,
|
|
66
68
|
},
|
|
@@ -69,7 +71,7 @@ exports.rule = {
|
|
|
69
71
|
return {
|
|
70
72
|
CallExpression: (node) => {
|
|
71
73
|
const callExpression = node;
|
|
72
|
-
const fqn = (0,
|
|
74
|
+
const fqn = (0, module_js_1.getFullyQualifiedName)(context, callExpression);
|
|
73
75
|
if (fqn &&
|
|
74
76
|
templatingFqns.has(fqn) &&
|
|
75
77
|
!isCallingFunctionResult(context, callExpression) &&
|
|
@@ -93,11 +95,11 @@ function isCallingFunctionResult(context, callExpression) {
|
|
|
93
95
|
if (callee.type !== 'Identifier') {
|
|
94
96
|
return false;
|
|
95
97
|
}
|
|
96
|
-
const variable = (0,
|
|
98
|
+
const variable = (0, ast_js_1.getVariableFromScope)(context.sourceCode.getScope(callee), callee.name);
|
|
97
99
|
if (!variable || variable.defs.some(def => def.type === 'ImportBinding')) {
|
|
98
100
|
return false;
|
|
99
101
|
}
|
|
100
|
-
const writeRef = (0,
|
|
102
|
+
const writeRef = (0, ast_js_1.getUniqueWriteReference)(variable);
|
|
101
103
|
return writeRef?.type === 'CallExpression';
|
|
102
104
|
}
|
|
103
105
|
function isQuestionable(node, index = 0) {
|
package/cjs/S8441/rule.js
CHANGED
|
@@ -51,7 +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 express_js_1 = require("../helpers/express.js");
|
|
55
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
56
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
57
|
+
const module_js_1 = require("../helpers/module.js");
|
|
58
|
+
const location_js_1 = require("../helpers/location.js");
|
|
55
59
|
// If a rule has a schema, use this to extract it.
|
|
56
60
|
// import { FromSchema } from 'json-schema-to-ts';
|
|
57
61
|
const meta = __importStar(require("./generated-meta.js"));
|
|
@@ -63,7 +67,7 @@ const messages = {
|
|
|
63
67
|
const SESSION_MIDDLEWARES = ['express-session', 'cookie-session'];
|
|
64
68
|
const STATIC_MIDDLEWARES = ['express.static'];
|
|
65
69
|
exports.rule = {
|
|
66
|
-
meta: (0,
|
|
70
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, { messages }),
|
|
67
71
|
create(context) {
|
|
68
72
|
let app = null;
|
|
69
73
|
let lastSessionMiddleware = null;
|
|
@@ -72,7 +76,7 @@ exports.rule = {
|
|
|
72
76
|
if (node.type !== 'CallExpression') {
|
|
73
77
|
return false;
|
|
74
78
|
}
|
|
75
|
-
const fqn = (0,
|
|
79
|
+
const fqn = (0, module_js_1.getFullyQualifiedName)(context, node);
|
|
76
80
|
return fqn !== null && names.includes(fqn);
|
|
77
81
|
}
|
|
78
82
|
return {
|
|
@@ -83,7 +87,7 @@ exports.rule = {
|
|
|
83
87
|
},
|
|
84
88
|
':function'(node) {
|
|
85
89
|
scopeStack.push({ app, lastSessionMiddleware });
|
|
86
|
-
const injectedApp =
|
|
90
|
+
const injectedApp = (0, express_js_1.attemptFindAppInjection)(node, context, node);
|
|
87
91
|
if (injectedApp) {
|
|
88
92
|
app = injectedApp;
|
|
89
93
|
lastSessionMiddleware = null;
|
|
@@ -98,7 +102,7 @@ exports.rule = {
|
|
|
98
102
|
},
|
|
99
103
|
VariableDeclarator(node) {
|
|
100
104
|
const varDecl = node;
|
|
101
|
-
const instantiatedApp =
|
|
105
|
+
const instantiatedApp = (0, express_js_1.attemptFindAppInstantiation)(varDecl, context);
|
|
102
106
|
if (instantiatedApp) {
|
|
103
107
|
app = instantiatedApp;
|
|
104
108
|
lastSessionMiddleware = null;
|
|
@@ -109,21 +113,21 @@ exports.rule = {
|
|
|
109
113
|
return;
|
|
110
114
|
}
|
|
111
115
|
const callExpr = node;
|
|
112
|
-
if (!(0,
|
|
116
|
+
if (!(0, ast_js_1.isMethodInvocation)(callExpr, app.name, 'use', 1)) {
|
|
113
117
|
return;
|
|
114
118
|
}
|
|
115
|
-
const flattenedArgs = (0,
|
|
119
|
+
const flattenedArgs = (0, ast_js_1.flattenArgs)(context, callExpr.arguments);
|
|
116
120
|
for (const middlewareNode of flattenedArgs) {
|
|
117
121
|
if (isMiddleware(context, middlewareNode, SESSION_MIDDLEWARES)) {
|
|
118
122
|
lastSessionMiddleware = callExpr;
|
|
119
123
|
continue;
|
|
120
124
|
}
|
|
121
125
|
if (lastSessionMiddleware && isMiddleware(context, middlewareNode, STATIC_MIDDLEWARES)) {
|
|
122
|
-
(0,
|
|
126
|
+
(0, location_js_1.report)(context, {
|
|
123
127
|
node: callExpr,
|
|
124
128
|
messageId: 'moveStaticBeforeSession',
|
|
125
129
|
message: messages.moveStaticBeforeSession,
|
|
126
|
-
}, [(0,
|
|
130
|
+
}, [(0, location_js_1.toSecondaryLocation)(lastSessionMiddleware, messages.sessionSecondaryLocation)]);
|
|
127
131
|
}
|
|
128
132
|
}
|
|
129
133
|
},
|
package/cjs/S881/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
|
extractOperation: 'Extract this {{incrementType}} operation into a dedicated statement.',
|
|
60
60
|
},
|
package/cjs/S888/rule.js
CHANGED
|
@@ -51,13 +51,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
55
56
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
57
|
const allEqualityOperators = new Set(['!=', '==', '!==', '===']);
|
|
57
58
|
const notEqualOperators = new Set(['!==', '!=']);
|
|
58
59
|
const plusMinusOperators = new Set(['+=', '-=']);
|
|
59
60
|
exports.rule = {
|
|
60
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
61
62
|
messages: {
|
|
62
63
|
replaceOperator: "Replace '{{operator}}' operator with one of '<=', '>=', '<', or '>' comparison operators.",
|
|
63
64
|
},
|
|
@@ -164,7 +165,7 @@ function isUpdateByOne(update, loopBody, context) {
|
|
|
164
165
|
}
|
|
165
166
|
function isUsedInsideBody(id, loopBody, context) {
|
|
166
167
|
if (id.type === 'Identifier') {
|
|
167
|
-
const variable = (0,
|
|
168
|
+
const variable = (0, ast_js_1.getVariableFromName)(context, id.name, id);
|
|
168
169
|
const bodyRange = loopBody.range;
|
|
169
170
|
if (variable && bodyRange) {
|
|
170
171
|
return variable.references.some(ref => isInBody(ref.identifier, bodyRange));
|
package/cjs/S930/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 location_js_1 = require("../helpers/location.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
|
const message = 'This function expects {{expectedArguments}}, but {{providedArguments}} provided.';
|
|
57
59
|
exports.rule = {
|
|
58
|
-
meta: (0,
|
|
60
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
59
61
|
messages: {
|
|
60
62
|
tooManyArguments: message,
|
|
61
63
|
},
|
|
@@ -66,7 +68,7 @@ exports.rule = {
|
|
|
66
68
|
const emptyFunctions = new Set();
|
|
67
69
|
return {
|
|
68
70
|
CallExpression(callExpr) {
|
|
69
|
-
if ((0,
|
|
71
|
+
if ((0, ast_js_1.isIdentifier)(callExpr.callee)) {
|
|
70
72
|
const reference = context.sourceCode
|
|
71
73
|
.getScope(callExpr)
|
|
72
74
|
.references.find(ref => ref.identifier === callExpr.callee);
|
|
@@ -77,14 +79,14 @@ exports.rule = {
|
|
|
77
79
|
}
|
|
78
80
|
else if (definition.type === 'Variable') {
|
|
79
81
|
const { init } = definition.node;
|
|
80
|
-
if (init && ((0,
|
|
82
|
+
if (init && ((0, ast_js_1.isFunctionExpression)(init) || (0, ast_js_1.isArrowFunctionExpression)(init))) {
|
|
81
83
|
checkFunction(callExpr, init);
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
|
-
else if ((0,
|
|
87
|
-
(0,
|
|
88
|
+
else if ((0, ast_js_1.isArrowFunctionExpression)(callExpr.callee) ||
|
|
89
|
+
(0, ast_js_1.isFunctionExpression)(callExpr.callee)) {
|
|
88
90
|
// IIFE
|
|
89
91
|
checkFunction(callExpr, callExpr.callee);
|
|
90
92
|
}
|
|
@@ -120,8 +122,8 @@ exports.rule = {
|
|
|
120
122
|
// special `arguments` variable has no definition
|
|
121
123
|
if (!definition) {
|
|
122
124
|
const ancestors = context.sourceCode.getAncestors(identifier).reverse();
|
|
123
|
-
const fn = ancestors.find(node => (0,
|
|
124
|
-
(0,
|
|
125
|
+
const fn = ancestors.find(node => (0, ast_js_1.isFunctionDeclaration)(node) ||
|
|
126
|
+
(0, ast_js_1.isFunctionExpression)(node));
|
|
125
127
|
if (fn) {
|
|
126
128
|
usingArguments.add(fn);
|
|
127
129
|
}
|
|
@@ -145,7 +147,7 @@ exports.rule = {
|
|
|
145
147
|
const providedArguments = argsLength === 0 ? "none was" :
|
|
146
148
|
argsLength === 1 ? "1 was" :
|
|
147
149
|
`${argsLength} were`;
|
|
148
|
-
(0,
|
|
150
|
+
(0, location_js_1.report)(context, {
|
|
149
151
|
message,
|
|
150
152
|
messageId: 'tooManyArguments',
|
|
151
153
|
data: {
|
|
@@ -159,13 +161,13 @@ exports.rule = {
|
|
|
159
161
|
const paramLength = functionNode.params.length;
|
|
160
162
|
const secondaryLocations = [];
|
|
161
163
|
if (paramLength > 0) {
|
|
162
|
-
secondaryLocations.push((0,
|
|
164
|
+
secondaryLocations.push((0, location_js_1.toSecondaryLocation)(functionNode.params[0], functionNode.params[paramLength - 1], 'Formal parameters'));
|
|
163
165
|
}
|
|
164
166
|
else {
|
|
165
167
|
// as we're not providing parent node, `getMainFunctionTokenLocation` may return `undefined`
|
|
166
|
-
const fnToken = (0,
|
|
168
|
+
const fnToken = (0, location_js_1.getMainFunctionTokenLocation)(functionNode, undefined, context);
|
|
167
169
|
if (fnToken) {
|
|
168
|
-
secondaryLocations.push((0,
|
|
170
|
+
secondaryLocations.push((0, location_js_1.toSecondaryLocation)({ loc: fnToken }, 'Formal parameters'));
|
|
169
171
|
}
|
|
170
172
|
}
|
|
171
173
|
// find actual extra arguments to highlight
|
package/cjs/helpers/ast.js
CHANGED
|
@@ -56,7 +56,10 @@ exports.isProperty = isProperty;
|
|
|
56
56
|
exports.isUnresolved = isUnresolved;
|
|
57
57
|
exports.hasParent = hasParent;
|
|
58
58
|
exports.hasTypePredicateReturn = hasTypePredicateReturn;
|
|
59
|
-
const
|
|
59
|
+
const ancestor_js_1 = require("./ancestor.js");
|
|
60
|
+
const collection_js_1 = require("./collection.js");
|
|
61
|
+
const module_js_1 = require("./module.js");
|
|
62
|
+
const location_js_1 = require("./location.js");
|
|
60
63
|
const MODULE_DECLARATION_NODES = new Set([
|
|
61
64
|
'ImportDeclaration',
|
|
62
65
|
'ExportNamedDeclaration',
|
|
@@ -256,7 +259,7 @@ function isNodeType(node, type) {
|
|
|
256
259
|
*/
|
|
257
260
|
function getLhsVariable(context, node) {
|
|
258
261
|
const ancestors = context.sourceCode.getAncestors(node);
|
|
259
|
-
const parent = (0,
|
|
262
|
+
const parent = (0, collection_js_1.last)(ancestors);
|
|
260
263
|
let formIdentifier;
|
|
261
264
|
if (parent.type === 'VariableDeclarator' && parent.id.type === 'Identifier') {
|
|
262
265
|
formIdentifier = parent.id;
|
|
@@ -304,13 +307,13 @@ function flattenArgs(context, args) {
|
|
|
304
307
|
function recHelper(nodePossiblyIdentifier) {
|
|
305
308
|
const n = getUniqueWriteUsageOrNode(context, nodePossiblyIdentifier);
|
|
306
309
|
if (n.type === 'ArrayExpression') {
|
|
307
|
-
return (0,
|
|
310
|
+
return (0, collection_js_1.flatMap)(n.elements, recHelper);
|
|
308
311
|
}
|
|
309
312
|
else {
|
|
310
313
|
return [n];
|
|
311
314
|
}
|
|
312
315
|
}
|
|
313
|
-
return (0,
|
|
316
|
+
return (0, collection_js_1.flatMap)(args, recHelper);
|
|
314
317
|
}
|
|
315
318
|
function resolveIdentifiers(node, acceptShorthand = false) {
|
|
316
319
|
const identifiers = [];
|
|
@@ -363,7 +366,7 @@ function getPropertyWithValue(context, objectExpression, propertyName, propertyV
|
|
|
363
366
|
}
|
|
364
367
|
function getPropertyFromSpreadElement(spreadElement, key, ctx) {
|
|
365
368
|
const props = getValueOfExpression(ctx, spreadElement.argument, 'ObjectExpression');
|
|
366
|
-
const recursiveDefinition = (0,
|
|
369
|
+
const recursiveDefinition = (0, ancestor_js_1.findFirstMatchingAncestor)(spreadElement.argument, node => node === props);
|
|
367
370
|
if (recursiveDefinition || props === undefined) {
|
|
368
371
|
return undefined;
|
|
369
372
|
}
|
|
@@ -436,10 +439,10 @@ function checkSensitiveCall(context, callExpression, sensitiveArgumentIndex, sen
|
|
|
436
439
|
}
|
|
437
440
|
const unsafeProperty = getPropertyWithValue(context, options, sensitiveProperty, sensitivePropertyValue);
|
|
438
441
|
if (unsafeProperty) {
|
|
439
|
-
(0,
|
|
442
|
+
(0, location_js_1.report)(context, {
|
|
440
443
|
node: callExpression.callee,
|
|
441
444
|
message,
|
|
442
|
-
}, [(0,
|
|
445
|
+
}, [(0, location_js_1.toSecondaryLocation)(unsafeProperty)]);
|
|
443
446
|
}
|
|
444
447
|
}
|
|
445
448
|
function isStringLiteral(node) {
|
|
@@ -509,7 +512,7 @@ function isProperty(node) {
|
|
|
509
512
|
* @param ctx Rule context
|
|
510
513
|
*/
|
|
511
514
|
function isUnresolved(node, ctx) {
|
|
512
|
-
if (!node || (0,
|
|
515
|
+
if (!node || (0, module_js_1.getFullyQualifiedName)(ctx, node) || isUndefined(node)) {
|
|
513
516
|
return false;
|
|
514
517
|
}
|
|
515
518
|
let nodeToCheck = node;
|
package/cjs/helpers/aws/s3.js
CHANGED
|
@@ -5,7 +5,10 @@ exports.isS3BucketConstructor = isS3BucketConstructor;
|
|
|
5
5
|
exports.isS3BucketDeploymentConstructor = isS3BucketDeploymentConstructor;
|
|
6
6
|
exports.getBucketProperty = getBucketProperty;
|
|
7
7
|
exports.findPropagatedSetting = findPropagatedSetting;
|
|
8
|
-
const
|
|
8
|
+
const location_js_1 = require("../location.js");
|
|
9
|
+
const module_js_1 = require("../module.js");
|
|
10
|
+
const ancestor_js_1 = require("../ancestor.js");
|
|
11
|
+
const ast_js_1 = require("../ast.js");
|
|
9
12
|
const cdk_js_1 = require("./cdk.js");
|
|
10
13
|
/**
|
|
11
14
|
* A rule template for AWS S3 Buckets
|
|
@@ -40,7 +43,7 @@ function S3BucketTemplate(callback, meta = {}) {
|
|
|
40
43
|
* new s3.Bucket();
|
|
41
44
|
*/
|
|
42
45
|
function isS3BucketConstructor(context, node) {
|
|
43
|
-
return (0, cdk_js_1.normalizeFQN)((0,
|
|
46
|
+
return (0, cdk_js_1.normalizeFQN)((0, module_js_1.getFullyQualifiedName)(context, node)) === 'aws_cdk_lib.aws_s3.Bucket';
|
|
44
47
|
}
|
|
45
48
|
/**
|
|
46
49
|
* Detects S3 BucketDeployment's constructor invocation from 'aws-cdk-lib/aws-s3-deployment':
|
|
@@ -49,7 +52,7 @@ function isS3BucketConstructor(context, node) {
|
|
|
49
52
|
* new s3.BucketDeployment();
|
|
50
53
|
*/
|
|
51
54
|
function isS3BucketDeploymentConstructor(context, node) {
|
|
52
|
-
return ((0, cdk_js_1.normalizeFQN)((0,
|
|
55
|
+
return ((0, cdk_js_1.normalizeFQN)((0, module_js_1.getFullyQualifiedName)(context, node)) ===
|
|
53
56
|
'aws_cdk_lib.aws_s3_deployment.BucketDeployment');
|
|
54
57
|
}
|
|
55
58
|
/**
|
|
@@ -71,11 +74,11 @@ function isS3BucketDeploymentConstructor(context, node) {
|
|
|
71
74
|
function getBucketProperty(context, bucket, key) {
|
|
72
75
|
const args = bucket.arguments;
|
|
73
76
|
const optionsArg = args[2];
|
|
74
|
-
const options = (0,
|
|
77
|
+
const options = (0, ast_js_1.getValueOfExpression)(context, optionsArg, 'ObjectExpression');
|
|
75
78
|
if (options == null) {
|
|
76
79
|
return null;
|
|
77
80
|
}
|
|
78
|
-
return options.properties.find(property => (0,
|
|
81
|
+
return options.properties.find(property => (0, ast_js_1.isProperty)(property) && (0, ast_js_1.isIdentifier)(property.key, key));
|
|
79
82
|
}
|
|
80
83
|
/**
|
|
81
84
|
* Finds the propagated setting of a sensitive property
|
|
@@ -83,7 +86,7 @@ function getBucketProperty(context, bucket, key) {
|
|
|
83
86
|
function findPropagatedSetting(sensitiveProperty, propagatedValue) {
|
|
84
87
|
const isPropagatedProperty = sensitiveProperty.value !== propagatedValue;
|
|
85
88
|
if (isPropagatedProperty) {
|
|
86
|
-
return (0,
|
|
89
|
+
return (0, location_js_1.toSecondaryLocation)((0, ancestor_js_1.getNodeParent)(propagatedValue), 'Propagated setting.');
|
|
87
90
|
}
|
|
88
91
|
return undefined;
|
|
89
92
|
}
|