From f48082abd7a667aba30a8db2516ebfeb25c114dd Mon Sep 17 00:00:00 2001 From: Boris Pallares Date: Wed, 2 Oct 2019 20:06:35 -0500 Subject: [PATCH 1/2] Adds no-for-in converter along with tests --- src/rules/converters.ts | 3 +- src/rules/converters/no-for-in.ts | 14 ++++ src/rules/converters/tests/no-for-in.test.ts | 67 ++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/rules/converters/no-for-in.ts create mode 100644 src/rules/converters/tests/no-for-in.test.ts diff --git a/src/rules/converters.ts b/src/rules/converters.ts index f1a6289b0..66a0d13fa 100644 --- a/src/rules/converters.ts +++ b/src/rules/converters.ts @@ -44,6 +44,7 @@ import { convertNoEmptyInterface } from "./converters/no-empty-interface"; import { convertNoEval } from "./converters/no-eval"; import { convertNoExplicitAny } from "./converters/no-explicit-any"; import { convertNoFloatingPromises } from "./converters/no-floating-promises"; +import { convertNoForIn } from "./converters/no-for-in"; import { convertNoForInArray } from "./converters/no-for-in-array"; import { convertNoInferrableTypes } from "./converters/no-inferrable-types"; import { convertNoInternalModule } from "./converters/no-internal-module"; @@ -137,6 +138,7 @@ export const converters = new Map([ ["no-empty-interface", convertNoEmptyInterface], ["no-eval", convertNoEval], ["no-floating-promises", convertNoFloatingPromises], + ["no-for-in", convertNoForIn], ["no-for-in-array", convertNoForInArray], ["no-inferrable-types", convertNoInferrableTypes], ["no-internal-module", convertNoInternalModule], @@ -229,7 +231,6 @@ export const converters = new Map([ // tslint-microsoft-contrib rules: // ["max-func-body-length", convertMaxFuncBodyLength], // ["no-empty-line-after-opening-brace", convertNoEmptyLineAfterOpeningBrace], // padded-blocks - // ["no-for-in", convertNoForIn], // no-restricted-syntax config // ["no-function-expression", convertNoFunctionExpression], // ban-syntax config // ["no-suspicious-comment", convertNoSuspiciousComment], // ["no-with-statement", convertNoWithStatement], diff --git a/src/rules/converters/no-for-in.ts b/src/rules/converters/no-for-in.ts new file mode 100644 index 000000000..8b3bb5b3f --- /dev/null +++ b/src/rules/converters/no-for-in.ts @@ -0,0 +1,14 @@ +import { RuleConverter } from "../converter"; + +export const convertNoForIn: RuleConverter = tslintRule => { + return { + rules: [ + { + ...(tslintRule.ruleArguments.length !== 0 && { + ruleArguments: tslintRule.ruleArguments, + }), + ruleName: "no-restricted-syntax", + }, + ], + }; +}; diff --git a/src/rules/converters/tests/no-for-in.test.ts b/src/rules/converters/tests/no-for-in.test.ts new file mode 100644 index 000000000..af1da0ba1 --- /dev/null +++ b/src/rules/converters/tests/no-for-in.test.ts @@ -0,0 +1,67 @@ +import { convertNoForIn } from "../no-for-in"; + +describe(convertNoForIn, () => { + test("conversion without arguments", () => { + const result = convertNoForIn({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-restricted-syntax", + }, + ], + }); + }); + test("conversion with arguments", () => { + const result = convertNoForIn({ + ruleArguments: ["error", "ForInStatement"], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-restricted-syntax", + ruleArguments: ["error", "ForInStatement"], + }, + ], + }); + }); + test("conversion with object arguments", () => { + const result = convertNoForIn({ + ruleArguments: [{ selector: "ForInStatement", message: "For in is not allowed." }], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-restricted-syntax", + ruleArguments: [ + { selector: "ForInStatement", message: "For in is not allowed." }, + ], + }, + ], + }); + }); + test("conversion with mixed arguments", () => { + const result = convertNoForIn({ + ruleArguments: [ + "error", + { selector: "ForInStatement", message: "For in is not allowed." }, + ], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "no-restricted-syntax", + ruleArguments: [ + "error", + { selector: "ForInStatement", message: "For in is not allowed." }, + ], + }, + ], + }); + }); +}); From 2d2e6b7135b996501c06088c37cd3247f6131d74 Mon Sep 17 00:00:00 2001 From: Boris Pallares Date: Thu, 3 Oct 2019 23:23:57 -0500 Subject: [PATCH 2/2] Fixes tests and coverter --- src/rules/converters/no-for-in.ts | 6 +-- src/rules/converters/tests/no-for-in.test.ts | 51 +------------------- 2 files changed, 3 insertions(+), 54 deletions(-) diff --git a/src/rules/converters/no-for-in.ts b/src/rules/converters/no-for-in.ts index 8b3bb5b3f..ed3225970 100644 --- a/src/rules/converters/no-for-in.ts +++ b/src/rules/converters/no-for-in.ts @@ -1,12 +1,10 @@ import { RuleConverter } from "../converter"; -export const convertNoForIn: RuleConverter = tslintRule => { +export const convertNoForIn: RuleConverter = () => { return { rules: [ { - ...(tslintRule.ruleArguments.length !== 0 && { - ruleArguments: tslintRule.ruleArguments, - }), + ruleArguments: ["ForInStatement"], ruleName: "no-restricted-syntax", }, ], diff --git a/src/rules/converters/tests/no-for-in.test.ts b/src/rules/converters/tests/no-for-in.test.ts index af1da0ba1..af3132032 100644 --- a/src/rules/converters/tests/no-for-in.test.ts +++ b/src/rules/converters/tests/no-for-in.test.ts @@ -10,56 +10,7 @@ describe(convertNoForIn, () => { rules: [ { ruleName: "no-restricted-syntax", - }, - ], - }); - }); - test("conversion with arguments", () => { - const result = convertNoForIn({ - ruleArguments: ["error", "ForInStatement"], - }); - - expect(result).toEqual({ - rules: [ - { - ruleName: "no-restricted-syntax", - ruleArguments: ["error", "ForInStatement"], - }, - ], - }); - }); - test("conversion with object arguments", () => { - const result = convertNoForIn({ - ruleArguments: [{ selector: "ForInStatement", message: "For in is not allowed." }], - }); - - expect(result).toEqual({ - rules: [ - { - ruleName: "no-restricted-syntax", - ruleArguments: [ - { selector: "ForInStatement", message: "For in is not allowed." }, - ], - }, - ], - }); - }); - test("conversion with mixed arguments", () => { - const result = convertNoForIn({ - ruleArguments: [ - "error", - { selector: "ForInStatement", message: "For in is not allowed." }, - ], - }); - - expect(result).toEqual({ - rules: [ - { - ruleName: "no-restricted-syntax", - ruleArguments: [ - "error", - { selector: "ForInStatement", message: "For in is not allowed." }, - ], + ruleArguments: ["ForInStatement"], }, ], });