Worker Threads + ESlint
npm install weslintWorker Threads + ESlint.
:warning: Node.js v10 needs an --experimental-worker flag.
``sh`
$ yarn add weslint
`ts
type TWeslintOptions = {
files: string[],
maxThreadCount?: number,
formatter?: string,
eslint?: CLIEngine.Options,
}
type TWeslintResult = {
hasErrors: boolean,
hasWarnings: boolean,
formattedReport: string,
}
const weslint: (options: TWeslintOptions) => Promise
`
* files – array of file pathsmaxThreadCount
* – cpus().length by defaultformatter
* – ESLint formatter nameeslint
* – ESLint CLIEngine options
`ts
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')
}
``