import { Diagnostic , DiagnosticSeverity , Range , Position } from 'vscode' ; import * as WriteGood from 'write-good' ; interface Suggestion { index : number ; offset : number ; reason : string ; } export function lintText ( content , wgConfig , startingLine = 0 , diagnostics = [ ] ) { if ( content == null ) return ; let lines = content . split ( /\r?\n/g ) ; lines . forEach ( ( line , lineCount ) => { let suggestions = WriteGood ( line , wgConfig ) ; suggestions . forEach ( ( suggestion , si ) => { let start = new Position ( lineCount + startingLine , suggestion . index ) ; let end = new Position ( lineCount + startingLine , suggestion . index + suggestion . offset ) ; diagnostics . push ( new Diagnostic ( new Range ( start , end ) , suggestion . reason , DiagnosticSeverity . Warning ) ) ; } ) ; } ) ; }