license import * as Lint from "tslint" ; import * as ts from "typescript" ; export function isMultilineText ( text ) { return /\n/ . test ( text ) ; } export function getDeleteFixForSpaceBetweenTokens ( firstNode , secondNode ) { const { parent } = firstNode ; const parentStart = parent ! . getStart ( ) ; const secondNodeStart = secondNode . getFullStart ( ) ; const firstNodeEnd = firstNode . getStart ( ) + firstNode . getWidth ( ) ; const secondNodeRelativeStart = secondNodeStart - parentStart ; const firstNodeRelativeEnd = firstNodeEnd - parentStart ; const parentText = parent ! . getText ( ) ; const trailingComments = ts . getTrailingCommentRanges ( parentText , firstNodeRelativeEnd ) ; const leadingComments = ts . getLeadingCommentRanges ( parentText , secondNodeRelativeStart ) ; const comments = ( trailingComments || [ ] ) . concat ( leadingComments || [ ] ) ; if ( secondNode . getStart ( ) - firstNode . getStart ( ) - firstNode . getWidth ( ) > getTotalCharCount ( comments ) ) { const replacements = comments . map ( ( comment ) => parentText . slice ( comment . pos , comment . end ) ) . join ( "" ) ; return new Lint . Replacement ( secondNodeStart , secondNode . getStart ( ) - secondNodeStart , replacements ) ; } else { return undefined ; } } function getTotalCharCount ( comments ) { return comments . map ( ( comment ) => comment . end - comment . pos ) . reduce ( ( l , r ) => l + r , 0 ) ; }