Skip to content

Commit da37e6e

Browse files
authored
Add prefer-switch converter (#1059)
1 parent cd7735f commit da37e6e

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/converters/lintConfigs/rules/ruleConverters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ import { convertPreferForOf } from "./ruleConverters/prefer-for-of";
118118
import { convertPreferFunctionOverMethod } from "./ruleConverters/prefer-function-over-method";
119119
import { convertPreferObjectSpread } from "./ruleConverters/prefer-object-spread";
120120
import { convertPreferReadonly } from "./ruleConverters/prefer-readonly";
121+
import { convertPreferSwitch } from "./ruleConverters/prefer-switch";
121122
import { convertPreferTemplate } from "./ruleConverters/prefer-template";
122123
import { convertPromiseFunctionAsync } from "./ruleConverters/promise-function-async";
123124
import { convertQuotemark } from "./ruleConverters/quotemark";
@@ -383,6 +384,7 @@ export const ruleConverters = new Map([
383384
["prefer-on-push-component-change-detection", convertPreferOnPushComponentChangeDetection],
384385
["prefer-output-readonly", convertPreferOutputReadonly],
385386
["prefer-readonly", convertPreferReadonly],
387+
["prefer-switch", convertPreferSwitch],
386388
["prefer-template", convertPreferTemplate],
387389
["promise-function-async", convertPromiseFunctionAsync],
388390
["quotemark", convertQuotemark],
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { RuleConverter } from "../ruleConverter";
2+
3+
export const convertPreferSwitch: RuleConverter = (tslintRule) => {
4+
return {
5+
rules: [
6+
{
7+
...(tslintRule.ruleArguments.length !== 0 &&
8+
"min-cases" in tslintRule.ruleArguments[0] && {
9+
ruleArguments: [{ minimumCases: tslintRule.ruleArguments[0]["min-cases"] }],
10+
}),
11+
ruleName: "unicorn/prefer-switch",
12+
},
13+
],
14+
plugins: ["eslint-plugin-unicorn"],
15+
};
16+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { convertPreferSwitch } from "../prefer-switch";
2+
3+
describe(convertPreferSwitch, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertPreferSwitch({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleName: "unicorn/prefer-switch",
13+
},
14+
],
15+
plugins: ["eslint-plugin-unicorn"],
16+
});
17+
});
18+
19+
test("conversion with 'min-cases' argument", () => {
20+
const result = convertPreferSwitch({
21+
ruleArguments: [{ 'min-cases': 4 }],
22+
});
23+
24+
expect(result).toEqual({
25+
rules: [
26+
{
27+
ruleArguments: [{ minimumCases: 4 }],
28+
ruleName: "unicorn/prefer-switch",
29+
},
30+
],
31+
plugins: ["eslint-plugin-unicorn"],
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)