diff --git a/src/converters/lintConfigs/rules/ruleConverters.ts b/src/converters/lintConfigs/rules/ruleConverters.ts index ccdb8339e..948371768 100644 --- a/src/converters/lintConfigs/rules/ruleConverters.ts +++ b/src/converters/lintConfigs/rules/ruleConverters.ts @@ -116,6 +116,7 @@ import { convertPreferForOf } from "./ruleConverters/prefer-for-of"; import { convertPreferFunctionOverMethod } from "./ruleConverters/prefer-function-over-method"; import { convertPreferObjectSpread } from "./ruleConverters/prefer-object-spread"; import { convertPreferReadonly } from "./ruleConverters/prefer-readonly"; +import { convertPreferSwitch } from "./ruleConverters/prefer-switch"; import { convertPreferTemplate } from "./ruleConverters/prefer-template"; import { convertPromiseFunctionAsync } from "./ruleConverters/promise-function-async"; import { convertQuotemark } from "./ruleConverters/quotemark"; @@ -376,6 +377,7 @@ export const ruleConverters = new Map([ ["prefer-on-push-component-change-detection", convertPreferOnPushComponentChangeDetection], ["prefer-output-readonly", convertPreferOutputReadonly], ["prefer-readonly", convertPreferReadonly], + ["prefer-switch", convertPreferSwitch], ["prefer-template", convertPreferTemplate], ["promise-function-async", convertPromiseFunctionAsync], ["quotemark", convertQuotemark], diff --git a/src/converters/lintConfigs/rules/ruleConverters/prefer-switch.ts b/src/converters/lintConfigs/rules/ruleConverters/prefer-switch.ts new file mode 100644 index 000000000..8aa6f0179 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/prefer-switch.ts @@ -0,0 +1,16 @@ +import { RuleConverter } from "../ruleConverter"; + +export const convertPreferSwitch: RuleConverter = (tslintRule) => { + return { + rules: [ + { + ...(tslintRule.ruleArguments.length !== 0 && + "min-cases" in tslintRule.ruleArguments[0] && { + ruleArguments: [{ minimumCases: tslintRule.ruleArguments[0]["min-cases"] }], + }), + ruleName: "unicorn/prefer-switch", + }, + ], + plugins: ["eslint-plugin-unicorn"], + }; +}; diff --git a/src/converters/lintConfigs/rules/ruleConverters/tests/prefer-switch.test.ts b/src/converters/lintConfigs/rules/ruleConverters/tests/prefer-switch.test.ts new file mode 100644 index 000000000..73d6efe20 --- /dev/null +++ b/src/converters/lintConfigs/rules/ruleConverters/tests/prefer-switch.test.ts @@ -0,0 +1,34 @@ +import { convertPreferSwitch } from "../prefer-switch"; + +describe(convertPreferSwitch, () => { + test("conversion without arguments", () => { + const result = convertPreferSwitch({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "unicorn/prefer-switch", + }, + ], + plugins: ["eslint-plugin-unicorn"], + }); + }); + + test("conversion with 'min-cases' argument", () => { + const result = convertPreferSwitch({ + ruleArguments: [{ 'min-cases': 4 }], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [{ minimumCases: 4 }], + ruleName: "unicorn/prefer-switch", + }, + ], + plugins: ["eslint-plugin-unicorn"], + }); + }); +});