From 9a62f5b0637b037304f9447e2b2efc250f185f88 Mon Sep 17 00:00:00 2001 From: KingDarBoja Date: Thu, 13 Aug 2020 20:26:18 -0500 Subject: [PATCH] Add codelyzer pipe-prefix converter --- src/rules/converters/codelyzer/pipe-prefix.ts | 19 ++++++++++ .../codelyzer/tests/pipe-prefix.test.ts | 38 +++++++++++++++++++ src/rules/rulesConverters.ts | 2 + 3 files changed, 59 insertions(+) create mode 100644 src/rules/converters/codelyzer/pipe-prefix.ts create mode 100644 src/rules/converters/codelyzer/tests/pipe-prefix.test.ts diff --git a/src/rules/converters/codelyzer/pipe-prefix.ts b/src/rules/converters/codelyzer/pipe-prefix.ts new file mode 100644 index 000000000..4a927e956 --- /dev/null +++ b/src/rules/converters/codelyzer/pipe-prefix.ts @@ -0,0 +1,19 @@ +import { RuleConverter } from "../../converter"; + +export const convertPipePrefix: RuleConverter = (tslintRule) => { + return { + rules: [ + { + ...(tslintRule.ruleArguments.length !== 0 && { + ruleArguments: [ + { + prefixes: tslintRule.ruleArguments, + }, + ], + }), + ruleName: "@angular-eslint/pipe-prefix", + }, + ], + plugins: ["@angular-eslint/eslint-plugin"], + }; +}; diff --git a/src/rules/converters/codelyzer/tests/pipe-prefix.test.ts b/src/rules/converters/codelyzer/tests/pipe-prefix.test.ts new file mode 100644 index 000000000..a04661967 --- /dev/null +++ b/src/rules/converters/codelyzer/tests/pipe-prefix.test.ts @@ -0,0 +1,38 @@ +import { convertPipePrefix } from "../pipe-prefix"; + +describe(convertPipePrefix, () => { + test("conversion without arguments", () => { + const result = convertPipePrefix({ + ruleArguments: [], + }); + + expect(result).toEqual({ + rules: [ + { + ruleName: "@angular-eslint/pipe-prefix", + }, + ], + plugins: ["@angular-eslint/eslint-plugin"], + }); + }); + + test("conversion with arguments", () => { + const result = convertPipePrefix({ + ruleArguments: ["ng", "sg", "mg"], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [ + { + prefixes: ["ng", "sg", "mg"], + }, + ], + ruleName: "@angular-eslint/pipe-prefix", + }, + ], + plugins: ["@angular-eslint/eslint-plugin"], + }); + }); +}); diff --git a/src/rules/rulesConverters.ts b/src/rules/rulesConverters.ts index 35c79548a..fc532fdf6 100644 --- a/src/rules/rulesConverters.ts +++ b/src/rules/rulesConverters.ts @@ -158,6 +158,7 @@ import { convertNoOutputRename } from "./converters/codelyzer/no-output-rename"; import { convertNoOutputsMetadataProperty } from "./converters/codelyzer/no-outputs-metadata-property"; import { convertNoPipeImpure } from "./converters/codelyzer/no-pipe-impure"; import { convertNoQueriesMetadataProperty } from "./converters/codelyzer/no-queries-metadata-property"; +import { convertPipePrefix } from "./converters/codelyzer/pipe-prefix"; import { convertPreferOnPushComponentChangeDetection } from "./converters/codelyzer/prefer-on-push-component-change-detection"; import { convertPreferOutputReadonly } from "./converters/codelyzer/prefer-output-readonly"; import { convertRelativeUrlPrefix } from "./converters/codelyzer/relative-url-prefix"; @@ -323,6 +324,7 @@ export const rulesConverters = new Map([ ["one-variable-per-declaration", convertOneVariablePerDeclaration], ["only-arrow-functions", convertOnlyArrowFunctions], ["ordered-imports", convertOrderedImports], + ["pipe-prefix", convertPipePrefix], ["prefer-const", convertPreferConst], ["prefer-for-of", convertPreferForOf], ["prefer-function-over-method", convertPreferFunctionOverMethod],