Skip to content

Commit

Permalink
fix: component selector name
Browse files Browse the repository at this point in the history
Throw more explicit error saying that a dash is required.

Fix #192
  • Loading branch information
mgechev committed Dec 21, 2016
1 parent 36f5cb4 commit 3d53a18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/selectorNameBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ export abstract class SelectorRule extends Lint.Rules.AbstractRule {
this));
}

public getFailureString(failureConfig): string {
return sprintf(failureConfig.fail, failureConfig.className, this.getOptions().ruleArguments, failureConfig.selector);
}

public abstract getTypeFailure(): any;
public abstract getNameFailure(): any;
protected abstract getSinglePrefixFailure(): any;
Expand All @@ -81,7 +77,7 @@ export abstract class SelectorRule extends Lint.Rules.AbstractRule {
}

private setMultiPrefix(prefix:string) {
this.isMultiPrefix = typeof prefix==='string';
this.isMultiPrefix = typeof prefix ==='string';
}

private setPrefixArguments(prefix:any) {
Expand Down Expand Up @@ -153,7 +149,11 @@ export class SelectorValidatorWalker extends Lint.RuleWalker {
let error = sprintf(this.rule.getTypeFailure(), className,this.rule.getOptions().ruleArguments[0]);
this.addFailure(this.createFailure(i.getStart(), i.getWidth(),error));
} else if (!validateSelectors(this.rule.validateName.bind(this.rule))) {
let error = sprintf(this.rule.getNameFailure(),className,this.rule.getOptions().ruleArguments[2]);
let name = this.rule.getOptions().ruleArguments[2];
if (name === 'kebab-case') {
name += ' and include dash';
}
let error = sprintf(this.rule.getNameFailure(), className, name);
this.addFailure(this.createFailure(i.getStart(), i.getWidth(), error));
} else if (!validateSelectors(this.rule.validatePrefix.bind(this.rule))) {
let error = sprintf(this.rule.getPrefixFailure(),className,this.rule.prefixArguments);
Expand Down
4 changes: 2 additions & 2 deletions test/componentSelectorRule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe('component-selector-name', () => {
})
class Test {}`;
assertFailure('component-selector', source, {
message: 'The selector of the component "Test" should be named kebab-case ($$05-02$$)',
message: 'The selector of the component "Test" should be named kebab-case and include dash ($$05-02$$)',
startPosition: {
line: 2,
character: 18
Expand All @@ -213,7 +213,7 @@ describe('component-selector-name', () => {
})
class Test {}`;
assertFailure('component-selector', source, {
message: 'The selector of the component "Test" should be named kebab-case ($$05-02$$)',
message: 'The selector of the component "Test" should be named kebab-case and include dash ($$05-02$$)',
startPosition: {
line: 2,
character: 18
Expand Down

0 comments on commit 3d53a18

Please sign in to comment.