import { CLIEngine } from 'eslint' ; import { REPO_ROOT } from '@kbn/utils' ; import { createFailError , ToolingLog } from '@kbn/dev-utils' ; import { File } from '../file' ; param { ToolingLog } log param { Array < File > } files return { undefined } export function lintFiles ( log , files , { fix } = { } ) { const cli = new CLIEngine ( { cache : true , cwd : REPO_ROOT , fix , } ) ; const paths = files . map ( ( file ) => file . getRelativePath ( ) ) ; const report = cli . executeOnFiles ( paths ) ; if ( fix ) { CLIEngine . outputFixes ( report ) ; } const failTypes = [ ] ; if ( report . errorCount > 0 ) failTypes . push ( 'errors' ) ; if ( report . warningCount > 0 ) failTypes . push ( 'warning' ) ; if ( ! failTypes . length ) { log . success ( '[eslint] %d files linted successfully' , files . length ) ; return ; } log . error ( cli . getFormatter ( ) ( report . results ) ) ; throw createFailError ( `[eslint] ${ failTypes . join ( ' & ' ) }` ) ; }