UNPKG

criticizer

Version:

Linting for Angular applications, following angular.io/styleguide.

34 lines (29 loc) 1.17 kB
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 = 'In the class "%s", the directive output ' + 'property "%s" should not be renamed.' + 'Please, consider the following use "@Output() %s = new EventEmitter();"'; public apply(sourceFile:ts.SourceFile):Lint.RuleFailure[] { return this.applyWithWalker( new OutputMetadataWalker(sourceFile, this.getOptions())); } } export class OutputMetadataWalker extends Ng2Walker { visitNg2Output(property:ts.PropertyDeclaration, output:ts.Decorator, args:string[]) { let className = (<any>property).parent.name.text; let memberName = (<any>property.name).text; if (args.length !== 0 && memberName !== args[0]) { let failureConfig:string[] = [className, memberName, memberName]; failureConfig.unshift(Rule.FAILURE_STRING); this.addFailure( this.createFailure( property.getStart(), property.getWidth(), sprintf.apply(this, failureConfig))); } } }