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/S3757/rule.js
CHANGED
|
@@ -55,19 +55,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.rule = void 0;
|
|
57
57
|
const typescript_1 = __importDefault(require("typescript"));
|
|
58
|
-
const
|
|
58
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
59
|
+
const type_js_1 = require("../helpers/type.js");
|
|
60
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
59
61
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
62
|
const BINARY_OPERATORS = new Set(['/', '*', '%', '-', '-=', '*=', '/=', '%=']);
|
|
61
63
|
const UNARY_OPERATORS = new Set(['++', '--', '+', '-']);
|
|
62
64
|
exports.rule = {
|
|
63
|
-
meta: (0,
|
|
65
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
64
66
|
messages: {
|
|
65
67
|
noEvaluatedNaN: 'Change the expression which uses this operand so that it can\'t evaluate to "NaN" (Not a Number).',
|
|
66
68
|
},
|
|
67
69
|
}),
|
|
68
70
|
create(context) {
|
|
69
71
|
const services = context.sourceCode.parserServices;
|
|
70
|
-
if (!(0,
|
|
72
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
71
73
|
return {};
|
|
72
74
|
}
|
|
73
75
|
function isObjectType(...types) {
|
|
@@ -83,8 +85,8 @@ exports.rule = {
|
|
|
83
85
|
if (!BINARY_OPERATORS.has(expression.operator)) {
|
|
84
86
|
return;
|
|
85
87
|
}
|
|
86
|
-
const leftType = (0,
|
|
87
|
-
const rightType = (0,
|
|
88
|
+
const leftType = (0, type_js_1.getTypeFromTreeNode)(expression.left, services);
|
|
89
|
+
const rightType = (0, type_js_1.getTypeFromTreeNode)(expression.right, services);
|
|
88
90
|
if (isObjectType(leftType)) {
|
|
89
91
|
context.report({ node: expression.left, messageId: 'noEvaluatedNaN' });
|
|
90
92
|
}
|
|
@@ -97,7 +99,7 @@ exports.rule = {
|
|
|
97
99
|
if (!UNARY_OPERATORS.has(expr.operator)) {
|
|
98
100
|
return;
|
|
99
101
|
}
|
|
100
|
-
const argType = (0,
|
|
102
|
+
const argType = (0, type_js_1.getTypeFromTreeNode)(expr.argument, services);
|
|
101
103
|
if (isObjectType(argType)) {
|
|
102
104
|
context.report({ node, messageId: 'noEvaluatedNaN' });
|
|
103
105
|
}
|
package/cjs/S3758/rule.js
CHANGED
|
@@ -55,18 +55,20 @@ 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");
|
|
59
61
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
62
|
const comparisonOperators = new Set(['>', '<', '>=', '<=']);
|
|
61
63
|
exports.rule = {
|
|
62
|
-
meta: (0,
|
|
64
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
63
65
|
messages: {
|
|
64
66
|
reEvaluateDataFlow: 'Re-evaluate the data flow; this operand of a numeric comparison could be of type {{type}}.',
|
|
65
67
|
},
|
|
66
68
|
}),
|
|
67
69
|
create(context) {
|
|
68
70
|
const services = context.sourceCode.parserServices;
|
|
69
|
-
if (!(0,
|
|
71
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
70
72
|
return {};
|
|
71
73
|
}
|
|
72
74
|
return {
|
|
@@ -80,9 +82,9 @@ exports.rule = {
|
|
|
80
82
|
return;
|
|
81
83
|
}
|
|
82
84
|
const checker = services.program.getTypeChecker();
|
|
83
|
-
const leftType = (0,
|
|
84
|
-
const rightType = (0,
|
|
85
|
-
if ((0,
|
|
85
|
+
const leftType = (0, type_js_1.getTypeFromTreeNode)(left, services);
|
|
86
|
+
const rightType = (0, type_js_1.getTypeFromTreeNode)(right, services);
|
|
87
|
+
if ((0, type_js_1.isStringType)(leftType) || (0, type_js_1.isStringType)(rightType)) {
|
|
86
88
|
return;
|
|
87
89
|
}
|
|
88
90
|
const isLeftConvertibleToNumber = isConvertibleToNumber(leftType, checker);
|
|
@@ -121,7 +123,7 @@ function isConvertibleToNumber(typ, checker) {
|
|
|
121
123
|
return (valueOfSignatures.length === 0 ||
|
|
122
124
|
valueOfSignatures.some(signature => {
|
|
123
125
|
const returnType = signature.getReturnType();
|
|
124
|
-
return (0,
|
|
126
|
+
return (0, type_js_1.isNumberType)(returnType) || (0, type_js_1.isBigIntType)(returnType);
|
|
125
127
|
}));
|
|
126
128
|
}
|
|
127
129
|
function getValueOfSignatures(typ, checker) {
|
package/cjs/S3760/rule.js
CHANGED
|
@@ -55,22 +55,25 @@ 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 location_js_1 = require("../helpers/location.js");
|
|
59
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
60
|
+
const type_js_1 = require("../helpers/type.js");
|
|
61
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
59
62
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
63
|
const MESSAGE = 'Convert this operand into a number.';
|
|
61
64
|
exports.rule = {
|
|
62
|
-
meta: (0,
|
|
65
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
63
66
|
create(context) {
|
|
64
67
|
const services = context.sourceCode.parserServices;
|
|
65
|
-
if (!(0,
|
|
68
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
66
69
|
return {};
|
|
67
70
|
}
|
|
68
71
|
return {
|
|
69
72
|
BinaryExpression: (node) => {
|
|
70
73
|
const binaryExpression = node;
|
|
71
74
|
const operator = binaryExpression.operator;
|
|
72
|
-
const leftType = (0,
|
|
73
|
-
const rightType = (0,
|
|
75
|
+
const leftType = (0, type_js_1.getTypeFromTreeNode)(binaryExpression.left, services);
|
|
76
|
+
const rightType = (0, type_js_1.getTypeFromTreeNode)(binaryExpression.right, services);
|
|
74
77
|
if (operator === '+') {
|
|
75
78
|
checkPlus(leftType, rightType, binaryExpression, context);
|
|
76
79
|
}
|
|
@@ -84,8 +87,8 @@ exports.rule = {
|
|
|
84
87
|
AssignmentExpression: (node) => {
|
|
85
88
|
const assignmentExpression = node;
|
|
86
89
|
const operator = assignmentExpression.operator;
|
|
87
|
-
const leftType = (0,
|
|
88
|
-
const rightType = (0,
|
|
90
|
+
const leftType = (0, type_js_1.getTypeFromTreeNode)(assignmentExpression.left, services);
|
|
91
|
+
const rightType = (0, type_js_1.getTypeFromTreeNode)(assignmentExpression.right, services);
|
|
89
92
|
if (operator === '+=') {
|
|
90
93
|
checkPlus(leftType, rightType, assignmentExpression, context);
|
|
91
94
|
}
|
|
@@ -95,9 +98,9 @@ exports.rule = {
|
|
|
95
98
|
},
|
|
96
99
|
'UnaryExpression[operator="-"]': (node) => {
|
|
97
100
|
const unaryExpression = node;
|
|
98
|
-
const type = (0,
|
|
101
|
+
const type = (0, type_js_1.getTypeFromTreeNode)(unaryExpression.argument, services);
|
|
99
102
|
if (isBooleanStringOrDate(type)) {
|
|
100
|
-
(0,
|
|
103
|
+
(0, location_js_1.report)(context, {
|
|
101
104
|
node: unaryExpression.argument,
|
|
102
105
|
message: MESSAGE,
|
|
103
106
|
});
|
|
@@ -105,9 +108,9 @@ exports.rule = {
|
|
|
105
108
|
},
|
|
106
109
|
UpdateExpression: (node) => {
|
|
107
110
|
const updateExpression = node;
|
|
108
|
-
const type = (0,
|
|
111
|
+
const type = (0, type_js_1.getTypeFromTreeNode)(updateExpression.argument, services);
|
|
109
112
|
if (isBooleanStringOrDate(type)) {
|
|
110
|
-
(0,
|
|
113
|
+
(0, location_js_1.report)(context, {
|
|
111
114
|
node: updateExpression.argument,
|
|
112
115
|
message: MESSAGE,
|
|
113
116
|
});
|
|
@@ -131,27 +134,27 @@ function isDateMinusDateException(leftType, rightType, operator) {
|
|
|
131
134
|
}
|
|
132
135
|
function checkPlus(leftType, rightType, expression, context) {
|
|
133
136
|
if (isNumber(leftType) && isBooleanOrDate(rightType)) {
|
|
134
|
-
(0,
|
|
137
|
+
(0, location_js_1.report)(context, {
|
|
135
138
|
node: expression.right,
|
|
136
139
|
message: MESSAGE,
|
|
137
|
-
}, [(0,
|
|
140
|
+
}, [(0, location_js_1.toSecondaryLocation)(expression.left)]);
|
|
138
141
|
}
|
|
139
142
|
if (isNumber(rightType) && isBooleanOrDate(leftType)) {
|
|
140
|
-
(0,
|
|
143
|
+
(0, location_js_1.report)(context, {
|
|
141
144
|
node: expression.left,
|
|
142
145
|
message: MESSAGE,
|
|
143
|
-
}, [(0,
|
|
146
|
+
}, [(0, location_js_1.toSecondaryLocation)(expression.right)]);
|
|
144
147
|
}
|
|
145
148
|
}
|
|
146
149
|
function checkComparison(leftType, rightType, expression, context) {
|
|
147
150
|
if (isBooleanOrNumber(leftType) && isBooleanStringOrDate(rightType)) {
|
|
148
|
-
(0,
|
|
151
|
+
(0, location_js_1.report)(context, {
|
|
149
152
|
node: expression.right,
|
|
150
153
|
message: MESSAGE,
|
|
151
154
|
});
|
|
152
155
|
}
|
|
153
156
|
else if (isBooleanOrNumber(rightType) && isBooleanStringOrDate(leftType)) {
|
|
154
|
-
(0,
|
|
157
|
+
(0, location_js_1.report)(context, {
|
|
155
158
|
node: expression.left,
|
|
156
159
|
message: MESSAGE,
|
|
157
160
|
});
|
|
@@ -163,13 +166,13 @@ function checkArithmetic(leftType, rightType, expression, context) {
|
|
|
163
166
|
}
|
|
164
167
|
const secondaryLocations = [];
|
|
165
168
|
if (isBooleanStringOrDate(leftType)) {
|
|
166
|
-
secondaryLocations.push((0,
|
|
169
|
+
secondaryLocations.push((0, location_js_1.toSecondaryLocation)(expression.left));
|
|
167
170
|
}
|
|
168
171
|
if (isBooleanStringOrDate(rightType)) {
|
|
169
|
-
secondaryLocations.push((0,
|
|
172
|
+
secondaryLocations.push((0, location_js_1.toSecondaryLocation)(expression.right));
|
|
170
173
|
}
|
|
171
174
|
if (secondaryLocations.length !== 0) {
|
|
172
|
-
(0,
|
|
175
|
+
(0, location_js_1.report)(context, {
|
|
173
176
|
node: expression,
|
|
174
177
|
message: 'Convert the operands of this operation into numbers.',
|
|
175
178
|
}, secondaryLocations);
|
|
@@ -191,5 +194,5 @@ function isNumber(type) {
|
|
|
191
194
|
return (type.flags & typescript_1.default.TypeFlags.NumberLike) > 0 || type.symbol?.name === 'Number';
|
|
192
195
|
}
|
|
193
196
|
function isBooleanStringOrDate(type) {
|
|
194
|
-
return isBoolean(type) || (0,
|
|
197
|
+
return isBoolean(type) || (0, type_js_1.isStringType)(type) || type.symbol?.name === 'Date';
|
|
195
198
|
}
|
package/cjs/S3776/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 location_js_1 = require("../helpers/location.js");
|
|
55
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
56
|
+
const jsx_js_1 = require("../helpers/jsx.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
|
const DEFAULT_THRESHOLD = 15;
|
|
57
61
|
const message = 'Refactor this function to reduce its Cognitive Complexity from {{complexityAmount}} to the {{threshold}} allowed.';
|
|
58
62
|
exports.rule = {
|
|
59
|
-
meta: (0,
|
|
63
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
60
64
|
messages: {
|
|
61
65
|
refactorFunction: message,
|
|
62
66
|
fileComplexity: '{{complexityAmount}}',
|
|
@@ -227,19 +231,19 @@ exports.rule = {
|
|
|
227
231
|
parent: node.parent,
|
|
228
232
|
complexityIfNested,
|
|
229
233
|
complexityIfThisSecondaryIsTopLevel: complexityIfNotNested,
|
|
230
|
-
loc: (0,
|
|
234
|
+
loc: (0, location_js_1.getMainFunctionTokenLocation)(node, node.parent, context),
|
|
231
235
|
});
|
|
232
236
|
}
|
|
233
237
|
if (isFileComplexity) {
|
|
234
238
|
return;
|
|
235
239
|
}
|
|
236
|
-
checkFunction(functionComplexity, (0,
|
|
240
|
+
checkFunction(functionComplexity, (0, location_js_1.getMainFunctionTokenLocation)(node, node.parent, context));
|
|
237
241
|
}
|
|
238
242
|
function visitIfStatement(ifStatement) {
|
|
239
243
|
const { parent } = ifStatement;
|
|
240
|
-
const { loc: ifLoc } = (0,
|
|
244
|
+
const { loc: ifLoc } = (0, location_js_1.getFirstToken)(ifStatement, context);
|
|
241
245
|
// if the current `if` statement is `else if`, do not count it in structural complexity
|
|
242
|
-
if ((0,
|
|
246
|
+
if ((0, ast_js_1.isIfStatement)(parent) && parent.alternate === ifStatement) {
|
|
243
247
|
addComplexity(ifLoc);
|
|
244
248
|
}
|
|
245
249
|
else {
|
|
@@ -250,33 +254,33 @@ exports.rule = {
|
|
|
250
254
|
// if `else` branch is not `else if` then
|
|
251
255
|
// - increase nesting level inside `else` statement
|
|
252
256
|
// - add +1 complexity
|
|
253
|
-
if (ifStatement.alternate && !(0,
|
|
257
|
+
if (ifStatement.alternate && !(0, ast_js_1.isIfStatement)(ifStatement.alternate)) {
|
|
254
258
|
nestingNodes.add(ifStatement.alternate);
|
|
255
|
-
const elseTokenLoc = (0,
|
|
259
|
+
const elseTokenLoc = (0, location_js_1.getFirstTokenAfter)(ifStatement.consequent, context).loc;
|
|
256
260
|
addComplexity(elseTokenLoc);
|
|
257
261
|
}
|
|
258
262
|
}
|
|
259
263
|
function visitLoop(loop) {
|
|
260
|
-
addStructuralComplexity((0,
|
|
264
|
+
addStructuralComplexity((0, location_js_1.getFirstToken)(loop, context).loc);
|
|
261
265
|
nestingNodes.add(loop.body);
|
|
262
266
|
}
|
|
263
267
|
function visitSwitchStatement(switchStatement) {
|
|
264
|
-
addStructuralComplexity((0,
|
|
268
|
+
addStructuralComplexity((0, location_js_1.getFirstToken)(switchStatement, context).loc);
|
|
265
269
|
for (const switchCase of switchStatement.cases) {
|
|
266
270
|
nestingNodes.add(switchCase);
|
|
267
271
|
}
|
|
268
272
|
}
|
|
269
273
|
function visitContinueOrBreakStatement(statement) {
|
|
270
274
|
if (statement.label) {
|
|
271
|
-
addComplexity((0,
|
|
275
|
+
addComplexity((0, location_js_1.getFirstToken)(statement, context).loc);
|
|
272
276
|
}
|
|
273
277
|
}
|
|
274
278
|
function visitCatchClause(catchClause) {
|
|
275
|
-
addStructuralComplexity((0,
|
|
279
|
+
addStructuralComplexity((0, location_js_1.getFirstToken)(catchClause, context).loc);
|
|
276
280
|
nestingNodes.add(catchClause.body);
|
|
277
281
|
}
|
|
278
282
|
function visitConditionalExpression(conditionalExpression) {
|
|
279
|
-
const questionTokenLoc = (0,
|
|
283
|
+
const questionTokenLoc = (0, location_js_1.getFirstTokenAfter)(conditionalExpression.test, context).loc;
|
|
280
284
|
addStructuralComplexity(questionTokenLoc);
|
|
281
285
|
nestingNodes.add(conditionalExpression.consequent);
|
|
282
286
|
nestingNodes.add(conditionalExpression.alternate);
|
|
@@ -294,7 +298,7 @@ exports.rule = {
|
|
|
294
298
|
const firstLetter = name[0];
|
|
295
299
|
return firstLetter === firstLetter.toUpperCase();
|
|
296
300
|
};
|
|
297
|
-
if (!(0,
|
|
301
|
+
if (!(0, ast_js_1.isArrowFunctionExpression)(node) && node.id) {
|
|
298
302
|
return checkFirstLetter(node.id.name);
|
|
299
303
|
}
|
|
300
304
|
const { parent } = node;
|
|
@@ -304,7 +308,7 @@ exports.rule = {
|
|
|
304
308
|
return false;
|
|
305
309
|
}
|
|
306
310
|
function visitLogicalExpression(logicalExpression) {
|
|
307
|
-
const jsxShortCircuitNodes = (0,
|
|
311
|
+
const jsxShortCircuitNodes = (0, jsx_js_1.getJsxShortCircuitNodes)(logicalExpression);
|
|
308
312
|
if (jsxShortCircuitNodes != null) {
|
|
309
313
|
for (const node of jsxShortCircuitNodes) {
|
|
310
314
|
consideredLogicalExpressions.add(node);
|
|
@@ -318,7 +322,7 @@ exports.rule = {
|
|
|
318
322
|
if (current.operator !== '||' &&
|
|
319
323
|
current.operator !== '??' &&
|
|
320
324
|
(!previous || previous.operator !== current.operator)) {
|
|
321
|
-
const operatorTokenLoc = (0,
|
|
325
|
+
const operatorTokenLoc = (0, location_js_1.getFirstTokenAfter)(current.left, context).loc;
|
|
322
326
|
addComplexity(operatorTokenLoc);
|
|
323
327
|
}
|
|
324
328
|
previous = current;
|
|
@@ -326,7 +330,7 @@ exports.rule = {
|
|
|
326
330
|
}
|
|
327
331
|
}
|
|
328
332
|
function flattenLogicalExpression(node) {
|
|
329
|
-
if ((0,
|
|
333
|
+
if ((0, ast_js_1.isLogicalExpression)(node)) {
|
|
330
334
|
consideredLogicalExpressions.add(node);
|
|
331
335
|
return [
|
|
332
336
|
...flattenLogicalExpression(node.left),
|
|
@@ -354,8 +358,8 @@ exports.rule = {
|
|
|
354
358
|
complexityIfNotNested.push(complexityPoint);
|
|
355
359
|
}
|
|
356
360
|
if (functionOwnComplexity.length > 0) {
|
|
357
|
-
const addedWithoutFunctionNesting = (0,
|
|
358
|
-
(0,
|
|
361
|
+
const addedWithoutFunctionNesting = (0, collection_js_1.last)(functionOwnControlFlowNesting) + 1;
|
|
362
|
+
(0, collection_js_1.last)(functionOwnComplexity).push({
|
|
359
363
|
complexity: addedWithoutFunctionNesting,
|
|
360
364
|
location,
|
|
361
365
|
});
|
|
@@ -364,7 +368,7 @@ exports.rule = {
|
|
|
364
368
|
function addComplexity(location) {
|
|
365
369
|
const complexityPoint = { complexity: 1, location };
|
|
366
370
|
if (functionOwnComplexity.length > 0) {
|
|
367
|
-
(0,
|
|
371
|
+
(0, collection_js_1.last)(functionOwnComplexity).push(complexityPoint);
|
|
368
372
|
}
|
|
369
373
|
if (enclosingFunctions.length === 0) {
|
|
370
374
|
// top level scope
|
|
@@ -386,9 +390,9 @@ exports.rule = {
|
|
|
386
390
|
const secondaryLocations = complexity.map(complexityPoint => {
|
|
387
391
|
const { complexity, location } = complexityPoint;
|
|
388
392
|
const message = complexity === 1 ? '+1' : `+${complexity} (incl. ${complexity - 1} for nesting)`;
|
|
389
|
-
return (0,
|
|
393
|
+
return (0, location_js_1.toSecondaryLocation)({ loc: location }, message);
|
|
390
394
|
});
|
|
391
|
-
(0,
|
|
395
|
+
(0, location_js_1.report)(context, {
|
|
392
396
|
messageId: 'refactorFunction',
|
|
393
397
|
message,
|
|
394
398
|
data: {
|
package/cjs/S3782/rule.js
CHANGED
|
@@ -54,14 +54,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
54
54
|
};
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.rule = void 0;
|
|
57
|
-
const
|
|
57
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
58
|
+
const type_js_1 = require("../helpers/type.js");
|
|
59
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
58
60
|
const typescript_1 = __importDefault(require("typescript"));
|
|
59
61
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
62
|
exports.rule = {
|
|
61
|
-
meta: (0,
|
|
63
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
62
64
|
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
|
const tc = services.program.getTypeChecker();
|
|
@@ -87,7 +89,7 @@ exports.rule = {
|
|
|
87
89
|
return null;
|
|
88
90
|
}
|
|
89
91
|
const declaredType = tc.getTypeFromTypeNode(parameterType);
|
|
90
|
-
const actualType = (0,
|
|
92
|
+
const actualType = (0, type_js_1.getTypeFromTreeNode)(callExpression.arguments[i], services);
|
|
91
93
|
if (
|
|
92
94
|
// @ts-ignore private API, see https://github.com/microsoft/TypeScript/issues/9879
|
|
93
95
|
!tc.isTypeAssignableTo(actualType, declaredType) &&
|
package/cjs/S3785/rule.js
CHANGED
|
@@ -55,17 +55,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.rule = void 0;
|
|
57
57
|
const typescript_1 = __importDefault(require("typescript"));
|
|
58
|
-
const
|
|
58
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
59
|
+
const type_js_1 = require("../helpers/type.js");
|
|
60
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
61
|
+
const location_js_1 = require("../helpers/location.js");
|
|
59
62
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
63
|
exports.rule = {
|
|
61
|
-
meta: (0,
|
|
64
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
62
65
|
create(context) {
|
|
63
66
|
const services = context.sourceCode.parserServices;
|
|
64
|
-
if (!(0,
|
|
67
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
65
68
|
return {};
|
|
66
69
|
}
|
|
67
70
|
function isPrimitive(node) {
|
|
68
|
-
const type = (0,
|
|
71
|
+
const type = (0, type_js_1.getTypeFromTreeNode)(node, services);
|
|
69
72
|
return ((type.flags & typescript_1.default.TypeFlags.StringLike) !== 0 ||
|
|
70
73
|
(type.flags & typescript_1.default.TypeFlags.NumberLike) !== 0 ||
|
|
71
74
|
(type.flags & typescript_1.default.TypeFlags.BooleanLike) !== 0 ||
|
|
@@ -79,10 +82,10 @@ exports.rule = {
|
|
|
79
82
|
const opToken = context.sourceCode
|
|
80
83
|
.getTokensBetween(left, right)
|
|
81
84
|
.find(token => token.type === 'Keyword' && token.value === operator);
|
|
82
|
-
(0,
|
|
85
|
+
(0, location_js_1.report)(context, {
|
|
83
86
|
message: 'TypeError can be thrown as this operand might have primitive type.',
|
|
84
87
|
node: right,
|
|
85
|
-
}, [(0,
|
|
88
|
+
}, [(0, location_js_1.toSecondaryLocation)(opToken)]);
|
|
86
89
|
}
|
|
87
90
|
},
|
|
88
91
|
};
|
package/cjs/S3796/rule.js
CHANGED
|
@@ -51,7 +51,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
51
51
|
})();
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.rule = void 0;
|
|
54
|
-
const
|
|
54
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
55
|
+
const type_js_1 = require("../helpers/type.js");
|
|
56
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
57
|
+
const location_js_1 = require("../helpers/location.js");
|
|
58
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
55
59
|
const meta = __importStar(require("./generated-meta.js"));
|
|
56
60
|
const message = `Add a "return" statement to this callback.`;
|
|
57
61
|
const methodsWithCallback = new Set([
|
|
@@ -77,10 +81,10 @@ function hasCallBackWithoutReturn(argument, services) {
|
|
|
77
81
|
signatures.every(sig => checker.typeToString(sig.getReturnType()) === 'void'));
|
|
78
82
|
}
|
|
79
83
|
exports.rule = {
|
|
80
|
-
meta: (0,
|
|
84
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
81
85
|
create(context) {
|
|
82
86
|
const services = context.sourceCode.parserServices;
|
|
83
|
-
if (!(0,
|
|
87
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
84
88
|
return {};
|
|
85
89
|
}
|
|
86
90
|
return {
|
|
@@ -94,14 +98,14 @@ exports.rule = {
|
|
|
94
98
|
return;
|
|
95
99
|
}
|
|
96
100
|
if (methodsWithCallback.has(propName) &&
|
|
97
|
-
((0,
|
|
101
|
+
((0, type_js_1.isArray)(object, services) || (0, type_js_1.isTypedArray)(object, services)) &&
|
|
98
102
|
hasCallBackWithoutReturn(args[0], services)) {
|
|
99
103
|
context.report({
|
|
100
104
|
message,
|
|
101
105
|
...getNodeToReport(args[0], node, context),
|
|
102
106
|
});
|
|
103
107
|
}
|
|
104
|
-
else if ((0,
|
|
108
|
+
else if ((0, ast_js_1.isMemberExpression)(callExpression.callee, 'Array', 'from') &&
|
|
105
109
|
args.length > 1 &&
|
|
106
110
|
hasCallBackWithoutReturn(args[1], services)) {
|
|
107
111
|
context.report({
|
|
@@ -114,10 +118,10 @@ exports.rule = {
|
|
|
114
118
|
},
|
|
115
119
|
};
|
|
116
120
|
function extractPropName(memberExpression) {
|
|
117
|
-
if ((0,
|
|
121
|
+
if ((0, ast_js_1.isDotNotation)(memberExpression)) {
|
|
118
122
|
return memberExpression.property.name;
|
|
119
123
|
}
|
|
120
|
-
else if ((0,
|
|
124
|
+
else if ((0, ast_js_1.isIndexNotation)(memberExpression)) {
|
|
121
125
|
return memberExpression.property.value;
|
|
122
126
|
}
|
|
123
127
|
else {
|
|
@@ -129,7 +133,7 @@ function getNodeToReport(node, parent, context) {
|
|
|
129
133
|
node.type === 'FunctionExpression' ||
|
|
130
134
|
node.type === 'ArrowFunctionExpression') {
|
|
131
135
|
return {
|
|
132
|
-
loc: (0,
|
|
136
|
+
loc: (0, location_js_1.getMainFunctionTokenLocation)(node, parent, context),
|
|
133
137
|
};
|
|
134
138
|
}
|
|
135
139
|
return {
|
package/cjs/S3798/rule.js
CHANGED
|
@@ -34,10 +34,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.rule = void 0;
|
|
37
|
-
const
|
|
37
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
38
|
+
const ast_js_1 = require("../helpers/ast.js");
|
|
38
39
|
const meta = __importStar(require("./generated-meta.js"));
|
|
39
40
|
exports.rule = {
|
|
40
|
-
meta: (0,
|
|
41
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta, {
|
|
41
42
|
messages: {
|
|
42
43
|
defineLocally: 'Define this declaration in a local scope or bind explicitly the property to the global object.',
|
|
43
44
|
},
|
|
@@ -78,5 +79,5 @@ function findModuleScope(context) {
|
|
|
78
79
|
function isRequire(node) {
|
|
79
80
|
return (node?.type === 'CallExpression' &&
|
|
80
81
|
node.arguments.length === 1 &&
|
|
81
|
-
(0,
|
|
82
|
+
(0, ast_js_1.isIdentifier)(node.callee, 'require'));
|
|
82
83
|
}
|
package/cjs/S3800/rule.js
CHANGED
|
@@ -55,7 +55,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.rule = void 0;
|
|
57
57
|
const typescript_1 = __importDefault(require("typescript"));
|
|
58
|
-
const
|
|
58
|
+
const type_js_1 = require("../helpers/type.js");
|
|
59
|
+
const generate_meta_js_1 = require("../helpers/generate-meta.js");
|
|
60
|
+
const location_js_1 = require("../helpers/location.js");
|
|
61
|
+
const ancestor_js_1 = require("../helpers/ancestor.js");
|
|
62
|
+
const parser_services_js_1 = require("../helpers/parser-services.js");
|
|
63
|
+
const collection_js_1 = require("../helpers/collection.js");
|
|
59
64
|
const meta = __importStar(require("./generated-meta.js"));
|
|
60
65
|
class FunctionScope {
|
|
61
66
|
constructor() {
|
|
@@ -70,14 +75,14 @@ class FunctionScope {
|
|
|
70
75
|
}
|
|
71
76
|
const isASanitationFunction = (signature) => {
|
|
72
77
|
const { types } = signature.getReturnType();
|
|
73
|
-
return types.length === 2 && types.some(
|
|
78
|
+
return types.length === 2 && types.some(type_js_1.isBooleanTrueType) && types.some(type_js_1.isStringType);
|
|
74
79
|
};
|
|
75
80
|
exports.rule = {
|
|
76
|
-
meta: (0,
|
|
81
|
+
meta: (0, generate_meta_js_1.generateMeta)(meta),
|
|
77
82
|
create(context) {
|
|
78
83
|
let scopes = [];
|
|
79
84
|
const services = context.sourceCode.parserServices;
|
|
80
|
-
if (!(0,
|
|
85
|
+
if (!(0, parser_services_js_1.isRequiredParserServices)(services)) {
|
|
81
86
|
return {};
|
|
82
87
|
}
|
|
83
88
|
const checker = services.program.getTypeChecker();
|
|
@@ -91,22 +96,28 @@ exports.rule = {
|
|
|
91
96
|
if (isASanitationFunction(signature)) {
|
|
92
97
|
return;
|
|
93
98
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
// Exclude null-like and any-typed returns; any-typed returns come from external/unknown
|
|
100
|
+
// functions whose signature is unavailable and cannot contribute to type inconsistency.
|
|
101
|
+
const stmts = returnStatements.filter(retStmt => {
|
|
102
|
+
const type = (0, type_js_1.getTypeFromTreeNode)(retStmt.argument, services);
|
|
103
|
+
return !isNullLike(type) && !(0, type_js_1.isAny)(type);
|
|
104
|
+
});
|
|
105
|
+
const stmtsTypes = stmts.map(retStmt => (0, type_js_1.getTypeFromTreeNode)(retStmt.argument, services));
|
|
106
|
+
const stmtCategories = stmtsTypes.map(t => prettyPrint(t, checker));
|
|
107
|
+
if (stmtCategories.filter((val, i, arr) => distinct(val, i, arr)).length <= 1) {
|
|
97
108
|
return;
|
|
98
109
|
}
|
|
99
|
-
(0,
|
|
110
|
+
(0, location_js_1.report)(context, {
|
|
100
111
|
message: 'Refactor this function to always return the same type.',
|
|
101
|
-
loc: (0,
|
|
102
|
-
}, stmts.map((stmt, i) => (0,
|
|
112
|
+
loc: (0, location_js_1.getMainFunctionTokenLocation)(node, (0, ancestor_js_1.getParent)(context, node), context),
|
|
113
|
+
}, stmts.map((stmt, i) => (0, location_js_1.toSecondaryLocation)(stmt, `Returns ${prettyPrint(stmtsTypes[i], checker)}`)));
|
|
103
114
|
}
|
|
104
115
|
}
|
|
105
116
|
return {
|
|
106
117
|
ReturnStatement: (node) => {
|
|
107
118
|
const retStmt = node;
|
|
108
119
|
if (scopes.length > 0 && retStmt.argument) {
|
|
109
|
-
(0,
|
|
120
|
+
(0, collection_js_1.last)(scopes).addReturnStatement(retStmt);
|
|
110
121
|
}
|
|
111
122
|
},
|
|
112
123
|
':function': () => {
|
|
@@ -39,7 +39,7 @@ exports.meta = {
|
|
|
39
39
|
description: 'Functions should use "return" consistently',
|
|
40
40
|
recommended: false,
|
|
41
41
|
url: 'https://sonarsource.github.io/rspec/#/rspec/S3801/javascript',
|
|
42
|
-
requiresTypeChecking:
|
|
42
|
+
requiresTypeChecking: true,
|
|
43
43
|
},
|
|
44
44
|
fixable: undefined,
|
|
45
45
|
deprecated: false,
|