Worker Threads + ESlint.
--experimental-worker
flag.
$ yarn add weslint
type TWeslintOptions = {
files: string[],
maxThreadCount?: number,
formatter?: string,
eslint?: CLIEngine.Options,
}
type TWeslintResult = {
hasErrors: boolean,
hasWarnings: boolean,
formattedReport: string,
}
const weslint: (options: TWeslintOptions) => Promise<TWeslintResult>
files
– array of file pathsmaxThreadCount
–cpus().length
by defaultformatter
– ESLint formatter nameeslint
– ESLint CLIEngine options
import { weslint } from 'weslint'
const result = await weslint({
files: ['./file1.ts', './file2.ts']
})
if (result.hasErrors || result.hasWarnings) {
console.log(result.formattedReport)
}
if (result.hasErrors) {
throw new Error('oops')
}