Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/mgechev/codelyzer:
  fix document
  fix document
  fix: order problem with multiple prefixes for selector
  • Loading branch information
mgechev committed Apr 14, 2017
2 parents 3bb8ae3 + 1f89504 commit 9362759
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You can easily use codelyzer with your custom setup:
#### Installation

```shell
npm i codelyzer@2.0.0-beta.4 tslint@4.0.0 typescript@2.0.9 @angular/core@2.4.0 @angular/compiler@2.4.0 rxjs@5.0.1 zone.js@0.7.2
npm i codelyzer@~2.0.0 tslint@4.0.0 typescript@2.0.9 @angular/core@2.4.0 @angular/compiler@2.4.0 rxjs@5.0.1 zone.js@0.7.2
```

A. Using codelyzer package in PATH
Expand Down Expand Up @@ -79,7 +79,6 @@ Create the following `tslint.json` file like:
"templates-use-public": true,
"no-access-missing-member": true,
"invoke-injectable": true,
"invoke-injectable": true,
"template-to-ng-template": true
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/selectorNameBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export abstract class SelectorRule extends Lint.Rules.AbstractRule {
}

private setPrefixValidator(prefix: any, name: string) {
if (!this.isMultiPrefix) {
prefix = (prefix||[]).sort((a: string, b: string) => {
return a.length < b.length ? 1 : -1;
});
}
let prefixExpression: string = this.isMultiPrefix?prefix:(prefix||[]).join('|');
this.prefixValidator = SelectorValidator.prefix(prefixExpression, name);
}
Expand Down
9 changes: 9 additions & 0 deletions test/componentSelectorRule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ describe('component-selector-prefix', () => {
assertSuccess('component-selector', source, ['element', ['sg','ng','mg'], 'kebab-case']);
});

it('should succeed when set valid selector in @Component using multiple prefixes and some prefixes are substring of others', () => {
let source = `
@Component({
selector: 'abc-bar-foo'
})
class Test {}`;
assertSuccess('component-selector', source, ['element', ['ab','abc','mg'], 'kebab-case']);
});

it('should succeed without prefix', () => {
let source = `
@Component({
Expand Down

0 comments on commit 9362759

Please sign in to comment.