fileoverview import * as ts from 'typescript' ; import { Checker } from '../checker' ; import { ErrorCode } from '../error_code' ; import { AbstractRule } from '../rule' ; export class Rule extends AbstractRule { static readonly RULE_NAME = 'ban-mutable-exports' ; readonly ruleName = Rule . RULE_NAME ; readonly code = ErrorCode . BAN_MUTABLE_EXPORTS ; register ( checker ) { checker . on ( ts . SyntaxKind . SourceFile , checkFile , this . code ) ; } } function checkFile ( checker , file ) { if ( file . fileName . endsWith ( '.d.ts' ) ) { return ; } const sym = checker . typeChecker . getSymbolAtLocation ( file ) ; if ( ! sym ) return ; const exports = checker . typeChecker . getExportsOfModule ( sym ) ; for ( const exp of exports ) { let sym = exp ; if ( sym . flags & ts . SymbolFlags . Alias ) { sym = checker . typeChecker . getAliasedSymbol ( exp ) ; } const decl = sym . valueDeclaration ; if ( ! decl ) continue ; if ( decl . getSourceFile ( ) !== file ) { continue ; } if ( ! ts . isVariableDeclaration ( decl ) && ! ts . isBindingElement ( decl ) ) { continue ; } const isConst = ( ts . getCombinedNodeFlags ( decl ) & ts . NodeFlags . Const ) !== 0 ; if ( ! isConst ) { checker . addFailureAtNode ( exp . declarations [ 0 ] , `Exports must be const.` ) ; } } }