eslint-plugin-sonarjs 0.21.0 → 0.23.0
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/LICENSE +1 -1
- package/README.md +8 -8
- package/lib/rules/prefer-object-literal.js +12 -7
- package/lib/rules/prefer-object-literal.js.map +1 -1
- package/package.json +21 -21
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
2
|
Version 3, 29 June 2007
|
|
3
3
|
|
|
4
|
-
Copyright (C) 2007 Free Software Foundation, Inc. <
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
5
|
Everyone is permitted to copy and distribute verbatim copies
|
|
6
6
|
of this license document, but changing it is not allowed.
|
|
7
7
|
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# eslint-plugin-sonarjs [](https://badge.fury.io/js/eslint-plugin-sonarjs) [](https://cirrus-ci.com/github/SonarSource/eslint-plugin-sonarjs) [](https://sonarcloud.io/dashboard?id=eslint-plugin-sonarjs) [](https://sonarcloud.io/dashboard?id=eslint-plugin-sonarjs)
|
|
2
2
|
|
|
3
|
-
SonarJS rules for ESLint to
|
|
3
|
+
SonarJS rules for ESLint to help developers produce [Clean Code](https://www.sonarsource.com/solutions/clean-code/) by detecting bugs and suspicious patterns.
|
|
4
4
|
|
|
5
5
|
## Rules
|
|
6
6
|
|
|
7
7
|
### Bug Detection :bug:
|
|
8
8
|
|
|
9
|
-
Rules in this category aim to find places in code
|
|
9
|
+
Rules in this category aim to find places in code that have a high chance of being bugs, i.e. don't work as intended.
|
|
10
10
|
|
|
11
11
|
* All branches in a conditional structure should not have exactly the same implementation ([`no-all-duplicated-branches`])
|
|
12
12
|
* Collection elements should not be replaced unconditionally ([`no-element-overwrite`])
|
|
@@ -21,7 +21,7 @@ Rules in this category aim to find places in code which have a high chance of be
|
|
|
21
21
|
|
|
22
22
|
### Code Smell Detection :pig:
|
|
23
23
|
|
|
24
|
-
Code Smells, or maintainability issues, are raised for places of code which might be costly to change in the future. These rules also help to keep the high code quality and readability. And finally some rules report issues on different suspicious code
|
|
24
|
+
Code Smells, or maintainability issues, are raised for places of code which might be costly to change in the future. These rules also help to keep the high code quality and readability. And finally, some rules report issues on different suspicious code patterns.
|
|
25
25
|
|
|
26
26
|
* Cognitive Complexity of functions should not be too high ([`cognitive-complexity`])
|
|
27
27
|
* "if ... else if" constructs should end with "else" clauses ([`elseif-without-else`]) (*disabled*)
|
|
@@ -87,7 +87,7 @@ Code Smells, or maintainability issues, are raised for places of code which migh
|
|
|
87
87
|
## Usage
|
|
88
88
|
|
|
89
89
|
* If you don't have ESLint yet configured for your project, follow [these instructions](https://github.com/eslint/eslint#installation-and-usage).
|
|
90
|
-
* Install `eslint-plugin-sonarjs` using `npm` (or `yarn`) for
|
|
90
|
+
* Install `eslint-plugin-sonarjs` using `npm` (or `yarn`) for your project or globally:
|
|
91
91
|
|
|
92
92
|
```sh
|
|
93
93
|
npm install eslint-plugin-sonarjs --save-dev # install for your project
|
|
@@ -125,14 +125,14 @@ npm install eslint-plugin-sonarjs -g # or install globally
|
|
|
125
125
|
|
|
126
126
|
## Available Configurations
|
|
127
127
|
|
|
128
|
-
This plugin provides only `recommended` configuration. Almost all rules are activated in this profile with a few exceptions (check `disabled` tag in the rules list). `recommended` configuration activates rules with `error` severity.
|
|
128
|
+
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.
|
|
129
129
|
|
|
130
130
|
## ESLint and Sonar
|
|
131
131
|
|
|
132
|
-
This plugin exposes to ESLint users a subset of JS/TS rules from Sonar-* products (aka [SonarJS](https://github.com/SonarSource/SonarJS)). We extracted the rules
|
|
132
|
+
This plugin exposes to ESLint users a subset of JS/TS rules from Sonar-* products (aka [SonarJS](https://github.com/SonarSource/SonarJS)). We extracted the rules that are not available in ESLint core or other ESLint plugins to be beneficial for the ESLint community.
|
|
133
133
|
|
|
134
|
-
If you are a [SonarQube](https://www.sonarqube.org) or [SonarCloud](https://sonarcloud.io) user, to lint your code locally, we suggest
|
|
134
|
+
If you are a [SonarQube](https://www.sonarqube.org) or [SonarCloud](https://sonarcloud.io) user, to lint your code locally, we suggest using [SonarLint](https://www.sonarlint.org) IDE extension (available for VSCode, JetBrains IDEs and Eclipse). You can connect SonarLint to your SonarQube/SonarCloud project to synchronize rules configuration, issue statuses, etc.
|
|
135
135
|
|
|
136
136
|
## Contributing
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
Do you want to participate in the development of the project? Have a look at our [contributing](./docs/CONTRIBUTING.md) guide!
|
|
@@ -51,7 +51,8 @@ function checkObjectInitialization(statements, context) {
|
|
|
51
51
|
const objectDeclaration = getObjectDeclaration(statements[index]);
|
|
52
52
|
// eslint-disable-next-line sonarjs/no-collapsible-if
|
|
53
53
|
if (objectDeclaration && (0, nodes_1.isIdentifier)(objectDeclaration.id)) {
|
|
54
|
-
|
|
54
|
+
const nextStmt = statements[index + 1];
|
|
55
|
+
if (isPropertyAssignment(nextStmt, objectDeclaration.id, context.getSourceCode())) {
|
|
55
56
|
context.report({ messageId: 'declarePropertiesInsideObject', node: objectDeclaration });
|
|
56
57
|
}
|
|
57
58
|
}
|
|
@@ -73,15 +74,19 @@ function isPropertyAssignment(statement, objectIdentifier, sourceCode) {
|
|
|
73
74
|
if ((0, nodes_1.isMemberExpression)(left)) {
|
|
74
75
|
return (!left.computed &&
|
|
75
76
|
isSingleLineExpression(right, sourceCode) &&
|
|
76
|
-
(0, equivalence_1.areEquivalent)(left.object, objectIdentifier, sourceCode)
|
|
77
|
+
(0, equivalence_1.areEquivalent)(left.object, objectIdentifier, sourceCode) &&
|
|
78
|
+
!isCircularReference(left, right, sourceCode));
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
return false;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
function isSingleLineExpression(expression, sourceCode) {
|
|
83
|
+
const first = sourceCode.getFirstToken(expression).loc;
|
|
84
|
+
const last = sourceCode.getLastToken(expression).loc;
|
|
85
|
+
return first.start.line === last.end.line;
|
|
86
|
+
}
|
|
87
|
+
function isCircularReference(left, right, sourceCode) {
|
|
88
|
+
return (0, equivalence_1.areEquivalent)(left.object, right, sourceCode);
|
|
89
|
+
}
|
|
85
90
|
}
|
|
86
91
|
module.exports = rule;
|
|
87
92
|
//# sourceMappingURL=prefer-object-literal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-object-literal.js","sourceRoot":"","sources":["../../src/rules/prefer-object-literal.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,oDAAoD;AAGpD,0CAQwB;AACxB,sDAAqD;AACrD,gDAAwC;AAExC,MAAM,IAAI,GAA0C;IAClD,IAAI,EAAE;QACJ,QAAQ,EAAE;YACR,6BAA6B,EAC3B,yHAAyH;SAC5H;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,sCAAsC;YACnD,WAAW,EAAE,OAAO;YACpB,GAAG,EAAE,IAAA,kBAAO,EAAC,UAAU,CAAC;SACzB;KACF;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,cAAc,EAAE,CAAC,IAAmB,EAAE,EAAE,CACtC,yBAAyB,CAAE,IAAgC,CAAC,IAAI,EAAE,OAAO,CAAC;YAC5E,OAAO,EAAE,CAAC,IAAmB,EAAE,EAAE;gBAC/B,MAAM,UAAU,GAAI,IAAyB,CAAC,IAAI,CAAC,MAAM,CACvD,CAAC,SAAS,EAAmC,EAAE,CAAC,CAAC,IAAA,2BAAmB,EAAC,SAAS,CAAC,CAChF,CAAC;gBACF,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACjD,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,SAAS,yBAAyB,CAChC,UAAgC,EAChC,OAA+C;IAE/C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,KAAK,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACpC,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QAClE,qDAAqD;QACrD,IAAI,iBAAiB,IAAI,IAAA,oBAAY,EAAC,iBAAiB,CAAC,EAAE,CAAC,EAAE;YAC3D,
|
|
1
|
+
{"version":3,"file":"prefer-object-literal.js","sourceRoot":"","sources":["../../src/rules/prefer-object-literal.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,oDAAoD;AAGpD,0CAQwB;AACxB,sDAAqD;AACrD,gDAAwC;AAExC,MAAM,IAAI,GAA0C;IAClD,IAAI,EAAE;QACJ,QAAQ,EAAE;YACR,6BAA6B,EAC3B,yHAAyH;SAC5H;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,sCAAsC;YACnD,WAAW,EAAE,OAAO;YACpB,GAAG,EAAE,IAAA,kBAAO,EAAC,UAAU,CAAC;SACzB;KACF;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,cAAc,EAAE,CAAC,IAAmB,EAAE,EAAE,CACtC,yBAAyB,CAAE,IAAgC,CAAC,IAAI,EAAE,OAAO,CAAC;YAC5E,OAAO,EAAE,CAAC,IAAmB,EAAE,EAAE;gBAC/B,MAAM,UAAU,GAAI,IAAyB,CAAC,IAAI,CAAC,MAAM,CACvD,CAAC,SAAS,EAAmC,EAAE,CAAC,CAAC,IAAA,2BAAmB,EAAC,SAAS,CAAC,CAChF,CAAC;gBACF,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACjD,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AA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MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,UAAU,CAAC;QAC7C,IAAI,IAAA,0BAAkB,EAAC,IAAI,CAAC,EAAE;YAC5B,OAAO,CACL,CAAC,IAAI,CAAC,QAAQ;gBACd,sBAAsB,CAAC,KAAK,EAAE,UAAU,CAAC;gBACzC,IAAA,2BAAa,EAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,EAAE,UAAU,CAAC;gBACxD,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAC9C,CAAC;SACH;KACF;IACD,OAAO,KAAK,CAAC;IAEb,SAAS,sBAAsB,CAC7B,UAA+B,EAC/B,UAA+B;QAE/B,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,CAAC,UAAU,CAAE,CAAC,GAAG,CAAC;QACxD,MAAM,IAAI,GAAG,UAAU,CAAC,YAAY,CAAC,UAAU,CAAE,CAAC,GAAG,CAAC;QACtD,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IAC5C,CAAC;IAED,SAAS,mBAAmB,CAC1B,IAA+B,EAC/B,KAA0B,EAC1B,UAA+B;QAE/B,OAAO,IAAA,2BAAa,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;IACvD,CAAC;AACH,CAAC;AAED,iBAAS,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-sonarjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "SonarJS rules for ESLint",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"repository": "git@github.com:SonarSource/eslint-plugin-sonarjs.git",
|
|
8
|
-
"license": "LGPL-3.0",
|
|
8
|
+
"license": "LGPL-3.0-only",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"sonarjs",
|
|
11
11
|
"eslint",
|
|
@@ -33,33 +33,33 @@
|
|
|
33
33
|
"eslint": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@babel/core": "7.
|
|
37
|
-
"@babel/eslint-parser": "7.
|
|
38
|
-
"@babel/plugin-proposal-export-default-from": "
|
|
39
|
-
"@babel/plugin-proposal-function-bind": "
|
|
40
|
-
"@babel/preset-env": "7.
|
|
41
|
-
"@babel/preset-flow": "7.
|
|
42
|
-
"@babel/preset-react": "7.
|
|
43
|
-
"@types/eslint": "8.
|
|
44
|
-
"@types/jest": "
|
|
36
|
+
"@babel/core": "7.23.2",
|
|
37
|
+
"@babel/eslint-parser": "7.22.5",
|
|
38
|
+
"@babel/plugin-proposal-export-default-from": "7.18.9",
|
|
39
|
+
"@babel/plugin-proposal-function-bind": "7.18.9",
|
|
40
|
+
"@babel/preset-env": "7.23.2",
|
|
41
|
+
"@babel/preset-flow": "7.22.15",
|
|
42
|
+
"@babel/preset-react": "7.22.15",
|
|
43
|
+
"@types/eslint": "8.40.0",
|
|
44
|
+
"@types/jest": "29.5.2",
|
|
45
45
|
"@types/lodash": "4.14.182",
|
|
46
46
|
"@types/minimist": "1.2.2",
|
|
47
47
|
"@types/node": "14.14.31",
|
|
48
48
|
"@typescript-eslint/experimental-utils": "5.30.7",
|
|
49
49
|
"@typescript-eslint/parser": "5.30.7",
|
|
50
|
-
"eslint": "8.
|
|
50
|
+
"eslint": "8.47.0",
|
|
51
51
|
"eslint-config-prettier": "8.5.0",
|
|
52
52
|
"eslint-plugin-import": "2.26.0",
|
|
53
53
|
"eslint-plugin-notice": "0.9.10",
|
|
54
|
-
"eslint-plugin-sonarjs": "0.
|
|
55
|
-
"jest": "
|
|
54
|
+
"eslint-plugin-sonarjs": "0.22.0",
|
|
55
|
+
"jest": "29.5.0",
|
|
56
56
|
"jest-sonar-reporter": "2.0.0",
|
|
57
57
|
"lint-staged": "13.0.3",
|
|
58
58
|
"lodash": "4.17.21",
|
|
59
59
|
"minimist": "1.2.6",
|
|
60
60
|
"prettier": "2.7.1",
|
|
61
61
|
"rimraf": "3.0.2",
|
|
62
|
-
"ts-jest": "
|
|
62
|
+
"ts-jest": "29.1.1",
|
|
63
63
|
"ts-node": "10.9.1",
|
|
64
64
|
"typescript": "4.7.4"
|
|
65
65
|
},
|
|
@@ -78,18 +78,18 @@
|
|
|
78
78
|
"collectCoverageFrom": [
|
|
79
79
|
"src/**/*.ts"
|
|
80
80
|
],
|
|
81
|
-
"globals": {
|
|
82
|
-
"ts-jest": {
|
|
83
|
-
"babelConfig": false
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
81
|
"moduleFileExtensions": [
|
|
87
82
|
"ts",
|
|
88
83
|
"js",
|
|
89
84
|
"json"
|
|
90
85
|
],
|
|
91
86
|
"transform": {
|
|
92
|
-
"^.+\\.ts$":
|
|
87
|
+
"^.+\\.ts$": [
|
|
88
|
+
"ts-jest",
|
|
89
|
+
{
|
|
90
|
+
"babelConfig": false
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
93
|
},
|
|
94
94
|
"testMatch": [
|
|
95
95
|
"<rootDir>/tests/**/*.test.ts"
|