Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
eslint-plugin-sonarjs
(#161)
Co-authored-by: Julien <julien@ripouteau.com>
- Loading branch information
1 parent
423dbb7
commit 694223a
Showing
40 changed files
with
953 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Eslint Sonarjs extensions. | ||
* | ||
* @see [Eslint Sonarjs extensions](https://github.com/SonarSource/eslint-plugin-sonarjs#available-configurations) | ||
*/ | ||
export type SonarjsExtensions = 'plugin:sonarjs/recommended'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { RuleConfig } from '../rule-config'; | ||
|
||
/** | ||
* Config. | ||
*/ | ||
export type CognitiveComplexityConfig = 'sonar-runtime' | 'metric'; | ||
|
||
/** | ||
* Option. | ||
*/ | ||
export type CognitiveComplexityOption = number; | ||
|
||
/** | ||
* Options. | ||
*/ | ||
export type CognitiveComplexityOptions = [ | ||
CognitiveComplexityOption?, | ||
CognitiveComplexityConfig?, | ||
]; | ||
|
||
/** | ||
* Cognitive Complexity of functions should not be too high. | ||
* | ||
* @see [cognitive-complexity](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/cognitive-complexity.md) | ||
*/ | ||
export type CognitiveComplexityRuleConfig = | ||
RuleConfig<CognitiveComplexityOptions>; | ||
|
||
/** | ||
* Cognitive Complexity of functions should not be too high. | ||
* | ||
* @see [cognitive-complexity](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/cognitive-complexity.md) | ||
*/ | ||
export interface CognitiveComplexityRule { | ||
/** | ||
* Cognitive Complexity of functions should not be too high. | ||
* | ||
* @see [cognitive-complexity](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/cognitive-complexity.md) | ||
*/ | ||
'sonarjs/cognitive-complexity': CognitiveComplexityRuleConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { RuleConfig } from '../rule-config'; | ||
|
||
/** | ||
* "if ... else if" constructs should end with "else" clauses. | ||
* | ||
* @see [elseif-without-else](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/elseif-without-else.md) | ||
*/ | ||
export type ElseifWithoutElseRuleConfig = RuleConfig<[]>; | ||
|
||
/** | ||
* "if ... else if" constructs should end with "else" clauses. | ||
* | ||
* @see [elseif-without-else](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/elseif-without-else.md) | ||
*/ | ||
export interface ElseifWithoutElseRule { | ||
/** | ||
* "if ... else if" constructs should end with "else" clauses. | ||
* | ||
* @see [elseif-without-else](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/elseif-without-else.md) | ||
*/ | ||
'sonarjs/elseif-without-else': ElseifWithoutElseRuleConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { CognitiveComplexityRule } from './cognitive-complexity'; | ||
import type { ElseifWithoutElseRule } from './elseif-without-else'; | ||
import type { MaxSwitchCasesRule } from './max-switch-cases'; | ||
import type { NoAllDuplicatedBranchesRule } from './no-all-duplicated-branches'; | ||
import type { NoCollapsibleIfRule } from './no-collapsible-if'; | ||
import type { NoCollectionSizeMischeckRule } from './no-collection-size-mischeck'; | ||
import type { NoDuplicateStringRule } from './no-duplicate-string'; | ||
import type { NoDuplicatedBranchesRule } from './no-duplicated-branches'; | ||
import type { NoElementOverwriteRule } from './no-element-overwrite'; | ||
import type { NoEmptyCollectionRule } from './no-empty-collection'; | ||
import type { NoExtraArgumentsRule } from './no-extra-arguments'; | ||
import type { NoGratuitousExpressionsRule } from './no-gratuitous-expressions'; | ||
import type { NoIdenticalConditionsRule } from './no-identical-conditions'; | ||
import type { NoIdenticalExpressionsRule } from './no-identical-expressions'; | ||
import type { NoIdenticalFunctionsRule } from './no-identical-functions'; | ||
import type { NoIgnoredReturnRule } from './no-ignored-return'; | ||
import type { NoInvertedBooleanCheckRule } from './no-inverted-boolean-check'; | ||
import type { NoNestedSwitchRule } from './no-nested-switch'; | ||
import type { NoNestedTemplateLiteralsRule } from './no-nested-template-literals'; | ||
import type { NoOneIterationLoopRule } from './no-one-iteration-loop'; | ||
import type { NoRedundantBooleanRule } from './no-redundant-boolean'; | ||
import type { NoRedundantJumpRule } from './no-redundant-jump'; | ||
import type { NoSameLineConditionalRule } from './no-same-line-conditional'; | ||
import type { NoSmallSwitchRule } from './no-small-switch'; | ||
import type { NoUnusedCollectionRule } from './no-unused-collection'; | ||
import type { NoUseOfEmptyReturnValueRule } from './no-use-of-empty-return-value'; | ||
import type { NoUselessCatchRule } from './no-useless-catch'; | ||
import type { NonExistentOperatorRule } from './non-existent-operator'; | ||
import type { PreferImmediateReturnRule } from './prefer-immediate-return'; | ||
import type { PreferObjectLiteralRule } from './prefer-object-literal'; | ||
import type { PreferSingleBooleanReturnRule } from './prefer-single-boolean-return'; | ||
import type { PreferWhileRule } from './prefer-while'; | ||
|
||
/** | ||
* All SonarJS rules. | ||
*/ | ||
export type SonarJSRules = CognitiveComplexityRule & | ||
ElseifWithoutElseRule & | ||
MaxSwitchCasesRule & | ||
NoAllDuplicatedBranchesRule & | ||
NoCollapsibleIfRule & | ||
NoCollectionSizeMischeckRule & | ||
NoDuplicateStringRule & | ||
NoDuplicatedBranchesRule & | ||
NoElementOverwriteRule & | ||
NoEmptyCollectionRule & | ||
NoExtraArgumentsRule & | ||
NoGratuitousExpressionsRule & | ||
NoIdenticalConditionsRule & | ||
NoIdenticalExpressionsRule & | ||
NoIdenticalFunctionsRule & | ||
NoIgnoredReturnRule & | ||
NoInvertedBooleanCheckRule & | ||
NoNestedSwitchRule & | ||
NoNestedTemplateLiteralsRule & | ||
NoOneIterationLoopRule & | ||
NoRedundantBooleanRule & | ||
NoRedundantJumpRule & | ||
NoSameLineConditionalRule & | ||
NoSmallSwitchRule & | ||
NoUnusedCollectionRule & | ||
NoUseOfEmptyReturnValueRule & | ||
NoUselessCatchRule & | ||
NonExistentOperatorRule & | ||
PreferImmediateReturnRule & | ||
PreferObjectLiteralRule & | ||
PreferSingleBooleanReturnRule & | ||
PreferWhileRule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { RuleConfig } from '../rule-config'; | ||
|
||
/** | ||
* Option. | ||
*/ | ||
export type MaxSwitchCasesOption = number; | ||
|
||
/** | ||
* Options. | ||
*/ | ||
export type MaxSwitchCasesOptions = [MaxSwitchCasesOption?]; | ||
|
||
/** | ||
* "switch" statements should not have too many "case" clauses. | ||
* | ||
* @see [max-switch-cases](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/max-switch-cases.md) | ||
*/ | ||
export type MaxSwitchCasesRuleConfig = RuleConfig<MaxSwitchCasesOptions>; | ||
|
||
/** | ||
* "switch" statements should not have too many "case" clauses. | ||
* | ||
* @see [max-switch-cases](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/max-switch-cases.md) | ||
*/ | ||
export interface MaxSwitchCasesRule { | ||
/** | ||
* "switch" statements should not have too many "case" clauses. | ||
* | ||
* @see [max-switch-cases](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/max-switch-cases.md) | ||
*/ | ||
'sonarjs/max-switch-cases': MaxSwitchCasesRuleConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { RuleConfig } from '../rule-config'; | ||
|
||
/** | ||
* All branches in a conditional structure should not have exactly the same implementation. | ||
* | ||
* @see [no-all-duplicated-branches](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-all-duplicated-branches.md) | ||
*/ | ||
export type NoAllDuplicatedBranchesRuleConfig = RuleConfig<[]>; | ||
|
||
/** | ||
* All branches in a conditional structure should not have exactly the same implementation. | ||
* | ||
* @see [no-all-duplicated-branches](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-all-duplicated-branches.md) | ||
*/ | ||
export interface NoAllDuplicatedBranchesRule { | ||
/** | ||
* All branches in a conditional structure should not have exactly the same implementation. | ||
* | ||
* @see [no-all-duplicated-branches](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-all-duplicated-branches.md) | ||
*/ | ||
'sonarjs/no-all-duplicated-branches': NoAllDuplicatedBranchesRuleConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { RuleConfig } from '../rule-config'; | ||
|
||
/** | ||
* Option. | ||
*/ | ||
export type NoCollapsibleIfOption = 'sonar-runtime'; | ||
|
||
/** | ||
* Options. | ||
*/ | ||
export type NoCollapsibleIfOptions = [NoCollapsibleIfOption?]; | ||
|
||
/** | ||
* Collapsible "if" statements should be merged. | ||
* | ||
* @see [no-collapsible-if](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-collapsible-if.md) | ||
*/ | ||
export type NoCollapsibleIfRuleConfig = RuleConfig<NoCollapsibleIfOptions>; | ||
|
||
/** | ||
* Collapsible "if" statements should be merged. | ||
* | ||
* @see [no-collapsible-if](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-collapsible-if.md) | ||
*/ | ||
export interface NoCollapsibleIfRule { | ||
/** | ||
* Collapsible "if" statements should be merged. | ||
* | ||
* @see [no-collapsible-if](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-collapsible-if.md) | ||
*/ | ||
'sonarjs/no-collapsible-if': NoCollapsibleIfRuleConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { RuleConfig } from '../rule-config'; | ||
|
||
/** | ||
* Collection sizes and array length comparisons should make sense. | ||
* | ||
* @see [no-collection-size-mischeck](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-collection-size-mischeck.md) | ||
*/ | ||
export type NoCollectionSizeMischeckRuleConfig = RuleConfig<[]>; | ||
|
||
/** | ||
* Collection sizes and array length comparisons should make sense. | ||
* | ||
* @see [no-collection-size-mischeck](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-collection-size-mischeck.md) | ||
*/ | ||
export interface NoCollectionSizeMischeckRule { | ||
/** | ||
* Collection sizes and array length comparisons should make sense. | ||
* | ||
* @see [no-collection-size-mischeck](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-collection-size-mischeck.md) | ||
*/ | ||
'sonarjs/no-collection-size-mischeck': NoCollectionSizeMischeckRuleConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { RuleConfig } from '../rule-config'; | ||
|
||
/** | ||
* Config. | ||
*/ | ||
export type NoDuplicateStringConfig = 'sonar-runtime'; | ||
|
||
/** | ||
* Option. | ||
*/ | ||
export type NoDuplicateStringOption = number; | ||
|
||
/** | ||
* Options. | ||
*/ | ||
export type NoDuplicateStringOptions = [ | ||
NoDuplicateStringOption?, | ||
NoDuplicateStringConfig?, | ||
]; | ||
|
||
/** | ||
* String literals should not be duplicated. | ||
* | ||
* @see [no-duplicate-string](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-duplicate-string.md) | ||
*/ | ||
export type NoDuplicateStringRuleConfig = RuleConfig<NoDuplicateStringOptions>; | ||
|
||
/** | ||
* String literals should not be duplicated. | ||
* | ||
* @see [no-duplicate-string](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-duplicate-string.md) | ||
*/ | ||
export interface NoDuplicateStringRule { | ||
/** | ||
* String literals should not be duplicated. | ||
* | ||
* @see [no-duplicate-string](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/no-duplicate-string.md) | ||
*/ | ||
'sonarjs/no-duplicate-string': NoDuplicateStringRuleConfig; | ||
} |
Oops, something went wrong.