import * as ts from 'typescript' ; import { Checker } from '../../checker' ; import { ErrorCode } from '../../error_code' ; import { AbsoluteMatcher } from '../absolute_matcher' ; import { debugLog } from '../ast_tools' ; import { Fixer } from '../fixer' ; import { PatternEngine } from './pattern_engine' ; function checkId ( tc , n , matcher ) { debugLog ( ( ) => `inspecting ${ n . getText ( ) . trim ( ) }` ) ; if ( ! matcher . matches ( n , tc ) ) { debugLog ( ( ) => 'Not the right global name.' ) ; return ; } return n ; } /** Engine for the BANNED_NAME pattern */ export class NameEngine extends PatternEngine { register ( checker ) { for ( const value of this . config . values ) { const matcher = new AbsoluteMatcher ( value ) ; const bannedIdName = matcher . bannedName . split ( '.' ) . pop ( ) ! ; checker . onNamedIdentifier ( bannedIdName , this . wrapCheckWithAllowlistingAndFixer ( ( tc , n ) => checkId ( tc , n , matcher ) ) , this . config . errorCode ) ; } } }