Skip to content

Commit dc4ed26

Browse files
authored
Add codelyzer component-selector converter (#452)
1 parent 313eb7d commit dc4ed26

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { RuleConverter } from "../../converter";
2+
3+
export const convertComponentSelector: RuleConverter = (tslintRule) => {
4+
return {
5+
rules: [
6+
{
7+
...(tslintRule.ruleArguments.length !== 0 && {
8+
ruleArguments: [
9+
{
10+
type: tslintRule.ruleArguments[0],
11+
prefix: tslintRule.ruleArguments[1],
12+
style: tslintRule.ruleArguments[2],
13+
},
14+
],
15+
}),
16+
ruleName: "@angular-eslint/component-selector",
17+
},
18+
],
19+
plugins: ["@angular-eslint/eslint-plugin"],
20+
};
21+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { convertComponentSelector } from "../component-selector";
2+
3+
describe(convertComponentSelector, () => {
4+
test("conversion with arguments of same type", () => {
5+
const result = convertComponentSelector({
6+
ruleArguments: ["attribute", "myPrefix", "camelCase"],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleArguments: [
13+
{
14+
type: "attribute",
15+
prefix: "myPrefix",
16+
style: "camelCase",
17+
},
18+
],
19+
ruleName: "@angular-eslint/component-selector",
20+
},
21+
],
22+
plugins: ["@angular-eslint/eslint-plugin"],
23+
});
24+
});
25+
26+
test("conversion with arguments of mixed type", () => {
27+
const result = convertComponentSelector({
28+
ruleArguments: ["element", ["ng", "ngx"], "kebab-case"],
29+
});
30+
31+
expect(result).toEqual({
32+
rules: [
33+
{
34+
ruleArguments: [
35+
{
36+
type: "element",
37+
prefix: ["ng", "ngx"],
38+
style: "kebab-case",
39+
},
40+
],
41+
ruleName: "@angular-eslint/component-selector",
42+
},
43+
],
44+
plugins: ["@angular-eslint/eslint-plugin"],
45+
});
46+
});
47+
});

src/rules/rulesConverters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ import { convertVariableName } from "./converters/variable-name";
139139

140140
// Codelyzer converters
141141
import { convertComponentClassSuffix } from "./converters/codelyzer/component-class-suffix";
142+
import { convertComponentSelector } from "./converters/codelyzer/component-selector";
142143

143144
/**
144145
* Keys TSLint rule names to their ESLint rule converters.
@@ -158,6 +159,7 @@ export const rulesConverters = new Map([
158159
["class-name", convertClassName],
159160
["comment-format", convertCommentFormat],
160161
["component-class-suffix", convertComponentClassSuffix],
162+
["component-selector", convertComponentSelector],
161163
["curly", convertCurly],
162164
["cyclomatic-complexity", convertCyclomaticComplexity],
163165
["deprecation", convertDeprecation],

0 commit comments

Comments
 (0)