import { LinterGetOffensesFunction , LinterOffense , LinterOffenseSeverity , } from "vscode-linter-api" ; export interface CodeSnifferPayload { files : { [ key ] : CodeSnifferFilePayload ; } ; } export interface CodeSnifferFilePayload { messages : CodeSnifferOffense [ ] ; } export interface CodeSnifferOffense { message : string ; source : string ; severity : number ; fixable : boolean ; type : string ; line : number ; column : number ; } const offenseSeverity = { error : LinterOffenseSeverity . error , warning : LinterOffenseSeverity . warning , } ; export const getOffenses = ( { stdout , uri } ) => { const result = JSON . parse ( stdout ) ; const offenses = [ ] ; Object . values ( result . files ) [ 0 ] . messages . forEach ( ( offense ) => { const lineStart = Math . max ( 0 , offense . line - 1 ) ; const columnStart = Math . max ( 0 , offense . column - 1 ) ; offenses . push ( { uri , lineStart , lineEnd : lineStart , columnStart , columnEnd : columnStart , message : offense . message , code : offense . source , source : "php-code-sniffer" , correctable : offense . fixable , severity : offenseSeverity [ offense . severity ] , } ) ; } ) ; return offenses ; } ;