You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 3, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+43-42Lines changed: 43 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,43 +8,43 @@ SonarJS rules for ESLint to help developers produce [Clean Code](https://www.son
8
8
9
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
-
* All branches in a conditional structure should not have exactly the same implementation ([`no-all-duplicated-branches`])
12
-
* Collection elements should not be replaced unconditionally ([`no-element-overwrite`])
13
-
* Empty collections should not be accessed or iterated ([`no-empty-collection`])
14
-
* Function calls should not pass extra arguments ([`no-extra-arguments`])
15
-
* Related "if/else if" statements should not have the same condition ([`no-identical-conditions`])
16
-
* Identical expressions should not be used on both sides of a binary operator ([`no-identical-expressions`])
17
-
* Return values from functions without side effects should not be ignored ([`no-ignored-return`]) (*uses-types*)
18
-
* Loops with at most one iteration should be refactored ([`no-one-iteration-loop`])
19
-
* The output of functions that don't return anything should not be used ([`no-use-of-empty-return-value`])
20
-
* Non-existent operators '=+', '=-' and '=!' should not be used ([`non-existent-operator`]) (:wrench:*fixable*)
11
+
- All branches in a conditional structure should not have exactly the same implementation ([`no-all-duplicated-branches`])
12
+
- Collection elements should not be replaced unconditionally ([`no-element-overwrite`])
13
+
- Empty collections should not be accessed or iterated ([`no-empty-collection`])
14
+
- Function calls should not pass extra arguments ([`no-extra-arguments`])
15
+
- Related "if/else if" statements should not have the same condition ([`no-identical-conditions`])
16
+
- Identical expressions should not be used on both sides of a binary operator ([`no-identical-expressions`])
17
+
- Return values from functions without side effects should not be ignored ([`no-ignored-return`]) (_uses-types_)
18
+
- Loops with at most one iteration should be refactored ([`no-one-iteration-loop`])
19
+
- The output of functions that don't return anything should not be used ([`no-use-of-empty-return-value`])
20
+
- Non-existent operators '=+', '=-' and '=!' should not be used ([`non-existent-operator`]) (:wrench:_fixable_)
21
21
22
22
### Code Smell Detection :pig:
23
23
24
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
-
* Cognitive Complexity of functions should not be too high ([`cognitive-complexity`])
27
-
* "if ... else if" constructs should end with "else" clauses ([`elseif-without-else`]) (*disabled*)
28
-
* "switch" statements should not have too many "case" clauses ([`max-switch-cases`])
29
-
* Collapsible "if" statements should be merged ([`no-collapsible-if`])
30
-
* Collection sizes and array length comparisons should make sense ([`no-collection-size-mischeck`]) (:wrench:*fixable*, *uses-types*)
31
-
* String literals should not be duplicated ([`no-duplicate-string`])
32
-
* Two branches in a conditional structure should not have exactly the same implementation ([`no-duplicated-branches`])
33
-
* Boolean expressions should not be gratuitous ([`no-gratuitous-expressions`])
34
-
* Functions should not have identical implementations ([`no-identical-functions`])
35
-
* Boolean checks should not be inverted ([`no-inverted-boolean-check`]) (:wrench:*fixable*, *disabled*)
36
-
* "switch" statements should not be nested ([`no-nested-switch`])
37
-
* Template literals should not be nested ([`no-nested-template-literals`])
38
-
* Boolean literals should not be redundant ([`no-redundant-boolean`])
39
-
* Jump statements should not be redundant ([`no-redundant-jump`]) (:wrench:*fixable*)
40
-
* Conditionals should start on new lines ([`no-same-line-conditional`]) (:wrench:*fixable*)
41
-
* "switch" statements should have at least 3 "case" clauses ([`no-small-switch`])
42
-
* Collection and array contents should be used ([`no-unused-collection`])
43
-
* "catch" clauses should do more than rethrow ([`no-useless-catch`])
44
-
* Local variables should not be declared and then immediately returned or thrown ([`prefer-immediate-return`]) (:wrench:*fixable*)
45
-
* Object literal syntax should be used ([`prefer-object-literal`])
46
-
* Return of boolean expressions should not be wrapped into an "if-then-else" statement ([`prefer-single-boolean-return`]) (:wrench:*fixable*)
47
-
* A "while" loop should be used instead of a "for" loop ([`prefer-while`]) (:wrench:*fixable*)
26
+
- Cognitive Complexity of functions should not be too high ([`cognitive-complexity`])
27
+
- "if ... else if" constructs should end with "else" clauses ([`elseif-without-else`]) (_disabled_)
28
+
- "switch" statements should not have too many "case" clauses ([`max-switch-cases`])
29
+
- Collapsible "if" statements should be merged ([`no-collapsible-if`])
30
+
- Collection sizes and array length comparisons should make sense ([`no-collection-size-mischeck`]) (:wrench:_fixable_, _uses-types_)
31
+
- String literals should not be duplicated ([`no-duplicate-string`])
32
+
- Two branches in a conditional structure should not have exactly the same implementation ([`no-duplicated-branches`])
33
+
- Boolean expressions should not be gratuitous ([`no-gratuitous-expressions`])
34
+
- Functions should not have identical implementations ([`no-identical-functions`])
35
+
- Boolean checks should not be inverted ([`no-inverted-boolean-check`]) (:wrench:_fixable_, _disabled_)
36
+
- "switch" statements should not be nested ([`no-nested-switch`])
37
+
- Template literals should not be nested ([`no-nested-template-literals`])
38
+
- Boolean literals should not be redundant ([`no-redundant-boolean`])
39
+
- Jump statements should not be redundant ([`no-redundant-jump`]) (:wrench:_fixable_)
40
+
- Conditionals should start on new lines ([`no-same-line-conditional`]) (:wrench:_fixable_)
41
+
- "switch" statements should have at least 3 "case" clauses ([`no-small-switch`])
42
+
- Collection and array contents should be used ([`no-unused-collection`])
43
+
- "catch" clauses should do more than rethrow ([`no-useless-catch`])
44
+
- Local variables should not be declared and then immediately returned or thrown ([`prefer-immediate-return`]) (:wrench:_fixable_)
45
+
- Object literal syntax should be used ([`prefer-object-literal`])
46
+
- Return of boolean expressions should not be wrapped into an "if-then-else" statement ([`prefer-single-boolean-return`]) (:wrench:_fixable_)
47
+
- A "while" loop should be used instead of a "for" loop ([`prefer-while`]) (:wrench:_fixable_)
* To enable all rules of this plugin, 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.
124
+
125
+
- To enable all rules of this plugin, 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.
125
126
126
127
## Available Configurations
127
128
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
+
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
130
130
131
## ESLint and Sonar
131
132
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
+
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
134
134
135
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.
Copy file name to clipboardExpand all lines: docs/rules/no-collection-size-mischeck.md
+14-6Lines changed: 14 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,33 @@
1
1
# no-collection-size-mischeck
2
2
3
-
:wrench:*fixable*
3
+
:wrench:_fixable_
4
4
5
5
The size of a collection and the length of an array are always greater than or equal to zero. So testing that a size or length is greater than or equal to zero doesn't make sense, since the result is always `true`. Similarly testing that it is less than zero will always return `false`. Perhaps the intent was to check the non-emptiness of the collection or array instead.
0 commit comments