import * as ts from 'typescript' ; import { Checker } from '../checker' ; import { ErrorCode } from '../error_code' ; import { AbstractRule } from '../rule' ; /**
 * A Tsetse rule that checks for some potential unsafe property renaming
 * patterns.
 *
 * Note: This rule can have false positives.
 */ export class Rule extends AbstractRule { static readonly RULE_NAME = 'property-renaming-safe' ; readonly ruleName = Rule . RULE_NAME ; readonly code = ErrorCode . PROPERTY_RENAMING_SAFE ; register ( checker ) { checker . on ( ts . SyntaxKind . PropertyAccessExpression , checkIndexSignAccessedWithPropAccess , this . code ) ; } } function checkIndexSignAccessedWithPropAccess ( checker , pae ) { const typeChecker = checker . typeChecker ; const t = typeChecker . getTypeAtLocation ( pae . expression ) ; if ( ! t . getStringIndexType ( ) ) return ; const propSym = typeChecker . getSymbolAtLocation ( pae . name ) ; if ( propSym ) return ; checker . addFailureAtNode ( pae . name , `Property ${ pae . name . text } is not declared on Type ` + `${ typeChecker . typeToString ( t ) }. The type has a string index ` + `signature, but it is being accessed using a dotted property ` + `access.
See http://tsetse.info/property-renaming-safe.` ) ; }