diff --git a/src/rules/converters/codelyzer/directive-selector.ts b/src/rules/converters/codelyzer/directive-selector.ts new file mode 100644 index 000000000..75324bf60 --- /dev/null +++ b/src/rules/converters/codelyzer/directive-selector.ts @@ -0,0 +1,21 @@ +import { RuleConverter } from "../../converter"; + +export const convertDirectiveSelector: RuleConverter = (tslintRule) => { + return { + rules: [ + { + ...(tslintRule.ruleArguments.length !== 0 && { + ruleArguments: [ + { + type: tslintRule.ruleArguments[0], + prefix: tslintRule.ruleArguments[1], + style: tslintRule.ruleArguments[2], + }, + ], + }), + ruleName: "@angular-eslint/directive-selector", + }, + ], + plugins: ["@angular-eslint/eslint-plugin"], + }; +}; diff --git a/src/rules/converters/codelyzer/tests/directive-selector.test.ts b/src/rules/converters/codelyzer/tests/directive-selector.test.ts new file mode 100644 index 000000000..8ddc97b0e --- /dev/null +++ b/src/rules/converters/codelyzer/tests/directive-selector.test.ts @@ -0,0 +1,47 @@ +import { convertDirectiveSelector } from "../directive-selector"; + +describe(convertDirectiveSelector, () => { + test("conversion with arguments of same type", () => { + const result = convertDirectiveSelector({ + ruleArguments: ["attribute", "myPrefix", "camelCase"], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [ + { + type: "attribute", + prefix: "myPrefix", + style: "camelCase", + }, + ], + ruleName: "@angular-eslint/directive-selector", + }, + ], + plugins: ["@angular-eslint/eslint-plugin"], + }); + }); + + test("conversion with arguments of mixed type", () => { + const result = convertDirectiveSelector({ + ruleArguments: ["element", ["ng", "ngx"], "kebab-case"], + }); + + expect(result).toEqual({ + rules: [ + { + ruleArguments: [ + { + type: "element", + prefix: ["ng", "ngx"], + style: "kebab-case", + }, + ], + ruleName: "@angular-eslint/directive-selector", + }, + ], + plugins: ["@angular-eslint/eslint-plugin"], + }); + }); +}); diff --git a/src/rules/rulesConverters.ts b/src/rules/rulesConverters.ts index 044143760..b39115c08 100644 --- a/src/rules/rulesConverters.ts +++ b/src/rules/rulesConverters.ts @@ -143,6 +143,7 @@ import { convertComponentMaxInlineDeclarations } from "./converters/codelyzer/co import { convertComponentSelector } from "./converters/codelyzer/component-selector"; import { convertContextualLifecycle } from "./converters/codelyzer/contextual-lifecycle"; import { convertDirectiveClassSuffix } from "./converters/codelyzer/directive-class-suffix"; +import { convertDirectiveSelector } from "./converters/codelyzer/directive-selector"; import { convertNoAttributeDecorator } from "./converters/codelyzer/no-attribute-decorator"; import { convertUsePipeDecorator } from "./converters/codelyzer/use-pipe-decorator"; @@ -171,6 +172,7 @@ export const rulesConverters = new Map([ ["cyclomatic-complexity", convertCyclomaticComplexity], ["deprecation", convertDeprecation], ["directive-class-suffix", convertDirectiveClassSuffix], + ["directive-selector", convertDirectiveSelector], ["eofline", convertEofline], ["file-name-casing", convertFileNameCasing], ["forin", convertForin],