From 3d53a187c559067f9d71d364773fb55aedf4a0da Mon Sep 17 00:00:00 2001 From: mgechev Date: Wed, 21 Dec 2016 12:39:04 +0200 Subject: [PATCH] fix: component selector name Throw more explicit error saying that a dash is required. Fix #192 --- src/selectorNameBase.ts | 12 ++++++------ test/componentSelectorRule.spec.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/selectorNameBase.ts b/src/selectorNameBase.ts index 6f3787414..605221f90 100644 --- a/src/selectorNameBase.ts +++ b/src/selectorNameBase.ts @@ -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; @@ -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) { @@ -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); diff --git a/test/componentSelectorRule.spec.ts b/test/componentSelectorRule.spec.ts index d2b615b27..7ea5d7547 100644 --- a/test/componentSelectorRule.spec.ts +++ b/test/componentSelectorRule.spec.ts @@ -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 @@ -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