forked from mgechev/codelyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvokeInjectableRule.ts
More file actions
27 lines (24 loc) · 937 Bytes
/
invokeInjectableRule.ts
File metadata and controls
27 lines (24 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import * as Lint from 'tslint';
import * as ts from 'typescript';
import {sprintf} from 'sprintf-js';
import {Ng2Walker} from './angular/ng2Walker';
export class Rule extends Lint.Rules.AbstractRule {
static FAILURE_STRING: string = 'You have to invoke @Injectable()';
public apply(sourceFile:ts.SourceFile):Lint.RuleFailure[] {
return this.applyWithWalker(
new ValidateInjectableWalker(sourceFile,
this.getOptions()));
}
}
export class ValidateInjectableWalker extends Ng2Walker {
visitClassDeclaration(declaration: ts.ClassDeclaration) {
(<ts.Decorator[]>declaration.decorators || [])
.forEach((d: any) => {
// This means that "Injectable" is used as Identifier,
// not as a call expression.
if (d.expression && d.expression.text === 'Injectable') {
this.addFailure(this.createFailure(d.getStart(), d.getWidth(), Rule.FAILURE_STRING));
}
});
}
}