import * as ts from 'typescript' ; import * as Lint from 'tslint' ; import { ErrorTolerantWalker } from './ErrorTolerantWalker' ; /**
 * Implementation of the banned-term rulesets.
 */ export class BannedTermWalker extends ErrorTolerantWalker { private failureString : string ; private bannedTerms : string [ ] ; private allowQuotedProperties : boolean = false ; constructor ( sourceFile , options , failureString , bannedTerms ) { super ( sourceFile , options ) ; this . failureString = failureString ; this . bannedTerms = bannedTerms ; this . getOptions ( ) . forEach ( ( opt ) => { if ( typeof opt === 'object' ) { this . allowQuotedProperties = opt [ 'allow-quoted-properties' ] === true ; } } ) ; } protected visitFunctionDeclaration ( node ) { this . validateNode ( node ) ; super . visitFunctionDeclaration ( node ) ; } protected visitGetAccessor ( node ) { this . validateNode ( node ) ; super . visitGetAccessor ( node ) ; } protected visitMethodDeclaration ( node ) { this . validateNode ( node ) ; super . visitMethodDeclaration ( node ) ; } protected visitParameterDeclaration ( node ) { if ( node . name . getText ( ) !== 'this' ) { this . validateNode ( node ) ; } super . visitParameterDeclaration ( node ) ; } protected visitPropertyDeclaration ( node ) { this . validateNode ( node ) ; super . visitPropertyDeclaration ( node ) ; } protected visitPropertySignature ( node ) { if ( node . kind === ts . SyntaxKind . PropertySignature ) { const signature = < ts . PropertySignature > node ; const propertyName = signature . name ; if ( this . allowQuotedProperties === false || propertyName . kind !== ts . SyntaxKind . StringLiteral ) { this . validateNode ( node ) ; } } else { this . validateNode ( node ) ; } super . visitPropertySignature ( node ) ; } protected visitSetAccessor ( node ) { this . validateNode ( node ) ; super . visitSetAccessor ( node ) ; } protected visitVariableDeclaration ( node ) { this . validateNode ( node ) ; super . visitVariableDeclaration ( node ) ; } private validateNode ( node ) { if ( ( < any > node ) . name ) { if ( ( < any > node ) . name . text ) { const text = ( < any > node ) . name . text ; if ( this . isBannedTerm ( text ) ) { this . addFailureAt ( node . getStart ( ) , node . getWidth ( ) , this . failureString + text ) ; } } } } private isBannedTerm ( text ) { return this . bannedTerms . indexOf ( text ) !== - 1 ; } }