Skip to content

Commit 1641ad0

Browse files
committed
fix(selectorBase): do not validate components with directives rule
1 parent e21d70c commit 1641ad0

4 files changed

+22
-9
lines changed

src/componentSelectorRule.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {SelectorRule} from './selectorNameBase';
22

33
export class Rule extends SelectorRule {
4-
public getTypeFailure():any { return 'The selector of the component "%s" should be used as %s ($$05-03$$)'; }
5-
public getNameFailure():any { return 'The selector of the component "%s" should be named %s ($$05-02$$)'; }
6-
getSinglePrefixFailure():any { return 'The selector of the component "%s" should have prefix "%s" ($$02-07$$)'; }
7-
getManyPrefixFailure():any { return 'The selector of the component "%s" should have one of the prefixes: %s ($$02-07$$)'; }
4+
public handleType = 'Component';
5+
public getTypeFailure():any { return 'The selector of the component "%s" should be used as %s ($$05-03$$)'; }
6+
public getNameFailure():any { return 'The selector of the component "%s" should be named %s ($$05-02$$)'; }
7+
getSinglePrefixFailure():any { return 'The selector of the component "%s" should have prefix "%s" ($$02-07$$)'; }
8+
getManyPrefixFailure():any { return 'The selector of the component "%s" should have one of the prefixes: %s ($$02-07$$)'; }
89
}

src/directiveSelectorRule.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {SelectorRule} from './selectorNameBase';
22

33
export class Rule extends SelectorRule {
4-
public getTypeFailure():any { return 'The selector of the directive "%s" should be used as %s ($$02-06$$)'; }
5-
public getNameFailure():any { return 'The selector of the directive "%s" should be named %s ($$02-06$$)'; }
6-
getSinglePrefixFailure():any { return 'The selector of the directive "%s" should have prefix "%s" ($$02-08$$)'; }
7-
getManyPrefixFailure():any { return 'The selector of the directive "%s" should have one of the prefixes: %s ($$02-08$$)'; }
4+
public handleType = 'Directive';
5+
public getTypeFailure():any { return 'The selector of the directive "%s" should be used as %s ($$02-06$$)'; }
6+
public getNameFailure():any { return 'The selector of the directive "%s" should be named %s ($$02-06$$)'; }
7+
getSinglePrefixFailure():any { return 'The selector of the directive "%s" should have prefix "%s" ($$02-08$$)'; }
8+
getManyPrefixFailure():any { return 'The selector of the directive "%s" should have one of the prefixes: %s ($$02-08$$)'; }
89
}
910

src/selectorNameBase.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export abstract class SelectorRule extends Lint.Rules.AbstractRule {
1111
public prefixArguments:string;
1212
public cssSelectorProperty:string;
1313

14+
public handleType: string;
15+
1416
private typeValidator:Function;
1517
private prefixValidator:Function;
1618
private nameValidator:Function;
@@ -126,7 +128,8 @@ export class SelectorValidatorWalker extends Lint.RuleWalker {
126128
let name = expr.text;
127129
let args = baseExpr.arguments || [];
128130
let arg = args[0];
129-
if (name === 'Component' || name === 'Directive') {
131+
// Do not run component rules for directives
132+
if (this.rule.handleType === name) {
130133
this.validateSelector(className, arg);
131134
}
132135
}

test/directiveSelectorRule.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ describe('directive-selector-type', () => {
214214
@Directive({
215215
selector: '[sgBarFoo]'
216216
})
217+
class Test {}`;
218+
assertSuccess('directive-selector', source, ['attribute','sg','camelCase']);
219+
});
220+
it('should not validate @Component', () => {
221+
let source = `
222+
@Component({
223+
selector: 'sg-bar-foo'
224+
})
217225
class Test {}`;
218226
assertSuccess('directive-selector', source, ['attribute','sg','camelCase']);
219227
});

0 commit comments

Comments
 (0)