import * as ts from 'typescript' ; import * as Lint from 'tslint' ; import { ScopedSymbolTrackingWalker } from './ScopedSymbolTrackingWalker' ; import { AstUtils } from './AstUtils' ; /**
 * A walker that creates failures whenever it detects a string parameter is being passed to a certain constructor. .
 */ export class NoStringParameterToFunctionCallWalker extends ScopedSymbolTrackingWalker { private failureString : string ; private targetFunctionName : string ; public constructor ( sourceFile , targetFunctionName , options , program ? ) { super ( sourceFile , options , program ) ; this . targetFunctionName = targetFunctionName ; this . failureString = 'Forbidden ' + targetFunctionName + ' string parameter: ' ; } protected visitCallExpression ( node ) { this . validateExpression ( node ) ; super . visitCallExpression ( node ) ; } private validateExpression ( node ) { const functionName = AstUtils . getFunctionName ( node ) ; const firstArg = node . arguments [ 0 ] ; if ( functionName === this . targetFunctionName && firstArg != null ) { if ( ! this . isExpressionEvaluatingToFunction ( firstArg ) ) { const msg = this . failureString + firstArg . getFullText ( ) . trim ( ) . substring ( 0 , 40 ) ; this . addFailureAt ( node . getStart ( ) , node . getWidth ( ) , msg ) ; } } } }