import * as ts from 'typescript' ; /**
 * Utility methods for the chai.related rules.
 */ export namespace ChaiUtils { export function isExpectInvocation ( node ) { const callExpression = getLeftMostCallExpression ( node ) ; if ( callExpression == null ) { return false ; } return /.*\.?expect/ . test ( callExpression . expression . getText ( ) ) ; } export function getLeftMostCallExpression ( node ) { let leftSide = node . expression ; while ( leftSide != null ) { if ( leftSide . kind === ts . SyntaxKind . CallExpression ) { return < ts . CallExpression > leftSide ; } else if ( leftSide . kind === ts . SyntaxKind . PropertyAccessExpression ) { leftSide = ( < ts . PropertyAccessExpression > leftSide ) . expression ; } else { return null ; } } return null ; } export function getFirstExpectCallParameter ( node ) { const expectCall = ChaiUtils . getLeftMostCallExpression ( node ) ; if ( expectCall . arguments . length > 0 ) { return expectCall . arguments [ 0 ] ; } return null ; } export function getFirstExpectationParameter ( node ) { if ( node . arguments . length > 0 ) { return node . arguments [ 0 ] ; } return null ; } export function isEqualsInvocation ( propExpression ) { return /equal|equals|eq|eql|eqs/ . test ( propExpression . name . getText ( ) ) ; } }