eslint-plugin-sonarjs 1.0.0 → 1.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 +21 -10
- package/lib/package.json +106 -0
- package/lib/{index.d.ts → src/index.d.ts} +8 -0
- package/lib/{index.js → src/index.js} +7 -2
- package/package.json +2 -1
- /package/lib/{rules → src/rules}/cognitive-complexity.d.ts +0 -0
- /package/lib/{rules → src/rules}/cognitive-complexity.js +0 -0
- /package/lib/{rules → src/rules}/elseif-without-else.d.ts +0 -0
- /package/lib/{rules → src/rules}/elseif-without-else.js +0 -0
- /package/lib/{rules → src/rules}/max-switch-cases.d.ts +0 -0
- /package/lib/{rules → src/rules}/max-switch-cases.js +0 -0
- /package/lib/{rules → src/rules}/no-all-duplicated-branches.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-all-duplicated-branches.js +0 -0
- /package/lib/{rules → src/rules}/no-collapsible-if.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-collapsible-if.js +0 -0
- /package/lib/{rules → src/rules}/no-collection-size-mischeck.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-collection-size-mischeck.js +0 -0
- /package/lib/{rules → src/rules}/no-duplicate-string.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-duplicate-string.js +0 -0
- /package/lib/{rules → src/rules}/no-duplicated-branches.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-duplicated-branches.js +0 -0
- /package/lib/{rules → src/rules}/no-element-overwrite.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-element-overwrite.js +0 -0
- /package/lib/{rules → src/rules}/no-empty-collection.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-empty-collection.js +0 -0
- /package/lib/{rules → src/rules}/no-extra-arguments.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-extra-arguments.js +0 -0
- /package/lib/{rules → src/rules}/no-gratuitous-expressions.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-gratuitous-expressions.js +0 -0
- /package/lib/{rules → src/rules}/no-identical-conditions.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-identical-conditions.js +0 -0
- /package/lib/{rules → src/rules}/no-identical-expressions.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-identical-expressions.js +0 -0
- /package/lib/{rules → src/rules}/no-identical-functions.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-identical-functions.js +0 -0
- /package/lib/{rules → src/rules}/no-ignored-return.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-ignored-return.js +0 -0
- /package/lib/{rules → src/rules}/no-inverted-boolean-check.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-inverted-boolean-check.js +0 -0
- /package/lib/{rules → src/rules}/no-nested-switch.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-nested-switch.js +0 -0
- /package/lib/{rules → src/rules}/no-nested-template-literals.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-nested-template-literals.js +0 -0
- /package/lib/{rules → src/rules}/no-one-iteration-loop.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-one-iteration-loop.js +0 -0
- /package/lib/{rules → src/rules}/no-redundant-boolean.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-redundant-boolean.js +0 -0
- /package/lib/{rules → src/rules}/no-redundant-jump.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-redundant-jump.js +0 -0
- /package/lib/{rules → src/rules}/no-same-line-conditional.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-same-line-conditional.js +0 -0
- /package/lib/{rules → src/rules}/no-small-switch.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-small-switch.js +0 -0
- /package/lib/{rules → src/rules}/no-unused-collection.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-unused-collection.js +0 -0
- /package/lib/{rules → src/rules}/no-use-of-empty-return-value.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-use-of-empty-return-value.js +0 -0
- /package/lib/{rules → src/rules}/no-useless-catch.d.ts +0 -0
- /package/lib/{rules → src/rules}/no-useless-catch.js +0 -0
- /package/lib/{rules → src/rules}/non-existent-operator.d.ts +0 -0
- /package/lib/{rules → src/rules}/non-existent-operator.js +0 -0
- /package/lib/{rules → src/rules}/prefer-immediate-return.d.ts +0 -0
- /package/lib/{rules → src/rules}/prefer-immediate-return.js +0 -0
- /package/lib/{rules → src/rules}/prefer-object-literal.d.ts +0 -0
- /package/lib/{rules → src/rules}/prefer-object-literal.js +0 -0
- /package/lib/{rules → src/rules}/prefer-single-boolean-return.d.ts +0 -0
- /package/lib/{rules → src/rules}/prefer-single-boolean-return.js +0 -0
- /package/lib/{rules → src/rules}/prefer-while.d.ts +0 -0
- /package/lib/{rules → src/rules}/prefer-while.js +0 -0
- /package/lib/{utils → src/utils}/collections.d.ts +0 -0
- /package/lib/{utils → src/utils}/collections.js +0 -0
- /package/lib/{utils → src/utils}/conditions.d.ts +0 -0
- /package/lib/{utils → src/utils}/conditions.js +0 -0
- /package/lib/{utils → src/utils}/docs-url.d.ts +0 -0
- /package/lib/{utils → src/utils}/docs-url.js +0 -0
- /package/lib/{utils → src/utils}/equivalence.d.ts +0 -0
- /package/lib/{utils → src/utils}/equivalence.js +0 -0
- /package/lib/{utils → src/utils}/index.d.ts +0 -0
- /package/lib/{utils → src/utils}/index.js +0 -0
- /package/lib/{utils → src/utils}/jsx.d.ts +0 -0
- /package/lib/{utils → src/utils}/jsx.js +0 -0
- /package/lib/{utils → src/utils}/locations.d.ts +0 -0
- /package/lib/{utils → src/utils}/locations.js +0 -0
- /package/lib/{utils → src/utils}/nodes.d.ts +0 -0
- /package/lib/{utils → src/utils}/nodes.js +0 -0
- /package/lib/{utils → src/utils}/parser-services.d.ts +0 -0
- /package/lib/{utils → src/utils}/parser-services.js +0 -0
- /package/lib/{utils → src/utils}/utils-ast.d.ts +0 -0
- /package/lib/{utils → src/utils}/utils-ast.js +0 -0
- /package/lib/{utils → src/utils}/utils-collection.d.ts +0 -0
- /package/lib/{utils → src/utils}/utils-collection.js +0 -0
- /package/lib/{utils → src/utils}/utils-parent.d.ts +0 -0
- /package/lib/{utils → src/utils}/utils-parent.js +0 -0
- /package/lib/{utils → src/utils}/utils-type.d.ts +0 -0
- /package/lib/{utils → src/utils}/utils-type.js +0 -0
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ Code Smells, or maintainability issues, are raised for places of code which migh
|
|
|
82
82
|
## Prerequisites
|
|
83
83
|
|
|
84
84
|
- Node.js (>=16.x).
|
|
85
|
-
- ESLint
|
|
85
|
+
- ESLint 8.x or 9.x (peer dependency for the plugin).
|
|
86
86
|
|
|
87
87
|
## Usage
|
|
88
88
|
|
|
@@ -94,25 +94,35 @@ npm install eslint-plugin-sonarjs --save-dev # install for your project
|
|
|
94
94
|
npm install eslint-plugin-sonarjs -g # or install globally
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
- Add `eslint-plugin-sonarjs` to the
|
|
97
|
+
- Add `eslint-plugin-sonarjs` to the plugins of your ESLint config.
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
For ESLint 9: add `plugins` option to your `eslint.config.js` and include the recommended config to enable all rules:
|
|
100
|
+
|
|
101
|
+
```code
|
|
102
|
+
import sonarjs from "eslint-plugin-sonarjs";
|
|
103
|
+
|
|
104
|
+
[
|
|
105
|
+
sonarjs.configs.recommended,
|
|
106
|
+
{
|
|
107
|
+
"plugins": {
|
|
108
|
+
sonarjs,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
]
|
|
103
112
|
```
|
|
104
113
|
|
|
105
|
-
|
|
114
|
+
For ESLint 8: add `plugins` option to your `.eslintrc` and `plugin:sonarjs/recommended` to the `extends` option to enable all recommended rules:
|
|
106
115
|
|
|
107
116
|
```json
|
|
108
117
|
{
|
|
109
|
-
"
|
|
118
|
+
"plugins": ["sonarjs"],
|
|
119
|
+
"extends": ["plugin:sonarjs/recommended-legacy"]
|
|
110
120
|
}
|
|
111
121
|
```
|
|
112
122
|
|
|
113
123
|
- or enable only some rules manually:
|
|
114
124
|
|
|
115
|
-
```
|
|
125
|
+
```json
|
|
116
126
|
{
|
|
117
127
|
"rules": {
|
|
118
128
|
"sonarjs/cognitive-complexity": "error",
|
|
@@ -122,11 +132,12 @@ npm install eslint-plugin-sonarjs -g # or install globally
|
|
|
122
132
|
}
|
|
123
133
|
```
|
|
124
134
|
|
|
125
|
-
- To
|
|
135
|
+
- To allow each of the rules to fully perform, use `@typescript-eslint/parser` as a parser for ESLint ([like we do](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/6e06d59a233e07b28fbbd6398e08b9b0c63b18f9/.eslintrc.js#L4)) and set the [parserOptions.project](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#parseroptionsproject) option. Thanks to it, type information is available, which is beneficial or even essential for some rules.
|
|
126
136
|
|
|
127
137
|
## Available Configurations
|
|
128
138
|
|
|
129
139
|
This plugin provides only a `recommended` configuration. Almost all rules are activated in this profile with a few exceptions (check the `disabled` tag in the rules list). The `recommended` configuration activates rules with `error` severity.
|
|
140
|
+
We include a `recommended-legacy` configuration to be backward compatible with ESLint v8, with the same rule configuration..
|
|
130
141
|
|
|
131
142
|
## ESLint and Sonar
|
|
132
143
|
|
package/lib/package.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-sonarjs",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "SonarJS rules for ESLint",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"repository": "git@github.com:SonarSource/eslint-plugin-sonarjs.git",
|
|
8
|
+
"license": "LGPL-3.0-only",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"sonarjs",
|
|
11
|
+
"eslint",
|
|
12
|
+
"eslintplugin"
|
|
13
|
+
],
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/SonarSource/eslint-plugin-sonarjs/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/SonarSource/eslint-plugin-sonarjs",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=16"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"lib",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "rimraf lib && tsc -d -p src",
|
|
27
|
+
"test": "jest",
|
|
28
|
+
"ruling": "ts-node --files ruling/index.ts",
|
|
29
|
+
"precommit": "pretty-quick --staged",
|
|
30
|
+
"prepare": "husky install .husky",
|
|
31
|
+
"prepack": "npm run build",
|
|
32
|
+
"format": "prettier --write .",
|
|
33
|
+
"check-format": "prettier --list-different ."
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"eslint": "^8.0.0 || ^9.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@babel/core": "7.24.4",
|
|
40
|
+
"@babel/eslint-parser": "7.24.1",
|
|
41
|
+
"@babel/plugin-proposal-export-default-from": "7.24.1",
|
|
42
|
+
"@babel/plugin-proposal-function-bind": "7.24.1",
|
|
43
|
+
"@babel/preset-env": "7.24.4",
|
|
44
|
+
"@babel/preset-flow": "7.24.1",
|
|
45
|
+
"@babel/preset-react": "7.24.1",
|
|
46
|
+
"@types/eslint": "8.56.10",
|
|
47
|
+
"@types/eslint-ruling": "npm:@types/eslint@^8.56.10",
|
|
48
|
+
"@types/jest": "29.5.12",
|
|
49
|
+
"@types/lodash": "4.17.0",
|
|
50
|
+
"@types/minimist": "1.2.5",
|
|
51
|
+
"@types/node": "20.12.7",
|
|
52
|
+
"@typescript-eslint/parser": "7.7.1",
|
|
53
|
+
"@typescript-eslint/rule-tester": "7.7.1",
|
|
54
|
+
"@typescript-eslint/utils": "7.7.1",
|
|
55
|
+
"eslint": "8.57.0",
|
|
56
|
+
"eslint-config-prettier": "9.1.0",
|
|
57
|
+
"eslint-plugin-import": "2.29.1",
|
|
58
|
+
"eslint-plugin-notice": "0.9.10",
|
|
59
|
+
"eslint-plugin-sonarjs": "0.25.1",
|
|
60
|
+
"eslint-ruling": "npm:eslint@8.57.0",
|
|
61
|
+
"husky": "9.0.11",
|
|
62
|
+
"jest": "29.7.0",
|
|
63
|
+
"jest-sonar-reporter": "2.0.0",
|
|
64
|
+
"lodash": "4.17.21",
|
|
65
|
+
"minimist": "1.2.8",
|
|
66
|
+
"prettier": "3.2.5",
|
|
67
|
+
"pretty-quick": "4.0.0",
|
|
68
|
+
"rimraf": "5.0.5",
|
|
69
|
+
"semver": "^7.6.0",
|
|
70
|
+
"ts-jest": "29.1.2",
|
|
71
|
+
"ts-node": "10.9.2",
|
|
72
|
+
"typescript": "5.4.5"
|
|
73
|
+
},
|
|
74
|
+
"prettier": {
|
|
75
|
+
"printWidth": 100,
|
|
76
|
+
"trailingComma": "all",
|
|
77
|
+
"singleQuote": true,
|
|
78
|
+
"arrowParens": "avoid",
|
|
79
|
+
"endOfLine": "lf"
|
|
80
|
+
},
|
|
81
|
+
"jest": {
|
|
82
|
+
"roots": [
|
|
83
|
+
"tests",
|
|
84
|
+
"src"
|
|
85
|
+
],
|
|
86
|
+
"collectCoverageFrom": [
|
|
87
|
+
"src/**/*.ts"
|
|
88
|
+
],
|
|
89
|
+
"moduleFileExtensions": [
|
|
90
|
+
"ts",
|
|
91
|
+
"js",
|
|
92
|
+
"json"
|
|
93
|
+
],
|
|
94
|
+
"transform": {
|
|
95
|
+
"^.+\\.ts$": [
|
|
96
|
+
"ts-jest",
|
|
97
|
+
{
|
|
98
|
+
"babelConfig": false
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
"testMatch": [
|
|
103
|
+
"<rootDir>/tests/**/*.test.ts"
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -44,6 +44,10 @@ export declare const configs: {
|
|
|
44
44
|
recommended: FlatConfig.Config;
|
|
45
45
|
'recommended-legacy': TSESLint.ClassicConfig.Config;
|
|
46
46
|
};
|
|
47
|
+
export declare const meta: {
|
|
48
|
+
name: string;
|
|
49
|
+
version: string;
|
|
50
|
+
};
|
|
47
51
|
declare const _default: {
|
|
48
52
|
rules: {
|
|
49
53
|
'cognitive-complexity': TSESLint.RuleModule<string, (number | "sonar-runtime" | "metric")[], TSESLint.RuleListener>;
|
|
@@ -89,5 +93,9 @@ declare const _default: {
|
|
|
89
93
|
recommended: FlatConfig.Config;
|
|
90
94
|
'recommended-legacy': TSESLint.ClassicConfig.Config;
|
|
91
95
|
};
|
|
96
|
+
meta: {
|
|
97
|
+
name: string;
|
|
98
|
+
version: string;
|
|
99
|
+
};
|
|
92
100
|
};
|
|
93
101
|
export default _default;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.configs = exports.rules = void 0;
|
|
26
|
+
exports.meta = exports.configs = exports.rules = void 0;
|
|
27
27
|
const cognitiveComplexity = __importStar(require("./rules/cognitive-complexity"));
|
|
28
28
|
const elseifWithoutElse = __importStar(require("./rules/elseif-without-else"));
|
|
29
29
|
const maxSwitchCases = __importStar(require("./rules/max-switch-cases"));
|
|
@@ -56,6 +56,7 @@ const preferImmediateReturn = __importStar(require("./rules/prefer-immediate-ret
|
|
|
56
56
|
const preferObjectLiteral = __importStar(require("./rules/prefer-object-literal"));
|
|
57
57
|
const preferSingleBooleanReturn = __importStar(require("./rules/prefer-single-boolean-return"));
|
|
58
58
|
const preferWhile = __importStar(require("./rules/prefer-while"));
|
|
59
|
+
const package_json_1 = require("../package.json");
|
|
59
60
|
exports.rules = {
|
|
60
61
|
'cognitive-complexity': cognitiveComplexity,
|
|
61
62
|
'elseif-without-else': elseifWithoutElse,
|
|
@@ -109,4 +110,8 @@ exports.configs = {
|
|
|
109
110
|
recommended: recommendedConfig,
|
|
110
111
|
'recommended-legacy': recommendedLegacyConfig,
|
|
111
112
|
};
|
|
112
|
-
exports.
|
|
113
|
+
exports.meta = {
|
|
114
|
+
name: package_json_1.name,
|
|
115
|
+
version: package_json_1.version,
|
|
116
|
+
};
|
|
117
|
+
exports.default = { rules: exports.rules, configs: exports.configs, meta: exports.meta };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-sonarjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "SonarJS rules for ESLint",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"prettier": "3.2.5",
|
|
67
67
|
"pretty-quick": "4.0.0",
|
|
68
68
|
"rimraf": "5.0.5",
|
|
69
|
+
"semver": "^7.6.0",
|
|
69
70
|
"ts-jest": "29.1.2",
|
|
70
71
|
"ts-node": "10.9.2",
|
|
71
72
|
"typescript": "5.4.5"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|