Skip to content

Commit 9e18cf2

Browse files
Alan Agiushansl
Alan Agius
authored andcommitted
fix(@schematics/angular): kebab case prefix causes lint errors in new directives
`Component` selectors are always kekabed while `Directive` selectors are always camelized. This updates the lint rules to convert the prefix to the appropiate case Fixes #13796
1 parent a7c66f9 commit 9e18cf2

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"extends": "<%= relativePathToWorkspaceRoot %>/tslint.json",
3-
"rules": {
4-
"directive-selector": [
5-
true,
6-
"attribute",
7-
"<%= prefix %>",
8-
"camelCase"
9-
],
10-
"component-selector": [
11-
true,
12-
"element",
13-
"<%= prefix %>",
14-
"kebab-case"
15-
]
16-
}
2+
"extends": "<%= relativePathToWorkspaceRoot %>/tslint.json",
3+
"rules": {
4+
"directive-selector": [
5+
true,
6+
"attribute",
7+
"<%= utils.camelize(prefix) %>",
8+
"camelCase"
9+
],
10+
"component-selector": [
11+
true,
12+
"element",
13+
"<%= utils.dasherize(prefix) %>",
14+
"kebab-case"
15+
]
16+
}
1717
}

packages/schematics/angular/application/index_spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ describe('Application Schematic', () => {
148148
expect(content.rules['component-selector'][2]).toMatch('app');
149149
});
150150

151+
it('should set the right prefix in the tslint file when provided is kebabed', () => {
152+
const options: ApplicationOptions = { ...defaultOptions, prefix: 'foo-bar' };
153+
const tree = schematicRunner.runSchematic('application', options, workspaceTree);
154+
const path = '/projects/foo/tslint.json';
155+
const content = JSON.parse(tree.readContent(path));
156+
expect(content.rules['directive-selector'][2]).toMatch('fooBar');
157+
expect(content.rules['component-selector'][2]).toMatch('foo-bar');
158+
});
159+
151160
it('should set the right coverage folder in the karma.json file', () => {
152161
const tree = schematicRunner.runSchematic('application', defaultOptions, workspaceTree);
153162
const karmaConf = getFileContent(tree, '/projects/foo/karma.conf.js');

packages/schematics/angular/library/files/tslint.json.template

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"directive-selector": [
55
true,
66
"attribute",
7-
"<%= prefix %>",
7+
"<%= camelize(prefix) %>",
88
"camelCase"
99
],
1010
"component-selector": [
1111
true,
1212
"element",
13-
"<%= prefix %>",
13+
"<%= dasherize(prefix) %>",
1414
"kebab-case"
1515
]
1616
}

packages/schematics/angular/library/index_spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ describe('Library Schematic', () => {
123123
expect(workspace.projects.foo.prefix).toEqual('pre');
124124
});
125125

126+
it('should set the right prefix in the tslint file when provided is kebabed', () => {
127+
const options: GenerateLibrarySchema = { ...defaultOptions, prefix: 'foo-bar' };
128+
const tree = schematicRunner.runSchematic('library', options, workspaceTree);
129+
const path = '/projects/foo/tslint.json';
130+
const content = JSON.parse(tree.readContent(path));
131+
expect(content.rules['directive-selector'][2]).toMatch('fooBar');
132+
expect(content.rules['component-selector'][2]).toMatch('foo-bar');
133+
});
134+
126135
it('should handle a pascalCasedName', () => {
127136
const options = {...defaultOptions, name: 'pascalCasedName'};
128137
const tree = schematicRunner.runSchematic('library', options, workspaceTree);

0 commit comments

Comments
 (0)