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/S3801/rule.js
CHANGED
|
@@ -55,14 +55,18 @@ 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 parser_services_js_1 = require("../helpers/parser-services.js");
|
|
59
|
+
const type_js_1 = require("../helpers/type.js");
|
|
60
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
61
|
+
const location_js_1 = require("../helpers/location.js");
|
|
62
|
+
const ancestor_js_1 = require("../helpers/ancestor.js");
|
|
59
63
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
64
|
exports.rule = {
|
|
61
|
-
meta: (0,
|
|
65
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
62
66
|
create(context) {
|
|
63
67
|
const sourceCode = context.sourceCode;
|
|
64
68
|
const services = sourceCode.parserServices;
|
|
65
|
-
const hasTypeInformation = (0,
|
|
69
|
+
const hasTypeInformation = (0, parser_services_js_1.isRequiredParserServices)(services);
|
|
66
70
|
const functionContextStack = [];
|
|
67
71
|
const checkOnFunctionExit = (node) => checkFunctionLikeDeclaration(node, functionContextStack.at(-1), hasTypeInformation ? services : undefined);
|
|
68
72
|
// tracks the segments we've traversed in the current code path
|
|
@@ -78,9 +82,9 @@ exports.rule = {
|
|
|
78
82
|
checkFunctionForImplicitReturn(functionContext, services);
|
|
79
83
|
if (hasInconsistentReturns(functionContext)) {
|
|
80
84
|
const secondaryLocations = getSecondaryLocations(functionContext, node);
|
|
81
|
-
(0,
|
|
85
|
+
(0, location_js_1.report)(context, {
|
|
82
86
|
message: `Refactor this function to use "return" consistently.`,
|
|
83
|
-
loc: (0,
|
|
87
|
+
loc: (0, location_js_1.getMainFunctionTokenLocation)(node, (0, ancestor_js_1.getParent)(context, node), context),
|
|
84
88
|
}, secondaryLocations);
|
|
85
89
|
}
|
|
86
90
|
}
|
|
@@ -109,11 +113,11 @@ exports.rule = {
|
|
|
109
113
|
function getSecondaryLocations(functionContext, node) {
|
|
110
114
|
const secondaryLocations = functionContext.returnStatements
|
|
111
115
|
.slice()
|
|
112
|
-
.map(returnStatement => (0,
|
|
116
|
+
.map(returnStatement => (0, location_js_1.toSecondaryLocation)(returnStatement, returnStatement.argument ? 'Return with value' : 'Return without value'));
|
|
113
117
|
if (functionContext.containsImplicitReturn) {
|
|
114
118
|
const closeCurlyBraceToken = sourceCode.getLastToken(node, token => token.value === '}');
|
|
115
119
|
if (!!closeCurlyBraceToken) {
|
|
116
|
-
secondaryLocations.push((0,
|
|
120
|
+
secondaryLocations.push((0, location_js_1.toSecondaryLocation)(closeCurlyBraceToken, 'Implicit return without value'));
|
|
117
121
|
}
|
|
118
122
|
}
|
|
119
123
|
return secondaryLocations;
|
|
@@ -171,7 +175,7 @@ exports.rule = {
|
|
|
171
175
|
if (!currentContext) {
|
|
172
176
|
return;
|
|
173
177
|
}
|
|
174
|
-
const switchStmt = (0,
|
|
178
|
+
const switchStmt = (0, ancestor_js_1.getParent)(context, node);
|
|
175
179
|
const lastCase = switchStmt.cases.at(-1);
|
|
176
180
|
// Only track the last case - all fall-throughs eventually reach it
|
|
177
181
|
if (node === lastCase) {
|
|
@@ -223,7 +227,7 @@ function isExhaustiveSwitch(switchStmt, services) {
|
|
|
223
227
|
return true;
|
|
224
228
|
}
|
|
225
229
|
// Without a default, verify all union/enum members are covered
|
|
226
|
-
const discriminantType = (0,
|
|
230
|
+
const discriminantType = (0, type_js_1.getTypeFromTreeNode)(switchStmt.discriminant, services);
|
|
227
231
|
const types = discriminantType.isUnion() ? discriminantType.types : [discriminantType];
|
|
228
232
|
// Must be a union or enum type to be exhaustive without a default
|
|
229
233
|
if (types.length <= 1 && !isEnumType(discriminantType)) {
|
|
@@ -233,7 +237,7 @@ function isExhaustiveSwitch(switchStmt, services) {
|
|
|
233
237
|
const coveredTypes = new Set();
|
|
234
238
|
for (const caseClause of switchStmt.cases) {
|
|
235
239
|
if (caseClause.test) {
|
|
236
|
-
const testType = (0,
|
|
240
|
+
const testType = (0, type_js_1.getTypeFromTreeNode)(caseClause.test, services);
|
|
237
241
|
if (testType.isUnion()) {
|
|
238
242
|
testType.types.forEach(t => coveredTypes.add(t));
|
|
239
243
|
}
|
|
@@ -257,7 +261,7 @@ function isEnumType(type) {
|
|
|
257
261
|
* last statement calls a function that never returns.
|
|
258
262
|
*/
|
|
259
263
|
function isNeverReturningCall(callExpr, services) {
|
|
260
|
-
const signature = (0,
|
|
264
|
+
const signature = (0, type_js_1.getSignatureFromCallee)(callExpr, services);
|
|
261
265
|
if (!signature) {
|
|
262
266
|
return false;
|
|
263
267
|
}
|
package/cjs/S3827/rule.js
CHANGED
|
@@ -34,7 +34,10 @@ 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 ancestor_js_1 = require("../helpers/ancestor.js");
|
|
38
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
39
|
+
const vue_js_1 = require("../helpers/vue.js");
|
|
40
|
+
const location_js_1 = require("../helpers/location.js");
|
|
38
41
|
const meta = __importStar(require("./generated-meta.js"));
|
|
39
42
|
// https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits
|
|
40
43
|
const vueMacroNames = new Set([
|
|
@@ -46,7 +49,7 @@ const vueMacroNames = new Set([
|
|
|
46
49
|
'withDefaults',
|
|
47
50
|
]);
|
|
48
51
|
exports.rule = {
|
|
49
|
-
meta: (0,
|
|
52
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
50
53
|
create(context) {
|
|
51
54
|
const excludedNames = new Set();
|
|
52
55
|
const undeclaredIdentifiersByName = new Map();
|
|
@@ -66,7 +69,7 @@ exports.rule = {
|
|
|
66
69
|
excludedNames.add(identifier.name);
|
|
67
70
|
continue;
|
|
68
71
|
}
|
|
69
|
-
if (vueMacroNames.has(identifier.name) && (0,
|
|
72
|
+
if (vueMacroNames.has(identifier.name) && (0, vue_js_1.isInsideVueSetupScript)(identifier, context)) {
|
|
70
73
|
continue;
|
|
71
74
|
}
|
|
72
75
|
const undeclaredIndentifiers = undeclaredIdentifiersByName.get(identifier.name);
|
|
@@ -78,17 +81,17 @@ exports.rule = {
|
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
for (const [name, identifiers] of undeclaredIdentifiersByName.entries()) {
|
|
81
|
-
(0,
|
|
84
|
+
(0, location_js_1.report)(context, {
|
|
82
85
|
node: identifiers[0],
|
|
83
86
|
message: `"${name}" does not exist. Change its name or declare it so that its usage doesn't result in a "ReferenceError".`,
|
|
84
|
-
}, identifiers.slice(1).map(node => (0,
|
|
87
|
+
}, identifiers.slice(1).map(node => (0, location_js_1.toSecondaryLocation)(node)));
|
|
85
88
|
}
|
|
86
89
|
},
|
|
87
90
|
};
|
|
88
91
|
},
|
|
89
92
|
};
|
|
90
93
|
function isWithinWithStatement(node) {
|
|
91
|
-
return !!(0,
|
|
94
|
+
return !!(0, ancestor_js_1.findFirstMatchingAncestor)(node, ancestor => ancestor.type === 'WithStatement');
|
|
92
95
|
}
|
|
93
96
|
function hasTypeOfOperator(node) {
|
|
94
97
|
const parent = node.parent;
|
package/cjs/S3923/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 equivalence_js_1 = require("../helpers/equivalence.js");
|
|
55
|
+
const conditions_js_1 = require("../helpers/conditions.js");
|
|
56
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
57
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
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
|
removeOrEditConditionalStructure: "Remove this conditional structure or edit its code blocks so that they're not all the same.",
|
|
60
63
|
returnsTheSameValue: 'This conditional operation returns the same value whether the condition is "true" or "false".',
|
|
@@ -64,15 +67,15 @@ exports.rule = {
|
|
|
64
67
|
return {
|
|
65
68
|
IfStatement(ifStmt) {
|
|
66
69
|
// don't visit `else if` statements
|
|
67
|
-
if (!(0,
|
|
68
|
-
const { branches, endsWithElse } = (0,
|
|
70
|
+
if (!(0, ast_js_1.isIfStatement)(ifStmt.parent)) {
|
|
71
|
+
const { branches, endsWithElse } = (0, conditions_js_1.collectIfBranches)(ifStmt);
|
|
69
72
|
if (endsWithElse && allDuplicated(branches)) {
|
|
70
73
|
context.report({ messageId: 'removeOrEditConditionalStructure', node: ifStmt });
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
},
|
|
74
77
|
SwitchStatement(switchStmt) {
|
|
75
|
-
const { branches, endsWithDefault } = (0,
|
|
78
|
+
const { branches, endsWithDefault } = (0, conditions_js_1.collectSwitchBranches)(switchStmt);
|
|
76
79
|
if (endsWithDefault && allDuplicated(branches)) {
|
|
77
80
|
context.report({ messageId: 'removeOrEditConditionalStructure', node: switchStmt });
|
|
78
81
|
}
|
|
@@ -87,7 +90,7 @@ exports.rule = {
|
|
|
87
90
|
function allDuplicated(branches) {
|
|
88
91
|
return (branches.length > 1 &&
|
|
89
92
|
branches.slice(1).every((branch, index) => {
|
|
90
|
-
return (0,
|
|
93
|
+
return (0, equivalence_js_1.areEquivalent)(branch, branches[index], context.sourceCode);
|
|
91
94
|
}));
|
|
92
95
|
}
|
|
93
96
|
},
|
package/cjs/S3972/rule.js
CHANGED
|
@@ -51,11 +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 location_js_1 = require("../helpers/location.js");
|
|
55
56
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
57
|
const message = 'Move this "if" to a new line or add the missing "else".';
|
|
57
58
|
exports.rule = {
|
|
58
|
-
meta: (0,
|
|
59
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
59
60
|
hasSuggestions: true,
|
|
60
61
|
messages: {
|
|
61
62
|
sameLineCondition: message,
|
|
@@ -76,7 +77,7 @@ exports.rule = {
|
|
|
76
77
|
precedingIf.loc.start.line !== followingIf.loc.end.line) {
|
|
77
78
|
const precedingIfLastToken = sourceCode.getLastToken(precedingIf);
|
|
78
79
|
const followingIfToken = sourceCode.getFirstToken(followingIf);
|
|
79
|
-
(0,
|
|
80
|
+
(0, location_js_1.report)(context, {
|
|
80
81
|
messageId: 'sameLineCondition',
|
|
81
82
|
message,
|
|
82
83
|
loc: followingIfToken.loc,
|
|
@@ -90,7 +91,7 @@ exports.rule = {
|
|
|
90
91
|
fix: fixer => fixer.replaceTextRange([precedingIf.range[1], followingIf.range[0]], '\n' + ' '.repeat(precedingIf.loc.start.column)),
|
|
91
92
|
},
|
|
92
93
|
],
|
|
93
|
-
}, [(0,
|
|
94
|
+
}, [(0, location_js_1.toSecondaryLocation)(precedingIfLastToken)]);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
}
|
package/cjs/S3973/rule.js
CHANGED
|
@@ -51,16 +51,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
|
+
const ancestor_js_1 = require("../helpers/ancestor.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
|
const sourceCode = context.sourceCode;
|
|
60
62
|
return {
|
|
61
63
|
IfStatement: (node) => {
|
|
62
64
|
const ifStatement = node;
|
|
63
|
-
const parent = (0,
|
|
65
|
+
const parent = (0, ancestor_js_1.getParent)(context, node);
|
|
64
66
|
if (parent && parent.type !== 'IfStatement') {
|
|
65
67
|
const firstToken = sourceCode.getFirstToken(node);
|
|
66
68
|
checkIndentation(firstToken, ifStatement.consequent, context);
|
|
@@ -91,10 +93,10 @@ function checkIndentation(firstToken, statement, context, tokenToReport = firstT
|
|
|
91
93
|
firstToken.loc.start.column >= firstStatementToken.loc.start.column) {
|
|
92
94
|
const message = `Use curly braces or indentation to denote the code conditionally ` +
|
|
93
95
|
`executed by this "${tokenToReport.value}".`;
|
|
94
|
-
(0,
|
|
96
|
+
(0, location_js_1.report)(context, {
|
|
95
97
|
message,
|
|
96
98
|
loc: tokenToReport.loc,
|
|
97
|
-
}, [(0,
|
|
99
|
+
}, [(0, location_js_1.toSecondaryLocation)(firstStatementToken)]);
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
}
|
package/cjs/S3981/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 parser_services_js_1 = require("../helpers/parser-services.js");
|
|
55
56
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
57
|
const CollectionLike = new Set(['Array', 'Map', 'Set', 'WeakMap', 'WeakSet']);
|
|
57
58
|
const CollectionSizeLike = new Set(['length', 'size']);
|
|
58
59
|
exports.rule = {
|
|
59
|
-
meta: (0,
|
|
60
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
60
61
|
messages: {
|
|
61
62
|
fixCollectionSizeCheck: 'Fix this expression; {{propertyName}} of "{{objectName}}" is always greater or equal to zero.',
|
|
62
63
|
suggestFixedSizeCheck: 'Use "{{operator}}" for {{operation}} check',
|
|
@@ -65,7 +66,7 @@ exports.rule = {
|
|
|
65
66
|
}),
|
|
66
67
|
create(context) {
|
|
67
68
|
const services = context.sourceCode.parserServices;
|
|
68
|
-
const isTypeCheckerAvailable = (0,
|
|
69
|
+
const isTypeCheckerAvailable = (0, parser_services_js_1.isRequiredParserServices)(services);
|
|
69
70
|
return {
|
|
70
71
|
BinaryExpression: (node) => {
|
|
71
72
|
if (['<', '>='].includes(node.operator)) {
|
package/cjs/S3984/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 ancestor_js_1 = require("../helpers/ancestor.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
|
hasSuggestions: true,
|
|
59
60
|
messages: {
|
|
60
61
|
throwOrRemoveError: 'Throw this error or remove this useless statement.',
|
|
@@ -76,7 +77,7 @@ exports.rule = {
|
|
|
76
77
|
suggest: [
|
|
77
78
|
{
|
|
78
79
|
messageId: 'suggestThrowError',
|
|
79
|
-
fix: fixer => fixer.insertTextBefore((0,
|
|
80
|
+
fix: fixer => fixer.insertTextBefore((0, ancestor_js_1.getParent)(context, node), 'throw '),
|
|
80
81
|
},
|
|
81
82
|
],
|
|
82
83
|
});
|
package/cjs/S4030/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 collection_js_1 = require("../helpers/collection.js");
|
|
55
|
+
const ancestor_js_1 = require("../helpers/ancestor.js");
|
|
56
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
57
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
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
|
unusedCollection: "Either use this collection's contents or remove the collection.",
|
|
60
63
|
},
|
|
@@ -114,7 +117,7 @@ function isUnusedCollection(variable) {
|
|
|
114
117
|
return assignCollection;
|
|
115
118
|
}
|
|
116
119
|
function isReferenceAssigningCollection(ref) {
|
|
117
|
-
const declOrExprStmt = (0,
|
|
120
|
+
const declOrExprStmt = (0, ancestor_js_1.findFirstMatchingAncestor)(ref.identifier, n => n.type === 'VariableDeclarator' || n.type === 'ExpressionStatement');
|
|
118
121
|
if (declOrExprStmt) {
|
|
119
122
|
if (declOrExprStmt.type === 'VariableDeclarator' && declOrExprStmt.init) {
|
|
120
123
|
return isCollectionType(declOrExprStmt.init);
|
|
@@ -133,14 +136,14 @@ function isCollectionType(node) {
|
|
|
133
136
|
return true;
|
|
134
137
|
}
|
|
135
138
|
else if (node?.type === 'CallExpression' || node?.type === 'NewExpression') {
|
|
136
|
-
return (0,
|
|
139
|
+
return (0, ast_js_1.isIdentifier)(node.callee, ...collection_js_1.collectionConstructor);
|
|
137
140
|
}
|
|
138
141
|
return false;
|
|
139
142
|
}
|
|
140
143
|
function isRead(ref) {
|
|
141
|
-
const expressionStatement = (0,
|
|
144
|
+
const expressionStatement = (0, ancestor_js_1.findFirstMatchingAncestor)(ref.identifier, n => n.type === 'ExpressionStatement');
|
|
142
145
|
if (expressionStatement) {
|
|
143
|
-
return !((0,
|
|
146
|
+
return !((0, ast_js_1.isElementWrite)(expressionStatement, ref, false) ||
|
|
144
147
|
isWritingMethodCall(expressionStatement, ref));
|
|
145
148
|
}
|
|
146
149
|
//All the write statement that we search are part of ExpressionStatement, if there is none, it's a read
|
|
@@ -155,7 +158,7 @@ function isWritingMethodCall(statement, ref) {
|
|
|
155
158
|
const { callee } = statement.expression;
|
|
156
159
|
if (callee.type === 'MemberExpression') {
|
|
157
160
|
const { property } = callee;
|
|
158
|
-
return isReferenceTo(ref, callee.object) && (0,
|
|
161
|
+
return isReferenceTo(ref, callee.object) && (0, ast_js_1.isIdentifier)(property, ...collection_js_1.writingMethods);
|
|
159
162
|
}
|
|
160
163
|
}
|
|
161
164
|
return false;
|
package/cjs/S4036/rule.js
CHANGED
|
@@ -51,12 +51,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
|
+
const module_js_1 = require("../helpers/module.js");
|
|
56
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
55
57
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
58
|
const SENSITIVE_METHODS = ['exec', 'execSync', 'spawn', 'spawnSync', 'execFile', 'execFileSync'];
|
|
57
59
|
const REQUIRED_PATH_PREFIXES = ['./', '.\\', '../', '..\\', '/', '\\', 'C:\\'];
|
|
58
60
|
exports.rule = {
|
|
59
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
60
62
|
messages: {
|
|
61
63
|
issue: 'Make sure the "PATH" variable only contains fixed, unwriteable directories.',
|
|
62
64
|
},
|
|
@@ -64,7 +66,7 @@ exports.rule = {
|
|
|
64
66
|
create(context) {
|
|
65
67
|
return {
|
|
66
68
|
CallExpression: (node) => {
|
|
67
|
-
const fqn = (0,
|
|
69
|
+
const fqn = (0, module_js_1.getFullyQualifiedName)(context, node);
|
|
68
70
|
if (SENSITIVE_METHODS.some(method => fqn === `child_process.${method}`)) {
|
|
69
71
|
const sensitiveArg = findSensitiveArgument(context, node.arguments);
|
|
70
72
|
if (sensitiveArg !== null) {
|
|
@@ -83,9 +85,9 @@ function findSensitiveArgument(context, functionArgs) {
|
|
|
83
85
|
return null;
|
|
84
86
|
}
|
|
85
87
|
const pathArg = functionArgs[0]; // we know this for the SENSITIVE_METHODS
|
|
86
|
-
const literalInExpression = (0,
|
|
88
|
+
const literalInExpression = (0, ast_js_1.getValueOfExpression)(context, pathArg, 'Literal');
|
|
87
89
|
let stringLiteral;
|
|
88
|
-
if (literalInExpression !== undefined && (0,
|
|
90
|
+
if (literalInExpression !== undefined && (0, ast_js_1.isStringLiteral)(literalInExpression)) {
|
|
89
91
|
stringLiteral = literalInExpression;
|
|
90
92
|
}
|
|
91
93
|
else {
|
package/cjs/S4043/rule.js
CHANGED
|
@@ -55,11 +55,15 @@ 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 parser_services_js_1 = require("../helpers/parser-services.js");
|
|
59
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
60
|
+
const type_js_1 = require("../helpers/type.js");
|
|
61
|
+
const ancestor_js_1 = require("../helpers/ancestor.js");
|
|
62
|
+
const collection_js_1 = require("../helpers/collection.js");
|
|
59
63
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
|
-
const arrayMutatingMethods = new Set(['reverse', "'reverse'", '"reverse"', ...
|
|
64
|
+
const arrayMutatingMethods = new Set(['reverse', "'reverse'", '"reverse"', ...collection_js_1.sortLike]);
|
|
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
|
moveMethod: 'Move this array "{{method}}" operation to a separate statement or replace it with "{{suggestedMethod}}".',
|
|
@@ -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
|
return {
|
|
@@ -119,14 +123,14 @@ function formatMethod(mutatingMethod) {
|
|
|
119
123
|
}
|
|
120
124
|
}
|
|
121
125
|
function isArrayMutatingCall(memberExpression, services, propertyText) {
|
|
122
|
-
return arrayMutatingMethods.has(propertyText) && (0,
|
|
126
|
+
return arrayMutatingMethods.has(propertyText) && (0, type_js_1.isArray)(memberExpression.object, services);
|
|
123
127
|
}
|
|
124
128
|
function isIdentifierOrPropertyAccessExpression(node, services) {
|
|
125
129
|
return (node.type === 'Identifier' ||
|
|
126
130
|
(node.type === 'MemberExpression' && !isGetAccessor(node.property, services)));
|
|
127
131
|
}
|
|
128
132
|
function isGetAccessor(node, services) {
|
|
129
|
-
const symbol = (0,
|
|
133
|
+
const symbol = (0, type_js_1.getSymbolAtLocation)(node, services);
|
|
130
134
|
const declarations = symbol?.declarations;
|
|
131
135
|
return declarations?.length === 1 && declarations[0].kind === typescript_1.default.SyntaxKind.GetAccessor;
|
|
132
136
|
}
|
|
@@ -144,7 +148,7 @@ function isForbiddenOperation(node) {
|
|
|
144
148
|
return !isStandaloneExpression(node) && !isReturnedExpression(node);
|
|
145
149
|
}
|
|
146
150
|
function isStandaloneExpression(node) {
|
|
147
|
-
const ancestors = (0,
|
|
151
|
+
const ancestors = (0, ancestor_js_1.localAncestorsChain)(node);
|
|
148
152
|
const returnIdx = ancestors.findIndex(ancestor => ancestor.type === 'ExpressionStatement');
|
|
149
153
|
return (returnIdx > -1 &&
|
|
150
154
|
ancestors
|
|
@@ -152,7 +156,7 @@ function isStandaloneExpression(node) {
|
|
|
152
156
|
.every(ancestor => ['ChainExpression', 'LogicalExpression'].includes(ancestor.type)));
|
|
153
157
|
}
|
|
154
158
|
function isReturnedExpression(node) {
|
|
155
|
-
const ancestors = (0,
|
|
159
|
+
const ancestors = (0, ancestor_js_1.localAncestorsChain)(node);
|
|
156
160
|
const returnIdx = ancestors.findIndex(ancestor => ancestor.type === 'ReturnStatement');
|
|
157
161
|
return (returnIdx > -1 &&
|
|
158
162
|
ancestors
|
package/cjs/S4139/rule.js
CHANGED
|
@@ -51,22 +51,24 @@ 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
|
messages: {
|
|
59
61
|
useForOf: 'Use "for...of" to iterate over this "{{iterable}}".',
|
|
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 {
|
|
68
70
|
ForInStatement: (node) => {
|
|
69
|
-
const type = (0,
|
|
71
|
+
const type = (0, type_js_1.getTypeFromTreeNode)(node.right, services);
|
|
70
72
|
if (isIterable(type)) {
|
|
71
73
|
const iterable = type.symbol ? type.symbol.name : 'String';
|
|
72
74
|
context.report({
|
|
@@ -78,7 +80,7 @@ exports.rule = {
|
|
|
78
80
|
},
|
|
79
81
|
};
|
|
80
82
|
function isIterable(type) {
|
|
81
|
-
return isCollection(type) || (0,
|
|
83
|
+
return isCollection(type) || (0, type_js_1.isStringType)(type) || (0, type_js_1.isArrayLikeType)(type, services);
|
|
82
84
|
}
|
|
83
85
|
},
|
|
84
86
|
};
|
package/cjs/S4143/rule.js
CHANGED
|
@@ -51,11 +51,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const 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");
|
|
57
|
+
const location_js_1 = require("../helpers/location.js");
|
|
55
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
59
|
const message = 'Verify this is the index that was intended; "{{index}}" was already set on line {{line}}.';
|
|
57
60
|
exports.rule = {
|
|
58
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
59
62
|
messages: {
|
|
60
63
|
verifyIntendedIndex: message,
|
|
61
64
|
},
|
|
@@ -69,7 +72,7 @@ exports.rule = {
|
|
|
69
72
|
checkStatements(node.body);
|
|
70
73
|
},
|
|
71
74
|
Program(node) {
|
|
72
|
-
checkStatements((0,
|
|
75
|
+
checkStatements((0, ast_js_1.getProgramStatements)(node));
|
|
73
76
|
},
|
|
74
77
|
};
|
|
75
78
|
function checkStatements(statements) {
|
|
@@ -79,15 +82,15 @@ exports.rule = {
|
|
|
79
82
|
const keyWriteUsage = getKeyWriteUsage(statement);
|
|
80
83
|
if (keyWriteUsage) {
|
|
81
84
|
if (collection &&
|
|
82
|
-
!(0,
|
|
85
|
+
!(0, equivalence_js_1.areEquivalent)(keyWriteUsage.collectionNode, collection, context.sourceCode)) {
|
|
83
86
|
usedKeys.clear();
|
|
84
87
|
}
|
|
85
88
|
const sameKeyWriteUsage = usedKeys.get(keyWriteUsage.indexOrKey);
|
|
86
89
|
if (sameKeyWriteUsage?.node.loc) {
|
|
87
90
|
const secondaryLocations = [
|
|
88
|
-
(0,
|
|
91
|
+
(0, location_js_1.toSecondaryLocation)(sameKeyWriteUsage.node, 'Original value'),
|
|
89
92
|
];
|
|
90
|
-
(0,
|
|
93
|
+
(0, location_js_1.report)(context, {
|
|
91
94
|
node: keyWriteUsage.node,
|
|
92
95
|
messageId: 'verifyIntendedIndex',
|
|
93
96
|
message,
|
|
@@ -153,11 +156,11 @@ function isSimpleAssignment(node) {
|
|
|
153
156
|
return node.type === 'AssignmentExpression' && node.operator === '=';
|
|
154
157
|
}
|
|
155
158
|
function extractIndex(node) {
|
|
156
|
-
if ((0,
|
|
159
|
+
if ((0, ast_js_1.isLiteral)(node)) {
|
|
157
160
|
const { value } = node;
|
|
158
161
|
return typeof value === 'number' || typeof value === 'string' ? String(value) : undefined;
|
|
159
162
|
}
|
|
160
|
-
else if ((0,
|
|
163
|
+
else if ((0, ast_js_1.isIdentifier)(node)) {
|
|
161
164
|
return node.name;
|
|
162
165
|
}
|
|
163
166
|
return undefined;
|
|
@@ -165,7 +168,7 @@ function extractIndex(node) {
|
|
|
165
168
|
function mapOrSetKeyWriteUsage(node) {
|
|
166
169
|
if (node.type === 'CallExpression' && node.callee.type === 'MemberExpression') {
|
|
167
170
|
const propertyAccess = node.callee;
|
|
168
|
-
if ((0,
|
|
171
|
+
if ((0, ast_js_1.isIdentifier)(propertyAccess.property)) {
|
|
169
172
|
const methodName = propertyAccess.property.name;
|
|
170
173
|
const addMethod = methodName === 'add' && node.arguments.length === 1;
|
|
171
174
|
const setMethod = methodName === 'set' && node.arguments.length === 2;
|
package/cjs/S4144/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 equivalence_js_1 = require("../helpers/equivalence.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
56
|
+
const location_js_1 = require("../helpers/location.js");
|
|
57
|
+
const collection_js_1 = require("../helpers/collection.js");
|
|
55
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
59
|
const DEFAULT_MIN_LINES = 3;
|
|
57
60
|
const message = 'Update this function so that its implementation is not identical to the one on line {{line}}.';
|
|
58
61
|
exports.rule = {
|
|
59
|
-
meta: (0,
|
|
62
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
60
63
|
messages: {
|
|
61
64
|
identicalFunctions: message,
|
|
62
65
|
},
|
|
@@ -88,14 +91,14 @@ exports.rule = {
|
|
|
88
91
|
const duplicatingFunction = functions[i].function;
|
|
89
92
|
for (let j = 0; j < i; j++) {
|
|
90
93
|
const originalFunction = functions[j].function;
|
|
91
|
-
if ((0,
|
|
94
|
+
if ((0, equivalence_js_1.areEquivalent)(duplicatingFunction.body, originalFunction.body, context.sourceCode) &&
|
|
92
95
|
originalFunction.loc) {
|
|
93
|
-
const loc = (0,
|
|
94
|
-
const originalFunctionLoc = (0,
|
|
96
|
+
const loc = (0, location_js_1.getMainFunctionTokenLocation)(duplicatingFunction, functions[i].parent, context);
|
|
97
|
+
const originalFunctionLoc = (0, location_js_1.getMainFunctionTokenLocation)(originalFunction, functions[j].parent, context);
|
|
95
98
|
const secondaryLocations = [
|
|
96
|
-
(0,
|
|
99
|
+
(0, location_js_1.toSecondaryLocation)({ loc: originalFunctionLoc }, 'Original implementation'),
|
|
97
100
|
];
|
|
98
|
-
(0,
|
|
101
|
+
(0, location_js_1.report)(context, {
|
|
99
102
|
message,
|
|
100
103
|
data: {
|
|
101
104
|
line: originalFunction.loc.start.line,
|
|
@@ -112,12 +115,12 @@ exports.rule = {
|
|
|
112
115
|
if (tokens.length > 0 && tokens[0].value === '{') {
|
|
113
116
|
tokens.shift();
|
|
114
117
|
}
|
|
115
|
-
if (tokens.length > 0 && (0,
|
|
118
|
+
if (tokens.length > 0 && (0, collection_js_1.last)(tokens).value === '}') {
|
|
116
119
|
tokens.pop();
|
|
117
120
|
}
|
|
118
121
|
if (tokens.length > 0) {
|
|
119
122
|
const firstLine = tokens[0].loc.start.line;
|
|
120
|
-
const lastLine = (0,
|
|
123
|
+
const lastLine = (0, collection_js_1.last)(tokens).loc.end.line;
|
|
121
124
|
return lastLine - firstLine + 1 >= minLines;
|
|
122
125
|
}
|
|
123
126
|
return false;
|