Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/rules/converters/codelyzer/component-selector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { RuleConverter } from "../../converter";

export const convertComponentSelector: RuleConverter = (tslintRule) => {
return {
rules: [
{
...(tslintRule.ruleArguments.length !== 0 && {
ruleArguments: [
{
type: tslintRule.ruleArguments[0],
prefix: tslintRule.ruleArguments[1],
style: tslintRule.ruleArguments[2],
},
],
}),
ruleName: "@angular-eslint/component-selector",
},
],
plugins: ["@angular-eslint/eslint-plugin"],
};
};
47 changes: 47 additions & 0 deletions src/rules/converters/codelyzer/tests/component-selector.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { convertComponentSelector } from "../component-selector";

describe(convertComponentSelector, () => {
test("conversion with arguments of same type", () => {
const result = convertComponentSelector({
ruleArguments: ["attribute", "myPrefix", "camelCase"],
});

expect(result).toEqual({
rules: [
{
ruleArguments: [
{
type: "attribute",
prefix: "myPrefix",
style: "camelCase",
},
],
ruleName: "@angular-eslint/component-selector",
},
],
plugins: ["@angular-eslint/eslint-plugin"],
});
});

test("conversion with arguments of mixed type", () => {
const result = convertComponentSelector({
ruleArguments: ["element", ["ng", "ngx"], "kebab-case"],
});

expect(result).toEqual({
rules: [
{
ruleArguments: [
{
type: "element",
prefix: ["ng", "ngx"],
style: "kebab-case",
},
],
ruleName: "@angular-eslint/component-selector",
},
],
plugins: ["@angular-eslint/eslint-plugin"],
});
});
});
2 changes: 2 additions & 0 deletions src/rules/rulesConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import { convertVariableName } from "./converters/variable-name";

// Codelyzer converters
import { convertComponentClassSuffix } from "./converters/codelyzer/component-class-suffix";
import { convertComponentSelector } from "./converters/codelyzer/component-selector";

/**
* Keys TSLint rule names to their ESLint rule converters.
Expand All @@ -158,6 +159,7 @@ export const rulesConverters = new Map([
["class-name", convertClassName],
["comment-format", convertCommentFormat],
["component-class-suffix", convertComponentClassSuffix],
["component-selector", convertComponentSelector],
["curly", convertCurly],
["cyclomatic-complexity", convertCyclomaticComplexity],
["deprecation", convertDeprecation],
Expand Down