diff --git a/src/converters/lintConfigs/rules/ruleConverters.ts b/src/converters/lintConfigs/rules/ruleConverters.ts index 0b4286cc5..b87d77efa 100644 --- a/src/converters/lintConfigs/rules/ruleConverters.ts +++ b/src/converters/lintConfigs/rules/ruleConverters.ts @@ -55,7 +55,7 @@ import { convertNoDuplicateImports } from "./ruleConverters/no-duplicate-imports import { convertNoDuplicateSuper } from "./ruleConverters/no-duplicate-super"; import { convertNoDuplicateSwitchCase } from "./ruleConverters/no-duplicate-switch-case"; import { convertNoDuplicateVariable } from "./ruleConverters/no-duplicate-variable"; -import { convertNoDynamicDelete } from './ruleConverters/no-dynamic-delete'; +import { convertNoDynamicDelete } from "./ruleConverters/no-dynamic-delete"; import { convertNoEmpty } from "./ruleConverters/no-empty"; import { convertNoEmptyInterface } from "./ruleConverters/no-empty-interface"; import { convertNoEmptyLineAfterOpeningBrace } from "./ruleConverters/no-empty-line-after-opening-brace"; @@ -232,6 +232,45 @@ import { convertNoUnboundMethods } from "./ruleConverters/eslint-plugin-rxjs/no- import { convertNoUnsafeSubjectNext } from "./ruleConverters/eslint-plugin-rxjs/no-unsafe-subject-next"; import { convertNoUnsafeTakeUntil } from "./ruleConverters/eslint-plugin-rxjs/no-unsafe-takeuntil"; +// eslint-plugin-sonarjs converters +import { convertCognitiveComplexity } from "./ruleConverters/eslint-plugin-sonarjs/cognitive-complexity"; +import { convertConsecutiveOverloads } from "./ruleConverters/eslint-plugin-sonarjs/consecutive-overloads"; +import { convertMaxSwitchCases } from "./ruleConverters/eslint-plugin-sonarjs/max-switch-cases"; +import { convertNoAllDuplicatedBranches } from "./ruleConverters/eslint-plugin-sonarjs/no-all-duplicated-branches"; +import { convertNoAlphabeticalSort } from "./ruleConverters/eslint-plugin-sonarjs/no-alphabetical-sort"; +import { convertNoBigFunction } from "./ruleConverters/eslint-plugin-sonarjs/no-big-function"; +import { convertNoCollapsibleIf } from "./ruleConverters/eslint-plugin-sonarjs/no-collapsible-if"; +import { convertNoCollectionSizeMischeck } from "./ruleConverters/eslint-plugin-sonarjs/no-collection-size-mischeck"; +import { convertNoDuplicateString } from "./ruleConverters/eslint-plugin-sonarjs/no-duplicate-string"; +import { convertNoDuplicatedBranches } from "./ruleConverters/eslint-plugin-sonarjs/no-duplicated-branches"; +import { convertNoElementOverwrite } from "./ruleConverters/eslint-plugin-sonarjs/no-element-overwrite"; +import { convertNoEmptyDestructuring } from "./ruleConverters/eslint-plugin-sonarjs/no-empty-destructuring"; +import { convertNoEmptyNestedBlocks } from "./ruleConverters/eslint-plugin-sonarjs/no-empty-nested-blocks"; +import { convertNoExtraSemicolon } from "./ruleConverters/eslint-plugin-sonarjs/no-extra-semicolon"; +import { convertNoIdenticalConditions } from "./ruleConverters/eslint-plugin-sonarjs/no-identical-conditions"; +import { convertNoIdenticalExpressions } from "./ruleConverters/eslint-plugin-sonarjs/no-identical-expressions"; +import { convertNoIdenticalFunctions } from "./ruleConverters/eslint-plugin-sonarjs/no-identical-functions"; +import { convertNoInMisuse } from "./ruleConverters/eslint-plugin-sonarjs/no-in-misuse"; +import { convertNoInvalidAwait } from "./ruleConverters/eslint-plugin-sonarjs/no-invalid-await"; +import { convertNoInvertedBooleanCheck } from "./ruleConverters/eslint-plugin-sonarjs/no-inverted-boolean-check"; +import { convertNoMultilineStringLiterals } from "./ruleConverters/eslint-plugin-sonarjs/no-multiline-string-literals"; +import { convertNoRedundantBoolean } from "./ruleConverters/eslint-plugin-sonarjs/no-redundant-boolean"; +import { convertNoRedundantJump } from "./ruleConverters/eslint-plugin-sonarjs/no-redundant-jump"; +import { convertNoRedundantParentheses } from "./ruleConverters/eslint-plugin-sonarjs/no-redundant-parentheses"; +import { convertNoSameLineConditional } from "./ruleConverters/eslint-plugin-sonarjs/no-same-line-conditional"; +import { convertNoSelfAssignment } from "./ruleConverters/eslint-plugin-sonarjs/no-self-assignment"; +import { convertNoSmallSwitch } from "./ruleConverters/eslint-plugin-sonarjs/no-small-switch"; +import { convertNoUnconditionalJump } from "./ruleConverters/eslint-plugin-sonarjs/no-unconditional-jump"; +import { convertNoUnusedArray } from "./ruleConverters/eslint-plugin-sonarjs/no-unused-array"; +import { convertNoUseOfEmptyReturnValue } from "./ruleConverters/eslint-plugin-sonarjs/no-use-of-empty-return-value"; +import { convertNoUselessCast } from "./ruleConverters/eslint-plugin-sonarjs/no-useless-cast"; +import { convertNoUselessCatch } from "./ruleConverters/eslint-plugin-sonarjs/no-useless-catch"; +import { convertNoVariableUsageBeforeDeclaration } from "./ruleConverters/eslint-plugin-sonarjs/no-variable-usage-before-declaration"; +import { convertParametersMaxNumber } from "./ruleConverters/eslint-plugin-sonarjs/parameters-max-number"; +import { convertPreferDefaultLast } from "./ruleConverters/eslint-plugin-sonarjs/prefer-default-last"; +import { convertPreferImmediateReturn } from "./ruleConverters/eslint-plugin-sonarjs/prefer-immediate-return"; +import { convertUsePrimitiveType } from "./ruleConverters/eslint-plugin-sonarjs/use-primitive-type"; + /** * Keys TSLint rule names to their ESLint rule converters. */ @@ -248,10 +287,12 @@ export const ruleConverters = new Map([ ["binary-expression-operand-order", convertBinaryExpressionOperandOrder], ["callable-types", convertCallableTypes], ["class-name", convertClassName], + ["cognitive-complexity", convertCognitiveComplexity], ["comment-format", convertCommentFormat], ["component-class-suffix", convertComponentClassSuffix], ["component-max-inline-declarations", convertComponentMaxInlineDeclarations], ["component-selector", convertComponentSelector], + ["consecutive-overloads", convertConsecutiveOverloads], ["contextual-lifecycle", convertContextualLifecycle], ["contextual-decorator", convertContextualDecorator], ["curly", convertCurly], @@ -285,20 +326,26 @@ export const ruleConverters = new Map([ ["max-func-body-length", convertMaxFuncBodyLength], ["max-file-line-count", convertMaxFileLineCount], ["max-line-length", convertMaxLineLength], + ["max-switch-cases", convertMaxSwitchCases], ["member-access", convertMemberAccess], ["member-ordering", convertMemberOrdering], ["mocha-avoid-only", convertMochaAvoidOnly], ["new-parens", convertNewParens], ["newline-before-return", convertNewlineBeforeReturn], ["newline-per-chained-call", convertNewlinePerChainedCall], + ["no-all-duplicated-branches", convertNoAllDuplicatedBranches], + ["no-alphabetical-sort", convertNoAlphabeticalSort], ["no-angle-bracket-type-assertion", convertNoAngleBracketTypeAssertion], ["no-any", convertNoExplicitAny], ["no-arg", convertNoArg], ["no-async-without-await", convertNoAsyncWithoutAwait], ["no-attribute-decorator", convertNoAttributeDecorator], ["no-banned-terms", convertNoBannedTerms], + ["no-big-function", convertNoBigFunction], ["no-bitwise", convertNoBitwise], ["no-boolean-literal-compare", convertNoBooleanLiteralCompare], + ["no-collapsible-if", convertNoCollapsibleIf], + ["no-collection-size-mischeck", convertNoCollectionSizeMischeck], ["no-conditional-assignment", convertNoConditionalAssignment], ["no-conflicting-lifecycle", convertNoConflictingLifecycle], ["no-consecutive-blank-lines", convertNoConsecutiveBlankLines], @@ -310,34 +357,47 @@ export const ruleConverters = new Map([ ["no-default-export", convertNoDefaultExport], ["no-delete-expression", convertNoDeleteExpression], ["no-duplicate-imports", convertNoDuplicateImports], + ["no-duplicate-string", convertNoDuplicateString], ["no-duplicate-super", convertNoDuplicateSuper], ["no-duplicate-switch-case", convertNoDuplicateSwitchCase], ["no-duplicate-variable", convertNoDuplicateVariable], + ["no-duplicated-branches", convertNoDuplicatedBranches], ["no-dynamic-delete", convertNoDynamicDelete], + ["no-element-overwrite", convertNoElementOverwrite], + ["no-empty-destructuring", convertNoEmptyDestructuring], ["no-empty-interface", convertNoEmptyInterface], ["no-empty-line-after-opening-brace", convertNoEmptyLineAfterOpeningBrace], // padded-blocks + ["no-empty-nested-blocks", convertNoEmptyNestedBlocks], ["no-empty", convertNoEmpty], ["no-eval", convertNoEval], + ["no-extra-semicolon", convertNoExtraSemicolon], ["no-floating-promises", convertNoFloatingPromises], ["no-for-in-array", convertNoForInArray], ["no-for-in", convertNoForIn], ["no-forward-ref", convertNoForwardRef], ["no-host-metadata-property", convertNoHostMetadataProperty], + ["no-identical-conditions", convertNoIdenticalConditions], + ["no-identical-expressions", convertNoIdenticalExpressions], + ["no-identical-functions", convertNoIdenticalFunctions], ["no-implicit-dependencies", convertNoImplicitDependencies], ["no-import-side-effect", convertNoImportSideEffect], + ["no-in-misuse", convertNoInMisuse], ["no-inferrable-types", convertNoInferrableTypes], ["no-input-prefix", convertNoInputPrefix], ["no-input-rename", convertNoInputRename], ["no-inputs-metadata-property", convertNoInputsMetadataProperty], ["no-internal-module", convertNoInternalModule], + ["no-invalid-await", convertNoInvalidAwait], ["no-invalid-regexp", convertNoInvalidRegexp], ["no-invalid-template-strings", convertNoInvalidTemplateStrings], ["no-invalid-this", convertNoInvalidThis], + ["no-inverted-boolean-check", convertNoInvertedBooleanCheck], ["no-irregular-whitespace", convertNoIrregularWhitespace], ["no-lifecycle-call", convertNoLifecycleCall], ["no-magic-numbers", convertNoMagicNumbers], ["no-misused-new", convertNoMisusedNew], ["no-multiline-string", convertNoMultilineString], + ["no-multiline-string-literals", convertNoMultilineStringLiterals], ["no-namespace", convertNoNamespace], ["no-non-null-assertion", convertNoNonNullAssertion], ["no-null-keyword", convertNoNullKeyword], @@ -352,13 +412,19 @@ export const ruleConverters = new Map([ ["no-parameter-reassignment", convertNoParameterReassignment], ["no-pipe-impure", convertNoPipeImpure], ["no-queries-metadata-property", convertNoQueriesMetadataProperty], + ["no-redundant-boolean", convertNoRedundantBoolean], + ["no-redundant-jump", convertNoRedundantJump], ["no-redundant-jsdoc", convertNoRedundantJsdoc], + ["no-redundant-parentheses", convertNoRedundantParentheses], ["no-reference-import", convertNoReferenceImport], ["no-reference", convertNoReference], ["no-regex-spaces", convertNoRegexSpaces], ["no-require-imports", convertNoRequireImports], ["no-return-await", convertNoReturnAwait], + ["no-same-line-conditional", convertNoSameLineConditional], + ["no-self-assignment", convertNoSelfAssignment], ["no-shadowed-variable", convertNoShadowedVariable], + ["no-small-switch", convertNoSmallSwitch], ["no-sparse-arrays", convertNoSparseArrays], ["no-string-literal", convertNoStringLiteral], ["no-string-throw", convertNoStringThrow], @@ -368,17 +434,23 @@ export const ruleConverters = new Map([ ["no-this-assignment", convertNoThisAssignment], ["no-trailing-whitespace", convertNoTrailingWhitespace], ["no-unbound-method", convertNoUnboundMethod], + ["no-unconditional-jump", convertNoUnconditionalJump], ["no-unnecessary-class", convertNoUnnecessaryClass], ["no-unnecessary-initializer", convertNoUnnecessaryInitializer], ["no-unnecessary-qualifier", convertNoUnnecessaryQualifier], ["no-unnecessary-semicolons", convertNoUnnecessarySemicolons], ["no-unnecessary-type-assertion", convertNoUnnecessaryTypeAssertion], + ["no-unused-array", convertNoUnusedArray], ["no-unsafe-finally", convertNoUnsafeFinally], ["no-unused-expression", convertNoUnusedExpression], ["no-unused-variable", convertNoUnusedVariable], ["no-use-before-declare", convertNoUseBeforeDeclare], + ["no-use-of-empty-return-value", convertNoUseOfEmptyReturnValue], + ["no-useless-cast", convertNoUselessCast], + ["no-useless-catch", convertNoUselessCatch], ["no-var-keyword", convertNoVarKeyword], ["no-var-requires", convertNoVarRequires], + ["no-variable-usage-before-declaration", convertNoVariableUsageBeforeDeclaration], ["no-void-expression", convertNoVoidExpression], ["no-with-statement", convertNoWithStatement], ["object-literal-key-quotes", convertObjectLiteralKeyQuotes], @@ -387,12 +459,15 @@ export const ruleConverters = new Map([ ["one-variable-per-declaration", convertOneVariablePerDeclaration], ["only-arrow-functions", convertOnlyArrowFunctions], ["ordered-imports", convertOrderedImports], + ["parameters-max-number", convertParametersMaxNumber], ["pipe-prefix", convertPipePrefix], ["prefer-array-literal", convertPreferArrayLiteral], ["prefer-conditional-expression", convertPreferConditionalExpression], ["prefer-const", convertPreferConst], + ["prefer-default-last", convertPreferDefaultLast], ["prefer-for-of", convertPreferForOf], ["prefer-function-over-method", convertPreferFunctionOverMethod], + ["prefer-immediate-return", convertPreferImmediateReturn], ["prefer-object-spread", convertPreferObjectSpread], ["prefer-on-push-component-change-detection", convertPreferOnPushComponentChangeDetection], ["prefer-output-readonly", convertPreferOutputReadonly], @@ -444,6 +519,7 @@ export const ruleConverters = new Map([ ["use-lifecycle-interface", convertUseLifecycleInterface], ["use-pipe-decorator", convertUsePipeDecorator], ["use-pipe-transform-interface", convertUsePipeTransformInterface], + ["use-primitive-type", convertUsePrimitiveType], ["variable-name", convertVariableName], ["rxjs-no-async-subscribe", convertNoAsyncSubscribe], ["rxjs-no-implicit-any-catch", convertNoImplicitAnyCatch], diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/cognitive-complexity.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/cognitive-complexity.ts new file mode 100644 index 000000000..59dd318d1 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/cognitive-complexity.ts @@ -0,0 +1,15 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertCognitiveComplexity: RuleConverter = (tslintRule) => { + return { + rules: [ + { + ...(tslintRule.ruleArguments.length !== 0 && { + ruleArguments: tslintRule.ruleArguments, + }), + ruleName: "sonarjs/cognitive-complexity", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/consecutive-overloads.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/consecutive-overloads.ts new file mode 100644 index 000000000..e274822d5 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/consecutive-overloads.ts @@ -0,0 +1,11 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertConsecutiveOverloads: RuleConverter = () => { + return { + rules: [ + { + ruleName: "@typescript-eslint/adjacent-overload-signatures", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/max-switch-cases.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/max-switch-cases.ts new file mode 100644 index 000000000..143f8e429 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/max-switch-cases.ts @@ -0,0 +1,15 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertMaxSwitchCases: RuleConverter = (tslintRule) => { + return { + rules: [ + { + ...(tslintRule.ruleArguments.length !== 0 && { + ruleArguments: tslintRule.ruleArguments, + }), + ruleName: "sonarjs/max-switch-cases", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-all-duplicated-branches.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-all-duplicated-branches.ts new file mode 100644 index 000000000..85dc7c51f --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-all-duplicated-branches.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoAllDuplicatedBranches: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-all-duplicated-branches", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-alphabetical-sort.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-alphabetical-sort.ts new file mode 100644 index 000000000..6c778d5db --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-alphabetical-sort.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoAlphabeticalSort: RuleConverter = () => { + return { + rules: [ + { + ruleArguments: [{ ignoreStringArrays: true }], + ruleName: "@typescript-eslint/require-array-sort-compare", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-big-function.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-big-function.ts new file mode 100644 index 000000000..7b4fc6c8a --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-big-function.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoBigFunction: RuleConverter = (tslintRule) => { + return { + rules: [ + { + ruleArguments: [{ max: tslintRule.ruleArguments[0] ?? 200 }], + ruleName: "max-lines-per-function", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-collapsible-if.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-collapsible-if.ts new file mode 100644 index 000000000..b5c505418 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-collapsible-if.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoCollapsibleIf: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-collapsible-if", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-collection-size-mischeck.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-collection-size-mischeck.ts new file mode 100644 index 000000000..001a0c480 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-collection-size-mischeck.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoCollectionSizeMischeck: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-collection-size-mischeck", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-duplicate-string.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-duplicate-string.ts new file mode 100644 index 000000000..586352665 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-duplicate-string.ts @@ -0,0 +1,15 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoDuplicateString: RuleConverter = (tslintRule) => { + return { + rules: [ + { + ...(tslintRule.ruleArguments.length !== 0 && { + ruleArguments: tslintRule.ruleArguments, + }), + ruleName: "sonarjs/no-duplicate-string", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-duplicated-branches.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-duplicated-branches.ts new file mode 100644 index 000000000..d2331afe8 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-duplicated-branches.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoDuplicatedBranches: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-duplicated-branches", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-element-overwrite.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-element-overwrite.ts new file mode 100644 index 000000000..f22805889 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-element-overwrite.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoElementOverwrite: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-element-overwrite", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-empty-destructuring.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-empty-destructuring.ts new file mode 100644 index 000000000..f1f1f5f8e --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-empty-destructuring.ts @@ -0,0 +1,11 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoEmptyDestructuring: RuleConverter = () => { + return { + rules: [ + { + ruleName: "no-empty-pattern", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-empty-nested-blocks.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-empty-nested-blocks.ts new file mode 100644 index 000000000..709f37265 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-empty-nested-blocks.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoEmptyNestedBlocks: RuleConverter = () => { + return { + rules: [ + { + ruleArguments: [{ allowEmptyCatch: true }], + ruleName: "no-empty", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-extra-semicolon.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-extra-semicolon.ts new file mode 100644 index 000000000..c04cee51e --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-extra-semicolon.ts @@ -0,0 +1,15 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoExtraSemicolon: RuleConverter = () => { + return { + rules: [ + { + ruleName: "no-extra-semi", + ruleSeverity: "off", + }, + { + ruleName: "@typescript-eslint/no-extra-semi", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-identical-conditions.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-identical-conditions.ts new file mode 100644 index 000000000..fcf383aa8 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-identical-conditions.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoIdenticalConditions: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-identical-conditions", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-identical-expressions.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-identical-expressions.ts new file mode 100644 index 000000000..335f1f9f8 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-identical-expressions.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoIdenticalExpressions: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-identical-expressions", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-identical-functions.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-identical-functions.ts new file mode 100644 index 000000000..5af139bfc --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-identical-functions.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoIdenticalFunctions: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-identical-functions", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-in-misuse.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-in-misuse.ts new file mode 100644 index 000000000..03cfe22dd --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-in-misuse.ts @@ -0,0 +1,11 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoInMisuse: RuleConverter = () => { + return { + rules: [ + { + ruleName: "@typescript-eslint/no-for-in-array", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-invalid-await.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-invalid-await.ts new file mode 100644 index 000000000..c0cf6e03b --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-invalid-await.ts @@ -0,0 +1,11 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoInvalidAwait: RuleConverter = () => { + return { + rules: [ + { + ruleName: "@typescript-eslint/await-thenable", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-inverted-boolean-check.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-inverted-boolean-check.ts new file mode 100644 index 000000000..eaab49f79 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-inverted-boolean-check.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoInvertedBooleanCheck: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-inverted-boolean-check", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-multiline-string-literals.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-multiline-string-literals.ts new file mode 100644 index 000000000..70f267960 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-multiline-string-literals.ts @@ -0,0 +1,11 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoMultilineStringLiterals: RuleConverter = () => { + return { + rules: [ + { + ruleName: "no-multi-str", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-redundant-boolean.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-redundant-boolean.ts new file mode 100644 index 000000000..13718cd73 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-redundant-boolean.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoRedundantBoolean: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-redundant-boolean", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-redundant-jump.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-redundant-jump.ts new file mode 100644 index 000000000..23b16b5f1 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-redundant-jump.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoRedundantJump: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-redundant-jump", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-redundant-parentheses.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-redundant-parentheses.ts new file mode 100644 index 000000000..a04c2c5c9 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-redundant-parentheses.ts @@ -0,0 +1,11 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoRedundantParentheses: RuleConverter = () => { + return { + rules: [ + { + ruleName: "no-extra-parens", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-same-line-conditional.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-same-line-conditional.ts new file mode 100644 index 000000000..d465729e3 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-same-line-conditional.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoSameLineConditional: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-same-line-conditional", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-self-assignment.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-self-assignment.ts new file mode 100644 index 000000000..ca7ab9608 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-self-assignment.ts @@ -0,0 +1,11 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoSelfAssignment: RuleConverter = () => { + return { + rules: [ + { + ruleName: "no-self-assign", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-small-switch.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-small-switch.ts new file mode 100644 index 000000000..818b3f674 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-small-switch.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoSmallSwitch: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-small-switch", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-unconditional-jump.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-unconditional-jump.ts new file mode 100644 index 000000000..091430cc8 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-unconditional-jump.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoUnconditionalJump: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-one-iteration-loop", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-unused-array.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-unused-array.ts new file mode 100644 index 000000000..b67b4a6d1 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-unused-array.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoUnusedArray: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-unused-collection", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-use-of-empty-return-value.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-use-of-empty-return-value.ts new file mode 100644 index 000000000..c8ef1fb4d --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-use-of-empty-return-value.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoUseOfEmptyReturnValue: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-use-of-empty-return-value", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-useless-cast.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-useless-cast.ts new file mode 100644 index 000000000..343aeaa99 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-useless-cast.ts @@ -0,0 +1,11 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoUselessCast: RuleConverter = () => { + return { + rules: [ + { + ruleName: "@typescript-eslint/no-unnecessary-type-assertion", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-useless-catch.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-useless-catch.ts new file mode 100644 index 000000000..b07b49e82 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-useless-catch.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoUselessCatch: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/no-useless-catch", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-variable-usage-before-declaration.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-variable-usage-before-declaration.ts new file mode 100644 index 000000000..39791f736 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/no-variable-usage-before-declaration.ts @@ -0,0 +1,16 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertNoVariableUsageBeforeDeclaration: RuleConverter = () => { + return { + rules: [ + { + ruleName: "no-use-before-define", + ruleSeverity: "off", + }, + { + ruleArguments: [{ variables: true }], + ruleName: "@typescript-eslint/no-use-before-define", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/parameters-max-number.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/parameters-max-number.ts new file mode 100644 index 000000000..5389f0786 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/parameters-max-number.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertParametersMaxNumber: RuleConverter = (tslintRule) => { + return { + rules: [ + { + ruleArguments: [{ max: tslintRule.ruleArguments[0] ?? 7 }], + ruleName: "max-params", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/prefer-default-last.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/prefer-default-last.ts new file mode 100644 index 000000000..e13b7ee56 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/prefer-default-last.ts @@ -0,0 +1,11 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertPreferDefaultLast: RuleConverter = () => { + return { + rules: [ + { + ruleName: "default-case-last", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/prefer-immediate-return.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/prefer-immediate-return.ts new file mode 100644 index 000000000..6fce05b4a --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/prefer-immediate-return.ts @@ -0,0 +1,12 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertPreferImmediateReturn: RuleConverter = () => { + return { + rules: [ + { + ruleName: "sonarjs/prefer-immediate-return", + }, + ], + plugins: ["sonarjs"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/cognitive-complexity.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/cognitive-complexity.test.ts new file mode 100644 index 000000000..c2e852b42 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/cognitive-complexity.test.ts @@ -0,0 +1,34 @@ +import { convertCognitiveComplexity } from "../cognitive-complexity"; + +describe(convertCognitiveComplexity, () => { + test("conversion without arguments", () => { + const result = convertCognitiveComplexity({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/cognitive-complexity", + }, + ], + plugins: ["sonarjs"], + }); + }); + + test("conversion with maximum argument", () => { + const result = convertCognitiveComplexity({ + ruleArguments: [10], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [10], + ruleName: "sonarjs/cognitive-complexity", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/consecutive-overloads.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/consecutive-overloads.test.ts new file mode 100644 index 000000000..b8bae51aa --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/consecutive-overloads.test.ts @@ -0,0 +1,17 @@ +import { convertConsecutiveOverloads } from "../consecutive-overloads"; + +describe(convertConsecutiveOverloads, () => { + test("conversion without arguments", () => { + const result = convertConsecutiveOverloads({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "@typescript-eslint/adjacent-overload-signatures", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/max-switch-cases.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/max-switch-cases.test.ts new file mode 100644 index 000000000..3e3efa84e --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/max-switch-cases.test.ts @@ -0,0 +1,34 @@ +import { convertMaxSwitchCases } from "../max-switch-cases"; + +describe(convertMaxSwitchCases, () => { + test("conversion without arguments", () => { + const result = convertMaxSwitchCases({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/max-switch-cases", + }, + ], + plugins: ["sonarjs"], + }); + }); + + test("conversion with maximum argument", () => { + const result = convertMaxSwitchCases({ + ruleArguments: [10], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [10], + ruleName: "sonarjs/max-switch-cases", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-all-duplicated-branches.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-all-duplicated-branches.test.ts new file mode 100644 index 000000000..9d32db508 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-all-duplicated-branches.test.ts @@ -0,0 +1,18 @@ +import { convertNoAllDuplicatedBranches } from "../no-all-duplicated-branches"; + +describe(convertNoAllDuplicatedBranches, () => { + test("conversion without arguments", () => { + const result = convertNoAllDuplicatedBranches({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-all-duplicated-branches", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-alphabetical-sort.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-alphabetical-sort.test.ts new file mode 100644 index 000000000..645e902eb --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-alphabetical-sort.test.ts @@ -0,0 +1,18 @@ +import { convertNoAlphabeticalSort } from "../no-alphabetical-sort"; + +describe(convertNoAlphabeticalSort, () => { + test("conversion without arguments", () => { + const result = convertNoAlphabeticalSort({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [{ ignoreStringArrays: true }], + ruleName: "@typescript-eslint/require-array-sort-compare", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-big-function.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-big-function.test.ts new file mode 100644 index 000000000..969b4187b --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-big-function.test.ts @@ -0,0 +1,33 @@ +import { convertNoBigFunction } from "../no-big-function"; + +describe(convertNoBigFunction, () => { + test("conversion without arguments", () => { + const result = convertNoBigFunction({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [{ max: 200 }], + ruleName: "max-lines-per-function", + }, + ], + }); + }); + + test("conversion with maximum argument", () => { + const result = convertNoBigFunction({ + ruleArguments: [100], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [{ max: 100 }], + ruleName: "max-lines-per-function", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-collapsible-if.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-collapsible-if.test.ts new file mode 100644 index 000000000..14989b848 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-collapsible-if.test.ts @@ -0,0 +1,18 @@ +import { convertNoCollapsibleIf } from "../no-collapsible-if"; + +describe(convertNoCollapsibleIf, () => { + test("conversion without arguments", () => { + const result = convertNoCollapsibleIf({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-collapsible-if", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-collection-size-mischeck.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-collection-size-mischeck.test.ts new file mode 100644 index 000000000..fadc6f0a7 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-collection-size-mischeck.test.ts @@ -0,0 +1,18 @@ +import { convertNoCollectionSizeMischeck } from "../no-collection-size-mischeck"; + +describe(convertNoCollectionSizeMischeck, () => { + test("conversion without arguments", () => { + const result = convertNoCollectionSizeMischeck({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-collection-size-mischeck", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-duplicate-string.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-duplicate-string.test.ts new file mode 100644 index 000000000..50e158394 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-duplicate-string.test.ts @@ -0,0 +1,34 @@ +import { convertNoDuplicateString } from "../no-duplicate-string"; + +describe(convertNoDuplicateString, () => { + test("conversion without arguments", () => { + const result = convertNoDuplicateString({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-duplicate-string", + }, + ], + plugins: ["sonarjs"], + }); + }); + + test("conversion with maximum argument", () => { + const result = convertNoDuplicateString({ + ruleArguments: [5], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [5], + ruleName: "sonarjs/no-duplicate-string", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-duplicated-branches.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-duplicated-branches.test.ts new file mode 100644 index 000000000..d5c587829 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-duplicated-branches.test.ts @@ -0,0 +1,18 @@ +import { convertNoDuplicatedBranches } from "../no-duplicated-branches"; + +describe(convertNoDuplicatedBranches, () => { + test("conversion without arguments", () => { + const result = convertNoDuplicatedBranches({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-duplicated-branches", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-element-overwrite.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-element-overwrite.test.ts new file mode 100644 index 000000000..1b565b211 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-element-overwrite.test.ts @@ -0,0 +1,18 @@ +import { convertNoElementOverwrite } from "../no-element-overwrite"; + +describe(convertNoElementOverwrite, () => { + test("conversion without arguments", () => { + const result = convertNoElementOverwrite({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-element-overwrite", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-empty-destructuring.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-empty-destructuring.test.ts new file mode 100644 index 000000000..374092416 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-empty-destructuring.test.ts @@ -0,0 +1,17 @@ +import { convertNoEmptyDestructuring } from "../no-empty-destructuring"; + +describe(convertNoEmptyDestructuring, () => { + test("conversion without arguments", () => { + const result = convertNoEmptyDestructuring({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-empty-pattern", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-empty-nested-blocks.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-empty-nested-blocks.test.ts new file mode 100644 index 000000000..33a9747b9 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-empty-nested-blocks.test.ts @@ -0,0 +1,18 @@ +import { convertNoEmptyNestedBlocks } from "../no-empty-nested-blocks"; + +describe(convertNoEmptyNestedBlocks, () => { + test("conversion without arguments", () => { + const result = convertNoEmptyNestedBlocks({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [{ allowEmptyCatch: true }], + ruleName: "no-empty", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-extra-semicolon.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-extra-semicolon.test.ts new file mode 100644 index 000000000..21449ad66 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-extra-semicolon.test.ts @@ -0,0 +1,21 @@ +import { convertNoExtraSemicolon } from "../no-extra-semicolon"; + +describe(convertNoExtraSemicolon, () => { + test("conversion without arguments", () => { + const result = convertNoExtraSemicolon({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-extra-semi", + ruleSeverity: "off", + }, + { + ruleName: "@typescript-eslint/no-extra-semi", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-identical-conditions.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-identical-conditions.test.ts new file mode 100644 index 000000000..6010d1ba6 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-identical-conditions.test.ts @@ -0,0 +1,18 @@ +import { convertNoIdenticalConditions } from "../no-identical-conditions"; + +describe(convertNoIdenticalConditions, () => { + test("conversion without arguments", () => { + const result = convertNoIdenticalConditions({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-identical-conditions", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-identical-expressions.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-identical-expressions.test.ts new file mode 100644 index 000000000..6995d6c58 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-identical-expressions.test.ts @@ -0,0 +1,18 @@ +import { convertNoIdenticalExpressions } from "../no-identical-expressions"; + +describe(convertNoIdenticalExpressions, () => { + test("conversion without arguments", () => { + const result = convertNoIdenticalExpressions({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-identical-expressions", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-identical-functions.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-identical-functions.test.ts new file mode 100644 index 000000000..29856a3d5 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-identical-functions.test.ts @@ -0,0 +1,18 @@ +import { convertNoIdenticalFunctions } from "../no-identical-functions"; + +describe(convertNoIdenticalFunctions, () => { + test("conversion without arguments", () => { + const result = convertNoIdenticalFunctions({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-identical-functions", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-in-misuse.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-in-misuse.test.ts new file mode 100644 index 000000000..22b2286cf --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-in-misuse.test.ts @@ -0,0 +1,17 @@ +import { convertNoInMisuse } from "../no-in-misuse"; + +describe(convertNoInMisuse, () => { + test("conversion without arguments", () => { + const result = convertNoInMisuse({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "@typescript-eslint/no-for-in-array", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-invalid-await.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-invalid-await.test.ts new file mode 100644 index 000000000..e82bd202e --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-invalid-await.test.ts @@ -0,0 +1,17 @@ +import { convertNoInvalidAwait } from "../no-invalid-await"; + +describe(convertNoInvalidAwait, () => { + test("conversion without arguments", () => { + const result = convertNoInvalidAwait({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "@typescript-eslint/await-thenable", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-inverted-boolean-check.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-inverted-boolean-check.test.ts new file mode 100644 index 000000000..e21c4f5b2 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-inverted-boolean-check.test.ts @@ -0,0 +1,18 @@ +import { convertNoInvertedBooleanCheck } from "../no-inverted-boolean-check"; + +describe(convertNoInvertedBooleanCheck, () => { + test("conversion without arguments", () => { + const result = convertNoInvertedBooleanCheck({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-inverted-boolean-check", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-multiline-string-literals.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-multiline-string-literals.test.ts new file mode 100644 index 000000000..ce3967d6b --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-multiline-string-literals.test.ts @@ -0,0 +1,17 @@ +import { convertNoMultilineStringLiterals } from "../no-multiline-string-literals"; + +describe(convertNoMultilineStringLiterals, () => { + test("conversion without arguments", () => { + const result = convertNoMultilineStringLiterals({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-multi-str", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-redundant-boolean.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-redundant-boolean.test.ts new file mode 100644 index 000000000..68196a2a7 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-redundant-boolean.test.ts @@ -0,0 +1,18 @@ +import { convertNoRedundantBoolean } from "../no-redundant-boolean"; + +describe(convertNoRedundantBoolean, () => { + test("conversion without arguments", () => { + const result = convertNoRedundantBoolean({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-redundant-boolean", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-redundant-jump.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-redundant-jump.test.ts new file mode 100644 index 000000000..012749666 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-redundant-jump.test.ts @@ -0,0 +1,18 @@ +import { convertNoRedundantJump } from "../no-redundant-jump"; + +describe(convertNoRedundantJump, () => { + test("conversion without arguments", () => { + const result = convertNoRedundantJump({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-redundant-jump", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-redundant-parentheses.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-redundant-parentheses.test.ts new file mode 100644 index 000000000..e81604592 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-redundant-parentheses.test.ts @@ -0,0 +1,17 @@ +import { convertNoRedundantParentheses } from "../no-redundant-parentheses"; + +describe(convertNoRedundantParentheses, () => { + test("conversion without arguments", () => { + const result = convertNoRedundantParentheses({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-extra-parens", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-same-line-conditional.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-same-line-conditional.test.ts new file mode 100644 index 000000000..b3953a797 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-same-line-conditional.test.ts @@ -0,0 +1,18 @@ +import { convertNoSameLineConditional } from "../no-same-line-conditional"; + +describe(convertNoSameLineConditional, () => { + test("conversion without arguments", () => { + const result = convertNoSameLineConditional({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-same-line-conditional", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-self-assignment.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-self-assignment.test.ts new file mode 100644 index 000000000..007331740 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-self-assignment.test.ts @@ -0,0 +1,17 @@ +import { convertNoSelfAssignment } from "../no-self-assignment"; + +describe(convertNoSelfAssignment, () => { + test("conversion without arguments", () => { + const result = convertNoSelfAssignment({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-self-assign", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-small-switch.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-small-switch.test.ts new file mode 100644 index 000000000..67604b301 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-small-switch.test.ts @@ -0,0 +1,18 @@ +import { convertNoSmallSwitch } from "../no-small-switch"; + +describe(convertNoSmallSwitch, () => { + test("conversion without arguments", () => { + const result = convertNoSmallSwitch({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-small-switch", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-unconditional-jump.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-unconditional-jump.test.ts new file mode 100644 index 000000000..e03a293ee --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-unconditional-jump.test.ts @@ -0,0 +1,18 @@ +import { convertNoUnconditionalJump } from "../no-unconditional-jump"; + +describe(convertNoUnconditionalJump, () => { + test("conversion without arguments", () => { + const result = convertNoUnconditionalJump({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-one-iteration-loop", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-unused-array.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-unused-array.test.ts new file mode 100644 index 000000000..45279f872 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-unused-array.test.ts @@ -0,0 +1,18 @@ +import { convertNoUnusedArray } from "../no-unused-array"; + +describe(convertNoUnusedArray, () => { + test("conversion without arguments", () => { + const result = convertNoUnusedArray({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-unused-collection", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-use-of-empty-return-value.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-use-of-empty-return-value.test.ts new file mode 100644 index 000000000..87f016e03 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-use-of-empty-return-value.test.ts @@ -0,0 +1,18 @@ +import { convertNoUseOfEmptyReturnValue } from "../no-use-of-empty-return-value"; + +describe(convertNoUseOfEmptyReturnValue, () => { + test("conversion without arguments", () => { + const result = convertNoUseOfEmptyReturnValue({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-use-of-empty-return-value", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-useless-cast.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-useless-cast.test.ts new file mode 100644 index 000000000..9502e8c5d --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-useless-cast.test.ts @@ -0,0 +1,17 @@ +import { convertNoUselessCast } from "../no-useless-cast"; + +describe(convertNoUselessCast, () => { + test("conversion without arguments", () => { + const result = convertNoUselessCast({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "@typescript-eslint/no-unnecessary-type-assertion", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-useless-catch.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-useless-catch.test.ts new file mode 100644 index 000000000..07188e438 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-useless-catch.test.ts @@ -0,0 +1,18 @@ +import { convertNoUselessCatch } from "../no-useless-catch"; + +describe(convertNoUselessCatch, () => { + test("conversion without arguments", () => { + const result = convertNoUselessCatch({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/no-useless-catch", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-variable-usage-before-declaration.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-variable-usage-before-declaration.test.ts new file mode 100644 index 000000000..3a0d994a7 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/no-variable-usage-before-declaration.test.ts @@ -0,0 +1,22 @@ +import { convertNoVariableUsageBeforeDeclaration } from "../no-variable-usage-before-declaration"; + +describe(convertNoVariableUsageBeforeDeclaration, () => { + test("conversion without arguments", () => { + const result = convertNoVariableUsageBeforeDeclaration({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-use-before-define", + ruleSeverity: "off", + }, + { + ruleArguments: [{ variables: true }], + ruleName: "@typescript-eslint/no-use-before-define", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/parameters-max-number.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/parameters-max-number.test.ts new file mode 100644 index 000000000..29737f4b3 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/parameters-max-number.test.ts @@ -0,0 +1,33 @@ +import { convertParametersMaxNumber } from "../parameters-max-number"; + +describe(convertParametersMaxNumber, () => { + test("conversion without arguments", () => { + const result = convertParametersMaxNumber({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [{ max: 7 }], + ruleName: "max-params", + }, + ], + }); + }); + + test("conversion with maximum argument", () => { + const result = convertParametersMaxNumber({ + ruleArguments: [10], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [{ max: 10 }], + ruleName: "max-params", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/prefer-default-last.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/prefer-default-last.test.ts new file mode 100644 index 000000000..12fff710c --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/prefer-default-last.test.ts @@ -0,0 +1,17 @@ +import { convertPreferDefaultLast } from "../prefer-default-last"; + +describe(convertPreferDefaultLast, () => { + test("conversion without arguments", () => { + const result = convertPreferDefaultLast({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "default-case-last", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/prefer-immediate-return.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/prefer-immediate-return.test.ts new file mode 100644 index 000000000..ce394a5bd --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/prefer-immediate-return.test.ts @@ -0,0 +1,18 @@ +import { convertPreferImmediateReturn } from "../prefer-immediate-return"; + +describe(convertPreferImmediateReturn, () => { + test("conversion without arguments", () => { + const result = convertPreferImmediateReturn({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "sonarjs/prefer-immediate-return", + }, + ], + plugins: ["sonarjs"], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/use-primitive-type.test.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/use-primitive-type.test.ts new file mode 100644 index 000000000..98c7f29af --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/tests/use-primitive-type.test.ts @@ -0,0 +1,38 @@ +import { convertUsePrimitiveType } from "../use-primitive-type"; + +describe(convertUsePrimitiveType, () => { + test("conversion without arguments", () => { + const result = convertUsePrimitiveType({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-new-wrappers", + }, + { + ruleArguments: [ + { + types: { + String: { + message: "Use string instead", + fixWith: "string", + }, + Boolean: { + message: "Use boolean instead", + fixWith: "boolean", + }, + Number: { + message: "Use number instead", + fixWith: "number", + }, + }, + }, + ], + ruleName: "@typescript-eslint/ban-types", + }, + ], + }); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/use-primitive-type.ts b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/use-primitive-type.ts new file mode 100644 index 000000000..10a8eb4f5 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/eslint-plugin-sonarjs/use-primitive-type.ts @@ -0,0 +1,32 @@ +import { RuleConverter } from "../../ruleConverter"; + +export const convertUsePrimitiveType: RuleConverter = () => { + return { + rules: [ + { + ruleName: "no-new-wrappers", + }, + { + ruleArguments: [ + { + types: { + String: { + message: "Use string instead", + fixWith: "string", + }, + Boolean: { + message: "Use boolean instead", + fixWith: "boolean", + }, + Number: { + message: "Use number instead", + fixWith: "number", + }, + }, + }, + ], + ruleName: "@typescript-eslint/ban-types", + }, + ], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleMergers.ts b/src/converters/lintConfigs/rules/ruleMergers.ts index 92c957ba4..ce6fd5f26 100644 --- a/src/converters/lintConfigs/rules/ruleMergers.ts +++ b/src/converters/lintConfigs/rules/ruleMergers.ts @@ -2,10 +2,12 @@ import { mergeBanTypes } from "./ruleMergers/ban-types"; import { mergeConsistentTypeAssertions } from "./ruleMergers/consistent-type-assertions"; import { mergeIndent } from "./ruleMergers/indent"; import { mergeNamingConvention } from "./ruleMergers/naming-convention"; +import { mergeNoEmpty } from "./ruleMergers/no-empty"; import { mergeNoEval } from "./ruleMergers/no-eval"; import { mergeNoMemberDelimiterStyle } from "./ruleMergers/member-delimiter-style"; import { mergeNoUnnecessaryTypeAssertion } from "./ruleMergers/no-unnecessary-type-assertion"; import { mergeTripleSlashReference } from "./ruleMergers/triple-slash-reference"; +import { mergeNoUseBeforeDefine } from "./ruleMergers/no-use-before-define"; export const ruleMergers = new Map([ ["@typescript-eslint/ban-types", mergeBanTypes], @@ -13,7 +15,9 @@ export const ruleMergers = new Map([ ["@typescript-eslint/indent", mergeIndent], ["@typescript-eslint/member-delimiter-style", mergeNoMemberDelimiterStyle], ["@typescript-eslint/naming-convention", mergeNamingConvention], + ["@typescript-eslint/no-use-before-define", mergeNoUseBeforeDefine], ["@typescript-eslint/no-unnecessary-type-assertion", mergeNoUnnecessaryTypeAssertion], ["@typescript-eslint/triple-slash-reference", mergeTripleSlashReference], + ["no-empty", mergeNoEmpty], ["no-eval", mergeNoEval], ]); diff --git a/src/converters/lintConfigs/rules/ruleMergers/no-empty.ts b/src/converters/lintConfigs/rules/ruleMergers/no-empty.ts new file mode 100644 index 000000000..3b07deb3f --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleMergers/no-empty.ts @@ -0,0 +1,23 @@ +import { RuleMerger } from "../ruleMerger"; + +/** + * https://eslint.org/docs/rules/no-empty arguments merger. + * + * The only (and optional) option is `{ allowEmptyCatch: boolean }` which defaults to `{ allowEmptyCatch: false }`. + * + * Since the `false` case is stricter this sould only set `{ allowEmptyCatch: true }` when both inputs enable it. + */ +export const mergeNoEmpty: RuleMerger = (existingOptions, newOptions) => { + if ( + existingOptions === undefined || + newOptions === undefined || + existingOptions.length === 0 || + newOptions.length === 0 || + !existingOptions[0].allowEmptyCatch || + !newOptions[0].allowEmptyCatch + ) { + return []; + } + + return [{ allowEmptyCatch: true }]; +}; diff --git a/src/converters/lintConfigs/rules/ruleMergers/no-use-before-define.ts b/src/converters/lintConfigs/rules/ruleMergers/no-use-before-define.ts new file mode 100644 index 000000000..c532292cd --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleMergers/no-use-before-define.ts @@ -0,0 +1,49 @@ +import { assignWith, isObject } from "lodash"; +import { RuleMerger } from "../ruleMerger"; + +const NO_USE_BEFORE_DEFINE_DEFAULT_OPTS = { + classes: true, + enums: true, + functions: true, + ignoreTypeReferences: true, + typedefs: true, + variables: true, +}; + +export const mergeNoUseBeforeDefine: RuleMerger = (existingOptions, newOptions) => { + const existingSingleOption = existingOptions?.[0]; + const newSingleOption = newOptions?.[0]; + + if (existingSingleOption === undefined && newSingleOption === undefined) { + return []; + } + + // when not explicitly opting out with a flag assume that the option is requesting at least that flag + if ( + (existingSingleOption === undefined && isOnlyTrueFlags(newSingleOption)) || + (newSingleOption === undefined && isOnlyTrueFlags(existingSingleOption)) + ) { + return []; + } + + return [ + assignWith( + {}, + NO_USE_BEFORE_DEFINE_DEFAULT_OPTS, + existingSingleOption, + newSingleOption, + (currentValue, newValue) => { + if (currentValue === undefined) { + return newValue; + } + + // when merging the flags always keep the opted out (false) flags + return !!currentValue && !!newValue; + }, + ), + ]; +}; + +function isOnlyTrueFlags(flagsObject: unknown) { + return isObject(flagsObject) && Object.values(flagsObject).every((flag) => !!flag); +} diff --git a/src/converters/lintConfigs/rules/ruleMergers/tests/no-empty.test.ts b/src/converters/lintConfigs/rules/ruleMergers/tests/no-empty.test.ts new file mode 100644 index 000000000..63b8fa516 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleMergers/tests/no-empty.test.ts @@ -0,0 +1,45 @@ +import { mergeNoEmpty } from "../no-empty"; + +describe(mergeNoEmpty, () => { + test("neither options existing", () => { + const result = mergeNoEmpty(undefined, undefined); + + expect(result).toEqual([]); + }); + + test("neither allowEmptyCatch existing", () => { + const result = mergeNoEmpty([{}], [{}]); + + expect(result).toEqual([]); + }); + + test("original allowEmptyCatch existing", () => { + const result = mergeNoEmpty([{ allowEmptyCatch: true }], []); + + expect(result).toEqual([]); + }); + + test("new allowEmptyCatch existing", () => { + const result = mergeNoEmpty([], [{ allowEmptyCatch: true }]); + + expect(result).toEqual([]); + }); + + test("original allowEmptyCatch is false but new allowEmptyCatch is true", () => { + const result = mergeNoEmpty([{ allowEmptyCatch: false }], [{ allowEmptyCatch: true }]); + + expect(result).toEqual([]); + }); + + test("original allowEmptyCatch is true but new allowEmptyCatch is false", () => { + const result = mergeNoEmpty([{ allowEmptyCatch: true }], [{ allowEmptyCatch: false }]); + + expect(result).toEqual([]); + }); + + test("both allowEmptyCatch are true", () => { + const result = mergeNoEmpty([{ allowEmptyCatch: true }], [{ allowEmptyCatch: true }]); + + expect(result).toEqual([{ allowEmptyCatch: true }]); + }); +}); diff --git a/src/converters/lintConfigs/rules/ruleMergers/tests/no-use-before-define.test.ts b/src/converters/lintConfigs/rules/ruleMergers/tests/no-use-before-define.test.ts new file mode 100644 index 000000000..14cdff2c5 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleMergers/tests/no-use-before-define.test.ts @@ -0,0 +1,51 @@ +import { mergeNoUseBeforeDefine } from "../no-use-before-define"; + +describe(mergeNoUseBeforeDefine, () => { + test("neither options existing", () => { + const result = mergeNoUseBeforeDefine(undefined, undefined); + + expect(result).toEqual([]); + }); + + test("original only true flags", () => { + const result = mergeNoUseBeforeDefine([{ classes: true }], []); + + expect(result).toEqual([]); + }); + + test("new only true flags", () => { + const result = mergeNoUseBeforeDefine([], [{ classes: true }]); + + expect(result).toEqual([]); + }); + + test("original false flags", () => { + const result = mergeNoUseBeforeDefine([{ classes: false }], []); + + expect(result).toEqual([ + { + classes: false, + enums: true, + functions: true, + ignoreTypeReferences: true, + typedefs: true, + variables: true, + }, + ]); + }); + + test("new false flags", () => { + const result = mergeNoUseBeforeDefine([], [{ classes: false }]); + + expect(result).toEqual([ + { + classes: false, + enums: true, + functions: true, + ignoreTypeReferences: true, + typedefs: true, + variables: true, + }, + ]); + }); +});