Skip to content

Commit 6a78abb

Browse files
KingDarBojaJosh Goldberg
andauthored
Add codelyzer directive-selector converter (#458)
Co-authored-by: Josh Goldberg <[email protected]>
1 parent bef17a2 commit 6a78abb

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 convertDirectiveSelector: 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/directive-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 { convertDirectiveSelector } from "../directive-selector";
2+
3+
describe(convertDirectiveSelector, () => {
4+
test("conversion with arguments of same type", () => {
5+
const result = convertDirectiveSelector({
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/directive-selector",
20+
},
21+
],
22+
plugins: ["@angular-eslint/eslint-plugin"],
23+
});
24+
});
25+
26+
test("conversion with arguments of mixed type", () => {
27+
const result = convertDirectiveSelector({
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/directive-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
@@ -143,6 +143,7 @@ import { convertComponentMaxInlineDeclarations } from "./converters/codelyzer/co
143143
import { convertComponentSelector } from "./converters/codelyzer/component-selector";
144144
import { convertContextualLifecycle } from "./converters/codelyzer/contextual-lifecycle";
145145
import { convertDirectiveClassSuffix } from "./converters/codelyzer/directive-class-suffix";
146+
import { convertDirectiveSelector } from "./converters/codelyzer/directive-selector";
146147
import { convertNoAttributeDecorator } from "./converters/codelyzer/no-attribute-decorator";
147148
import { convertUsePipeDecorator } from "./converters/codelyzer/use-pipe-decorator";
148149

@@ -171,6 +172,7 @@ export const rulesConverters = new Map([
171172
["cyclomatic-complexity", convertCyclomaticComplexity],
172173
["deprecation", convertDeprecation],
173174
["directive-class-suffix", convertDirectiveClassSuffix],
175+
["directive-selector", convertDirectiveSelector],
174176
["eofline", convertEofline],
175177
["file-name-casing", convertFileNameCasing],
176178
["forin", convertForin],

0 commit comments

Comments
 (0)