Skip to content

Commit

Permalink
fix: proper check for interface name
Browse files Browse the repository at this point in the history
  • Loading branch information
mgechev committed Sep 11, 2017
1 parent 28ecbdd commit cdfd3d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/directiveClassSuffixRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { NgWalker } from './angular/ngWalker';
import { DirectiveMetadata } from './angular/metadata';

const getInterfaceName = (t: any): string => {
if (t.expression && t.expression.name) {
if (!t.expression) {
return '';
}
if (t.expression.name) {
return t.expression.name.text;
}
return t.expression.text;
Expand Down Expand Up @@ -58,7 +61,10 @@ export class ClassMetadataWalker extends NgWalker {
const heritageClauses = meta.controller.heritageClauses;
if (heritageClauses) {
const i = heritageClauses.filter(h => h.token === ts.SyntaxKind.ImplementsKeyword);
if (i.length !== 0 && i[0].types.map(getInterfaceName).some(name => name.endsWith(ValidatorSuffix))) {
if (i.length !== 0 &&
i[0].types.map(getInterfaceName)
.filter(name => !!name)
.some(name => name.endsWith(ValidatorSuffix))) {
suffixes.push(ValidatorSuffix);
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/directiveClassSuffix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('directive-class-suffix', () => {
`;
assertAnnotated({
ruleName: 'directive-class-suffix',
message: 'The name of the class Test should end with the suffix Directive, Page, Validator (https://angular.io/styleguide#style-02-03)',
message: 'The name of the class Test should end with the suffix ' +
'Directive, Page, Validator (https://angular.io/styleguide#style-02-03)',
source,
options: ['Directive', 'Page', 'Validator']
});
Expand Down

0 comments on commit cdfd3d0

Please sign in to comment.