-
Notifications
You must be signed in to change notification settings - Fork 15
/
runLint.js
40 lines (36 loc) · 1.1 KB
/
runLint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict'
const { ESLint } = require('eslint')
const path = require('path')
const runLintWithFixtures = async (configFile, target) => {
const eslint = new ESLint({
overrideConfigFile: configFile,
ignore: false,
useEslintrc: false,
extensions: ['.js', '.jsx', '.ts', '.tsx'],
})
const lintResult = await eslint.lintFiles([target])
// console.log(JSON.stringify(lintResult, null, 2))
return lintResult.reduce((results, { filePath, messages }) => {
return Object.assign(results, {
[path.basename(filePath)]: messages.reduce(
(resultPerFile, { severity, ruleId }) => {
switch (severity) {
// warning
case 1:
resultPerFile.warnings.push(ruleId)
break
// errors
case 2:
resultPerFile.errors.push(ruleId)
break
default:
throw new Error(`Got an unknown severity: ${severity}(${ruleId})`)
}
return resultPerFile
},
{ warnings: [], errors: [] },
),
})
}, {})
}
module.exports = runLintWithFixtures