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/S5860/rule.js
CHANGED
|
@@ -52,17 +52,21 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
54
|
const regexpp = __importStar(require("@eslint-community/regexpp"));
|
|
55
|
-
const
|
|
55
|
+
const location_js_1 = require("../helpers/location.js");
|
|
56
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
57
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
58
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
59
|
+
const type_js_1 = require("../helpers/type.js");
|
|
56
60
|
const meta = __importStar(require("./generated-meta.js"));
|
|
57
|
-
const
|
|
61
|
+
const ast_js_2 = require("../helpers/regex/ast.js");
|
|
58
62
|
const group_js_1 = require("../helpers/regex/group.js");
|
|
59
|
-
const
|
|
63
|
+
const location_js_2 = require("../helpers/regex/location.js");
|
|
60
64
|
const extract_js_1 = require("../helpers/regex/extract.js");
|
|
61
65
|
exports.rule = {
|
|
62
|
-
meta: (0,
|
|
66
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
63
67
|
create(context) {
|
|
64
68
|
const services = context.sourceCode.parserServices;
|
|
65
|
-
if (!(0,
|
|
69
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
66
70
|
return {};
|
|
67
71
|
}
|
|
68
72
|
const intellisense = new RegexIntelliSense(services, context);
|
|
@@ -101,7 +105,7 @@ exports.rule = {
|
|
|
101
105
|
},
|
|
102
106
|
};
|
|
103
107
|
function checkStringReplaceGroupReferences(callExpr, intellisense) {
|
|
104
|
-
if ((0,
|
|
108
|
+
if ((0, ast_js_2.isStringReplaceCall)(callExpr, intellisense.services)) {
|
|
105
109
|
const [pattern, substr] = callExpr.arguments;
|
|
106
110
|
const regex = intellisense.findRegex(pattern);
|
|
107
111
|
if (regex) {
|
|
@@ -118,7 +122,7 @@ function checkStringReplaceGroupReferences(callExpr, intellisense) {
|
|
|
118
122
|
const indexedGroups = regex.groups.filter(group => indexes.has(group.index));
|
|
119
123
|
if (indexedGroups.length > 0) {
|
|
120
124
|
const locations = prepareSecondaries(regex, indexedGroups, intellisense, 'Group');
|
|
121
|
-
(0,
|
|
125
|
+
(0, location_js_1.report)(intellisense.context, {
|
|
122
126
|
message: `Directly use the group names instead of their numbers.`,
|
|
123
127
|
node: substr,
|
|
124
128
|
}, locations);
|
|
@@ -130,14 +134,14 @@ function checkIndexBasedGroupReference(memberExpr, intellisense) {
|
|
|
130
134
|
const { object: matcher, property } = memberExpr;
|
|
131
135
|
const regex = intellisense.resolve(matcher);
|
|
132
136
|
if (regex) {
|
|
133
|
-
const maybeIndex = (0,
|
|
137
|
+
const maybeIndex = (0, ast_js_1.getValueOfExpression)(intellisense.context, property, 'Literal');
|
|
134
138
|
if (maybeIndex && typeof maybeIndex.value === 'number') {
|
|
135
139
|
const index = maybeIndex.value;
|
|
136
140
|
const group = regex.groups.find(grp => grp.index === index);
|
|
137
141
|
if (group) {
|
|
138
142
|
group.used = true;
|
|
139
143
|
const locations = prepareSecondaries(regex, [group], intellisense, 'Group');
|
|
140
|
-
(0,
|
|
144
|
+
(0, location_js_1.report)(intellisense.context, {
|
|
141
145
|
message: `Directly use '${group.name}' instead of its group number.`,
|
|
142
146
|
node: property,
|
|
143
147
|
}, locations);
|
|
@@ -159,7 +163,7 @@ function checkNonExistingGroupReference(memberExpr, intellisense) {
|
|
|
159
163
|
}
|
|
160
164
|
else {
|
|
161
165
|
const locations = prepareSecondaries(regex, regex.groups, intellisense, 'Named group');
|
|
162
|
-
(0,
|
|
166
|
+
(0, location_js_1.report)(intellisense.context, {
|
|
163
167
|
message: `There is no group named '${groupName}' in the regular expression.`,
|
|
164
168
|
node: groupNode,
|
|
165
169
|
}, locations);
|
|
@@ -168,7 +172,7 @@ function checkNonExistingGroupReference(memberExpr, intellisense) {
|
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
function extractGroupNodes(memberExpr, intellisense) {
|
|
171
|
-
if ((0,
|
|
175
|
+
if ((0, ast_js_1.isDotNotation)(memberExpr)) {
|
|
172
176
|
const { property } = memberExpr;
|
|
173
177
|
const ancestors = intellisense.context.sourceCode.getAncestors(memberExpr);
|
|
174
178
|
let parent = ancestors.pop();
|
|
@@ -182,7 +186,7 @@ function extractGroupNodes(memberExpr, intellisense) {
|
|
|
182
186
|
return extractNamedOrDestructuredGroupNodes(parent);
|
|
183
187
|
case 'indices':
|
|
184
188
|
/* matcher.indices.groups.<name> or matcher.indices.groups['name'] */
|
|
185
|
-
if ((0,
|
|
189
|
+
if ((0, ast_js_1.isDotNotation)(parent) && parent.property.name === 'groups') {
|
|
186
190
|
parent = ancestors.pop();
|
|
187
191
|
if (parent) {
|
|
188
192
|
return extractNamedOrDestructuredGroupNodes(parent);
|
|
@@ -194,11 +198,11 @@ function extractGroupNodes(memberExpr, intellisense) {
|
|
|
194
198
|
return [];
|
|
195
199
|
}
|
|
196
200
|
function extractNamedOrDestructuredGroupNodes(node) {
|
|
197
|
-
if ((0,
|
|
201
|
+
if ((0, ast_js_1.isDotNotation)(node) || (0, ast_js_1.isIndexNotation)(node)) {
|
|
198
202
|
/* matcher.groups.<name> or matcher.groups['name'] */
|
|
199
203
|
return [node.property];
|
|
200
204
|
}
|
|
201
|
-
else if ((0,
|
|
205
|
+
else if ((0, ast_js_1.isObjectDestructuring)(node)) {
|
|
202
206
|
/* { <name1>,..<nameN> } = matcher.groups */
|
|
203
207
|
const destructuredGroups = [];
|
|
204
208
|
const pattern = node.type === 'VariableDeclarator' ? node.id : node.left;
|
|
@@ -219,7 +223,7 @@ function checkUnusedGroups(intellisense) {
|
|
|
219
223
|
const unusedGroups = regex.groups.filter(group => !group.used);
|
|
220
224
|
if (unusedGroups.length) {
|
|
221
225
|
const locations = prepareSecondaries(regex, unusedGroups, intellisense, 'Named group');
|
|
222
|
-
(0,
|
|
226
|
+
(0, location_js_1.report)(intellisense.context, {
|
|
223
227
|
message: 'Use the named groups of this regex or remove the names.',
|
|
224
228
|
node: regex.node,
|
|
225
229
|
}, locations);
|
|
@@ -230,9 +234,9 @@ function checkUnusedGroups(intellisense) {
|
|
|
230
234
|
function prepareSecondaries(regex, groups, intellisense, label) {
|
|
231
235
|
const locations = [];
|
|
232
236
|
for (const grp of groups) {
|
|
233
|
-
const loc = (0,
|
|
237
|
+
const loc = (0, location_js_2.getRegexpLocation)(regex.node, grp.node, intellisense.context);
|
|
234
238
|
if (loc) {
|
|
235
|
-
locations.push((0,
|
|
239
|
+
locations.push((0, location_js_1.toSecondaryLocation)({ loc }, `${label} '${grp.name}'`));
|
|
236
240
|
}
|
|
237
241
|
}
|
|
238
242
|
return locations;
|
|
@@ -242,9 +246,9 @@ function checkIndexedGroups(intellisense) {
|
|
|
242
246
|
for (const group of regex.groups) {
|
|
243
247
|
const locations = prepareSecondaries(regex, [group], intellisense, 'Group');
|
|
244
248
|
for (const reference of group.node.references) {
|
|
245
|
-
const loc = (0,
|
|
249
|
+
const loc = (0, location_js_2.getRegexpLocation)(regex.node, reference, intellisense.context);
|
|
246
250
|
if (loc && typeof reference.ref === 'number') {
|
|
247
|
-
(0,
|
|
251
|
+
(0, location_js_1.report)(intellisense.context, {
|
|
248
252
|
message: `Directly use '${group.name}' instead of its group number.`,
|
|
249
253
|
loc,
|
|
250
254
|
}, locations);
|
|
@@ -295,7 +299,7 @@ class RegexIntelliSense {
|
|
|
295
299
|
}
|
|
296
300
|
collectKnowledge(node) {
|
|
297
301
|
let regexNode = node;
|
|
298
|
-
if (node.type === 'CallExpression' && (0,
|
|
302
|
+
if (node.type === 'CallExpression' && (0, ast_js_2.isStringRegexMethodCall)(node, this.services)) {
|
|
299
303
|
/* implicit regex */
|
|
300
304
|
regexNode = node.arguments[0];
|
|
301
305
|
}
|
|
@@ -306,17 +310,17 @@ class RegexIntelliSense {
|
|
|
306
310
|
}
|
|
307
311
|
collectPatternMatcher(callExpr) {
|
|
308
312
|
const { callee, arguments: args } = callExpr;
|
|
309
|
-
if ((0,
|
|
313
|
+
if ((0, ast_js_1.isMethodCall)(callExpr) && args.length > 0) {
|
|
310
314
|
const target = callee.object;
|
|
311
|
-
const matcher = (0,
|
|
315
|
+
const matcher = (0, ast_js_1.getLhsVariable)(this.context, callExpr);
|
|
312
316
|
if (matcher) {
|
|
313
317
|
const method = callee.property;
|
|
314
|
-
if ((0,
|
|
318
|
+
if ((0, type_js_1.isString)(target, this.services) && ['match', 'matchAll'].includes(method.name)) {
|
|
315
319
|
/* str.match(pattern) */
|
|
316
320
|
const [pattern] = args;
|
|
317
321
|
this.bind(pattern, matcher);
|
|
318
322
|
}
|
|
319
|
-
else if (method.name === 'exec' && (0,
|
|
323
|
+
else if (method.name === 'exec' && (0, type_js_1.isString)(args[0], this.services)) {
|
|
320
324
|
/* pattern.exec(str) */
|
|
321
325
|
const pattern = target;
|
|
322
326
|
this.bind(pattern, matcher);
|
|
@@ -341,7 +345,7 @@ class RegexIntelliSense {
|
|
|
341
345
|
visited.add(node);
|
|
342
346
|
const variable = this.findVariable(node);
|
|
343
347
|
if (variable) {
|
|
344
|
-
const value = (0,
|
|
348
|
+
const value = (0, ast_js_1.getUniqueWriteUsage)(this.context, variable.name, node);
|
|
345
349
|
if (value) {
|
|
346
350
|
const regex = this.findRegexRec(value, visited);
|
|
347
351
|
if (regex) {
|
|
@@ -361,7 +365,7 @@ class RegexIntelliSense {
|
|
|
361
365
|
}
|
|
362
366
|
findVariable(node) {
|
|
363
367
|
if (node.type === 'Identifier') {
|
|
364
|
-
return (0,
|
|
368
|
+
return (0, ast_js_1.getVariableFromName)(this.context, node.name, node);
|
|
365
369
|
}
|
|
366
370
|
return null;
|
|
367
371
|
}
|
package/cjs/S5863/rule.js
CHANGED
|
@@ -51,12 +51,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const equivalence_js_1 = require("../helpers/equivalence.js");
|
|
55
|
+
const chai_js_1 = require("../helpers/chai.js");
|
|
56
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
57
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
58
|
+
const location_js_1 = require("../helpers/location.js");
|
|
55
59
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
60
|
exports.rule = {
|
|
57
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
58
62
|
create(context) {
|
|
59
|
-
if (!
|
|
63
|
+
if (!(0, chai_js_1.isImported)(context)) {
|
|
60
64
|
return {};
|
|
61
65
|
}
|
|
62
66
|
return {
|
|
@@ -72,7 +76,7 @@ exports.rule = {
|
|
|
72
76
|
function checkAssert(context, expression) {
|
|
73
77
|
if (expression.type === 'CallExpression') {
|
|
74
78
|
const { callee, arguments: args } = expression;
|
|
75
|
-
if (callee.type === 'MemberExpression' && (0,
|
|
79
|
+
if (callee.type === 'MemberExpression' && (0, ast_js_1.isIdentifier)(callee.object, 'assert')) {
|
|
76
80
|
findDuplicates(context, args);
|
|
77
81
|
}
|
|
78
82
|
}
|
|
@@ -88,7 +92,7 @@ function checkExpect(context, expression) {
|
|
|
88
92
|
else if (currentExpression.type === 'MemberExpression') {
|
|
89
93
|
currentExpression = currentExpression.object;
|
|
90
94
|
}
|
|
91
|
-
else if ((0,
|
|
95
|
+
else if ((0, ast_js_1.isIdentifier)(currentExpression, 'expect')) {
|
|
92
96
|
break;
|
|
93
97
|
}
|
|
94
98
|
else {
|
|
@@ -107,12 +111,12 @@ function checkShould(context, expression) {
|
|
|
107
111
|
currentExpression = currentExpression.callee;
|
|
108
112
|
}
|
|
109
113
|
else if (currentExpression.type === 'MemberExpression') {
|
|
110
|
-
if ((0,
|
|
114
|
+
if ((0, ast_js_1.isIdentifier)(currentExpression.property, 'should')) {
|
|
111
115
|
hasShould = true;
|
|
112
116
|
}
|
|
113
117
|
currentExpression = currentExpression.object;
|
|
114
118
|
}
|
|
115
|
-
else if ((0,
|
|
119
|
+
else if ((0, ast_js_1.isIdentifier)(currentExpression, 'should')) {
|
|
116
120
|
break;
|
|
117
121
|
}
|
|
118
122
|
else if (hasShould) {
|
|
@@ -128,10 +132,10 @@ function checkShould(context, expression) {
|
|
|
128
132
|
function findDuplicates(context, args) {
|
|
129
133
|
for (let i = 0; i < args.length; i++) {
|
|
130
134
|
for (let j = i + 1; j < args.length; j++) {
|
|
131
|
-
const duplicates = (0,
|
|
132
|
-
if (duplicates && !(0,
|
|
133
|
-
(0,
|
|
134
|
-
(0,
|
|
135
|
+
const duplicates = (0, equivalence_js_1.areEquivalent)(args[i], args[j], context.sourceCode);
|
|
136
|
+
if (duplicates && !(0, ast_js_1.isLiteral)(args[i])) {
|
|
137
|
+
(0, location_js_1.report)(context, { message: `Replace this argument or its duplicate.`, node: args[i] }, [
|
|
138
|
+
(0, location_js_1.toSecondaryLocation)(args[j]),
|
|
135
139
|
]);
|
|
136
140
|
}
|
|
137
141
|
}
|
package/cjs/S5867/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 location_js_1 = require("../helpers/location.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
56
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
57
|
const rule_template_js_1 = require("../helpers/regex/rule-template.js");
|
|
57
|
-
const
|
|
58
|
+
const location_js_2 = require("../helpers/regex/location.js");
|
|
58
59
|
exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
59
60
|
const unicodeProperties = [];
|
|
60
61
|
const unicodeCharacters = [];
|
|
@@ -152,15 +153,15 @@ exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
|
152
153
|
if (!isUnicodeEnabled && (unicodeProperties.length > 0 || unicodeCharacters.length > 0)) {
|
|
153
154
|
const secondaryLocations = [];
|
|
154
155
|
for (const p of unicodeProperties) {
|
|
155
|
-
const loc = (0,
|
|
156
|
+
const loc = (0, location_js_2.getRegexpLocation)(context.node, p.character, context, [0, p.offset]);
|
|
156
157
|
if (loc) {
|
|
157
|
-
secondaryLocations.push((0,
|
|
158
|
+
secondaryLocations.push((0, location_js_1.toSecondaryLocation)({ loc }, 'Unicode property'));
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
for (const c of unicodeCharacters) {
|
|
161
|
-
const loc = (0,
|
|
162
|
+
const loc = (0, location_js_2.getRegexpLocation)(context.node, c, context);
|
|
162
163
|
if (loc) {
|
|
163
|
-
secondaryLocations.push((0,
|
|
164
|
+
secondaryLocations.push((0, location_js_1.toSecondaryLocation)({ loc }, 'Unicode character'));
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
context.reportRegExpNode({
|
|
@@ -171,4 +172,4 @@ exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
|
171
172
|
}
|
|
172
173
|
},
|
|
173
174
|
};
|
|
174
|
-
}, (0,
|
|
175
|
+
}, (0, generate_meta_js_1.generateMeta)(meta));
|
package/cjs/S5868/rule.js
CHANGED
|
@@ -51,13 +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 ancestor_js_1 = require("../helpers/ancestor.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
56
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
55
57
|
const regexpp_1 = require("@eslint-community/regexpp");
|
|
56
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
57
59
|
const extract_js_1 = require("../helpers/regex/extract.js");
|
|
58
60
|
const flags_js_1 = require("../helpers/regex/flags.js");
|
|
59
61
|
const rule_template_js_1 = require("../helpers/regex/rule-template.js");
|
|
60
|
-
const
|
|
62
|
+
const ast_js_2 = require("../helpers/regex/ast.js");
|
|
61
63
|
const MODIFIABLE_REGEXP_FLAGS_TYPES = new Set([
|
|
62
64
|
'Literal',
|
|
63
65
|
'TemplateLiteral',
|
|
@@ -120,7 +122,7 @@ exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
|
120
122
|
return reported;
|
|
121
123
|
}
|
|
122
124
|
function addUnicodeFlag(fixer, node) {
|
|
123
|
-
if ((0,
|
|
125
|
+
if ((0, ast_js_1.isRegexLiteral)(node)) {
|
|
124
126
|
return insertTextAfter(fixer, node, 'u');
|
|
125
127
|
}
|
|
126
128
|
const regExpConstructor = getRegExpConstructor(node);
|
|
@@ -208,7 +210,7 @@ exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
|
208
210
|
}
|
|
209
211
|
},
|
|
210
212
|
};
|
|
211
|
-
}, (0,
|
|
213
|
+
}, (0, generate_meta_js_1.generateMeta)(meta, { hasSuggestions: true }));
|
|
212
214
|
function characters(nodes) {
|
|
213
215
|
let current = [];
|
|
214
216
|
const sequences = [current];
|
|
@@ -248,7 +250,7 @@ function isZeroWidthJoiner(code) {
|
|
|
248
250
|
return code === 0x200d;
|
|
249
251
|
}
|
|
250
252
|
function getRegExpConstructor(node) {
|
|
251
|
-
return (0,
|
|
253
|
+
return (0, ancestor_js_1.ancestorsChain)(node, new Set(['CallExpression', 'NewExpression'])).find(n => (0, ast_js_2.isRegExpConstructor)(n));
|
|
252
254
|
}
|
|
253
255
|
function hasModifiableFlags(regExpConstructor) {
|
|
254
256
|
const args = regExpConstructor.arguments;
|
package/cjs/S5869/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 location_js_1 = require("../helpers/location.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
56
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
57
|
const rule_template_js_1 = require("../helpers/regex/rule-template.js");
|
|
57
58
|
const simplified_regex_character_class_js_1 = require("../helpers/regex/simplified-regex-character-class.js");
|
|
58
|
-
const
|
|
59
|
+
const location_js_2 = require("../helpers/regex/location.js");
|
|
59
60
|
exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
60
61
|
let flags;
|
|
61
62
|
return {
|
|
@@ -79,9 +80,9 @@ exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
|
79
80
|
const [primary, ...secondaries] = duplicates;
|
|
80
81
|
const secondaryLocations = [];
|
|
81
82
|
for (const secondary of secondaries) {
|
|
82
|
-
const loc = (0,
|
|
83
|
+
const loc = (0, location_js_2.getRegexpLocation)(context.node, secondary, context);
|
|
83
84
|
if (loc) {
|
|
84
|
-
secondaryLocations.push((0,
|
|
85
|
+
secondaryLocations.push((0, location_js_1.toSecondaryLocation)({ loc }, 'Additional duplicate'));
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
context.reportRegExpNode({
|
|
@@ -92,4 +93,4 @@ exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
|
92
93
|
}
|
|
93
94
|
},
|
|
94
95
|
};
|
|
95
|
-
}, (0,
|
|
96
|
+
}, (0, generate_meta_js_1.generateMeta)(meta));
|
package/cjs/S5876/rule.js
CHANGED
|
@@ -51,10 +51,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const ancestor_js_1 = require("../helpers/ancestor.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
56
|
+
const module_js_1 = require("../helpers/module.js");
|
|
57
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
58
|
+
const collection_js_1 = require("../helpers/collection.js");
|
|
55
59
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
60
|
exports.rule = {
|
|
57
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
58
62
|
messages: {
|
|
59
63
|
createSession: 'Create a new session during user authentication to prevent session fixation attacks.',
|
|
60
64
|
},
|
|
@@ -70,14 +74,14 @@ exports.rule = {
|
|
|
70
74
|
sessionRegenerate = true;
|
|
71
75
|
return;
|
|
72
76
|
}
|
|
73
|
-
for (const childNode of (0,
|
|
77
|
+
for (const childNode of (0, ancestor_js_1.childrenOf)(node, context.sourceCode.visitorKeys)) {
|
|
74
78
|
visitCallback(childNode);
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
81
|
function hasSessionFalseOption(callExpression) {
|
|
78
82
|
const opt = callExpression.arguments[1];
|
|
79
83
|
if (opt?.type === 'ObjectExpression') {
|
|
80
|
-
const sessionProp = (0,
|
|
84
|
+
const sessionProp = (0, ast_js_1.getPropertyWithValue)(context, opt, 'session', false);
|
|
81
85
|
return !!sessionProp;
|
|
82
86
|
}
|
|
83
87
|
return false;
|
|
@@ -85,13 +89,13 @@ exports.rule = {
|
|
|
85
89
|
return {
|
|
86
90
|
CallExpression: (node) => {
|
|
87
91
|
const callExpression = node;
|
|
88
|
-
if ((0,
|
|
92
|
+
if ((0, module_js_1.getFullyQualifiedName)(context, callExpression) === 'passport.authenticate') {
|
|
89
93
|
if (hasSessionFalseOption(callExpression)) {
|
|
90
94
|
return;
|
|
91
95
|
}
|
|
92
|
-
const parent = (0,
|
|
96
|
+
const parent = (0, collection_js_1.last)(context.sourceCode.getAncestors(node));
|
|
93
97
|
if (parent.type === 'CallExpression') {
|
|
94
|
-
const callback = (0,
|
|
98
|
+
const callback = (0, ast_js_1.getValueOfExpression)(context, parent.arguments[2], 'FunctionExpression');
|
|
95
99
|
if (callback?.type === 'FunctionExpression') {
|
|
96
100
|
sessionRegenerate = false;
|
|
97
101
|
visitCallback(callback);
|
|
@@ -108,5 +112,5 @@ exports.rule = {
|
|
|
108
112
|
function isSessionRegenerate(node) {
|
|
109
113
|
return (node.type === 'CallExpression' &&
|
|
110
114
|
node.callee.type === 'MemberExpression' &&
|
|
111
|
-
(0,
|
|
115
|
+
(0, ast_js_1.isIdentifier)(node.callee.property, 'regenerate'));
|
|
112
116
|
}
|
package/cjs/S5958/rule.js
CHANGED
|
@@ -51,16 +51,19 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
|
+
const reaching_definitions_js_1 = require("../helpers/reaching-definitions.js");
|
|
56
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
57
|
+
const mocha_js_1 = require("../helpers/mocha.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
|
create(context) {
|
|
59
62
|
let catchWithDone = false;
|
|
60
63
|
function isInsideTest(node) {
|
|
61
64
|
return context.sourceCode
|
|
62
65
|
.getAncestors(node)
|
|
63
|
-
.some(n => n.type === 'CallExpression' &&
|
|
66
|
+
.some(n => n.type === 'CallExpression' && (0, mocha_js_1.isTestConstruct)(n));
|
|
64
67
|
}
|
|
65
68
|
return {
|
|
66
69
|
'CatchClause CallExpression[callee.name="done"]': (_node) => {
|
|
@@ -73,7 +76,7 @@ exports.rule = {
|
|
|
73
76
|
catchWithDone = false;
|
|
74
77
|
const { param } = node;
|
|
75
78
|
if (param?.type === 'Identifier') {
|
|
76
|
-
const exception = (0,
|
|
79
|
+
const exception = (0, reaching_definitions_js_1.getVariableFromIdentifier)(param, context.sourceCode.getScope(node));
|
|
77
80
|
if (exception?.references.length === 0) {
|
|
78
81
|
context.report({
|
|
79
82
|
node: param,
|
|
@@ -87,7 +90,7 @@ exports.rule = {
|
|
|
87
90
|
if (isInsideTest(node) &&
|
|
88
91
|
isThrowAssertWithoutNot(callExpr) &&
|
|
89
92
|
(callExpr.arguments.length === 0 ||
|
|
90
|
-
(callExpr.arguments.length === 1 && (0,
|
|
93
|
+
(callExpr.arguments.length === 1 && (0, ast_js_1.isIdentifier)(callExpr.arguments[0], 'Error')))) {
|
|
91
94
|
context.report({
|
|
92
95
|
node: callExpr.callee.property,
|
|
93
96
|
message: 'Assert more concrete exception type or assert the message of exception.',
|
|
@@ -103,17 +106,17 @@ function isThrowAssertWithoutNot(node) {
|
|
|
103
106
|
return false;
|
|
104
107
|
}
|
|
105
108
|
let { object, property } = node.callee;
|
|
106
|
-
if (!(0,
|
|
109
|
+
if (!(0, ast_js_1.isIdentifier)(property, 'throw')) {
|
|
107
110
|
return false;
|
|
108
111
|
}
|
|
109
112
|
while (object.type === 'MemberExpression') {
|
|
110
|
-
if ((0,
|
|
113
|
+
if ((0, ast_js_1.isIdentifier)(object.property, 'not')) {
|
|
111
114
|
return false;
|
|
112
115
|
}
|
|
113
|
-
if ((0,
|
|
116
|
+
if ((0, ast_js_1.isIdentifier)(object.property, 'should')) {
|
|
114
117
|
return true;
|
|
115
118
|
}
|
|
116
119
|
object = object.object;
|
|
117
120
|
}
|
|
118
|
-
return object.type === 'CallExpression' && (0,
|
|
121
|
+
return object.type === 'CallExpression' && (0, ast_js_1.isIdentifier)(object.callee, 'expect');
|
|
119
122
|
}
|
package/cjs/S5973/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 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");
|
|
57
|
+
const mocha_js_1 = require("../helpers/mocha.js");
|
|
55
58
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
59
|
const dependencies_js_1 = require("../helpers/package-jsons/dependencies.js");
|
|
57
60
|
exports.rule = {
|
|
58
|
-
meta: (0,
|
|
61
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
59
62
|
messages: {
|
|
60
63
|
stable: 'Make your tests stable so that they pass on the first try, or remove the flaky ones.',
|
|
61
64
|
},
|
|
@@ -73,7 +76,7 @@ exports.rule = {
|
|
|
73
76
|
report(context, node);
|
|
74
77
|
return;
|
|
75
78
|
}
|
|
76
|
-
if (
|
|
79
|
+
if ((0, mocha_js_1.isDescribeCase)(node)) {
|
|
77
80
|
describes.push(node);
|
|
78
81
|
return;
|
|
79
82
|
}
|
|
@@ -82,7 +85,7 @@ exports.rule = {
|
|
|
82
85
|
}
|
|
83
86
|
},
|
|
84
87
|
'CallExpression:exit': (node) => {
|
|
85
|
-
if (
|
|
88
|
+
if ((0, mocha_js_1.isDescribeCase)(node)) {
|
|
86
89
|
describes.pop();
|
|
87
90
|
}
|
|
88
91
|
},
|
|
@@ -93,9 +96,9 @@ exports.rule = {
|
|
|
93
96
|
},
|
|
94
97
|
};
|
|
95
98
|
function hasJestRetry(context, node, hasJest) {
|
|
96
|
-
const callExpressionName = (0,
|
|
99
|
+
const callExpressionName = (0, module_js_1.getFullyQualifiedName)(context, node);
|
|
97
100
|
return (callExpressionName === 'jest.retryTimes' ||
|
|
98
|
-
(hasJest && (0,
|
|
101
|
+
(hasJest && (0, ast_js_1.isMethodInvocation)(node, 'jest', 'retryTimes', 1)));
|
|
99
102
|
}
|
|
100
103
|
function hasJestDependency(context) {
|
|
101
104
|
const dependencies = (0, dependencies_js_1.getDependenciesSanitizePaths)(context);
|
|
@@ -108,7 +111,7 @@ function checkMochaRetries(context, node) {
|
|
|
108
111
|
const callee = node.callee;
|
|
109
112
|
if (callee.type === 'MemberExpression' &&
|
|
110
113
|
callee.object.type === 'ThisExpression' &&
|
|
111
|
-
(0,
|
|
114
|
+
(0, ast_js_1.isIdentifier)(callee.property, 'retries')) {
|
|
112
115
|
report(context, node);
|
|
113
116
|
}
|
|
114
117
|
}
|
package/cjs/S6019/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 collection_js_1 = require("../helpers/collection.js");
|
|
55
56
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
57
|
const rule_template_js_1 = require("../helpers/regex/rule-template.js");
|
|
57
58
|
exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
@@ -62,7 +63,7 @@ exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
|
62
63
|
}
|
|
63
64
|
},
|
|
64
65
|
};
|
|
65
|
-
}, (0,
|
|
66
|
+
}, (0, generate_meta_js_1.generateMeta)(meta));
|
|
66
67
|
function report(quantifier, context) {
|
|
67
68
|
const ending = quantifier.min === 1 ? '' : 's';
|
|
68
69
|
const message = `Fix this reluctant quantifier that will only ever match ${quantifier.min} repetition${ending}.`;
|
|
@@ -76,7 +77,7 @@ function checkElements(elements, context) {
|
|
|
76
77
|
if (elements.length === 0) {
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
79
|
-
const lastElement = (0,
|
|
80
|
+
const lastElement = (0, collection_js_1.last)(elements);
|
|
80
81
|
if (lastElement.type === 'Quantifier' && !lastElement.greedy) {
|
|
81
82
|
report(lastElement, context);
|
|
82
83
|
return;
|
package/cjs/S6035/rule.js
CHANGED
|
@@ -51,7 +51,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
55
55
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
56
|
const rule_template_js_1 = require("../helpers/regex/rule-template.js");
|
|
57
57
|
exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
@@ -78,4 +78,4 @@ exports.rule = (0, rule_template_js_1.createRegExpRule)(context => {
|
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
80
|
};
|
|
81
|
-
}, (0,
|
|
81
|
+
}, (0, generate_meta_js_1.generateMeta)(meta));
|
package/cjs/S6079/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 reaching_definitions_js_1 = require("../helpers/reaching-definitions.js");
|
|
56
|
+
const mocha_js_1 = require("../helpers/mocha.js");
|
|
57
|
+
const location_js_1 = require("../helpers/location.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
|
create(context) {
|
|
59
62
|
let currentDoneVariable;
|
|
60
63
|
let doneCall;
|
|
@@ -63,7 +66,7 @@ exports.rule = {
|
|
|
63
66
|
let currentCase;
|
|
64
67
|
const segmentFirstStatement = new Map();
|
|
65
68
|
function checkForTestCase(node) {
|
|
66
|
-
const testCase =
|
|
69
|
+
const testCase = (0, mocha_js_1.extractTestCase)(node);
|
|
67
70
|
if (!testCase) {
|
|
68
71
|
return;
|
|
69
72
|
}
|
|
@@ -82,7 +85,7 @@ exports.rule = {
|
|
|
82
85
|
if (!callbackScope) {
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
85
|
-
currentDoneVariable = (0,
|
|
88
|
+
currentDoneVariable = (0, reaching_definitions_js_1.getVariableFromIdentifier)(done, callbackScope);
|
|
86
89
|
}
|
|
87
90
|
function checkForDoneCall(node) {
|
|
88
91
|
const { callee } = node;
|
|
@@ -92,10 +95,10 @@ exports.rule = {
|
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
function report(statementAfterDone) {
|
|
95
|
-
(0,
|
|
98
|
+
(0, location_js_1.report)(context, {
|
|
96
99
|
node: statementAfterDone,
|
|
97
100
|
message: `Move this code before the call to "done".`,
|
|
98
|
-
}, [(0,
|
|
101
|
+
}, [(0, location_js_1.toSecondaryLocation)(doneCall)]);
|
|
99
102
|
doneSegment = undefined;
|
|
100
103
|
doneCall = undefined;
|
|
101
104
|
currentDoneVariable = undefined;
|