File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed
src/converters/lintConfigs/rules Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ import { convertPreferForOf } from "./ruleConverters/prefer-for-of";
118118import { convertPreferFunctionOverMethod } from "./ruleConverters/prefer-function-over-method" ;
119119import { convertPreferObjectSpread } from "./ruleConverters/prefer-object-spread" ;
120120import { convertPreferReadonly } from "./ruleConverters/prefer-readonly" ;
121+ import { convertPreferSwitch } from "./ruleConverters/prefer-switch" ;
121122import { convertPreferTemplate } from "./ruleConverters/prefer-template" ;
122123import { convertPromiseFunctionAsync } from "./ruleConverters/promise-function-async" ;
123124import { 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 ] ,
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments