Skip to content

Add codelyzer component-selector converter #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2020
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