* Runs the linter on the given set of files. * @param {Array } filesToLint * @return {Promise }
(filesToLint)
| 25 | * @return {Promise<void>} |
| 26 | */ |
| 27 | async function runLinter(filesToLint) { |
| 28 | logLocalDev(green('Starting linter...')); |
| 29 | const eslint = new ESLint(options); |
| 30 | const results = { |
| 31 | errorCount: 0, |
| 32 | warningCount: 0, |
| 33 | }; |
| 34 | const fixedFiles = {}; |
| 35 | for (const file of filesToLint) { |
| 36 | const text = fs.readFileSync(file, 'utf-8'); |
| 37 | const lintResult = await eslint.lintText(text, {filePath: file}); |
| 38 | const result = lintResult[0]; |
| 39 | if (!result) { |
| 40 | continue; // File was ignored |
| 41 | } |
| 42 | results.errorCount += result.errorCount; |
| 43 | results.warningCount += result.warningCount; |
| 44 | const formatter = await eslint.loadFormatter('stylish'); |
| 45 | const resultText = (await formatter.format(lintResult)) |
| 46 | .replace(`${process.cwd()}/`, '') |
| 47 | .trim(); |
| 48 | if (resultText.length) { |
| 49 | logOnSameLine(resultText); |
| 50 | } |
| 51 | if (argv.fix) { |
| 52 | await ESLint.outputFixes(lintResult); |
| 53 | } |
| 54 | logOnSameLineLocalDev(green('Linted: ') + file); |
| 55 | if (options.fix && result.output) { |
| 56 | const status = |
| 57 | result.errorCount == 0 ? green('Fixed: ') : yellow('Partially fixed: '); |
| 58 | logOnSameLine(status + cyan(file)); |
| 59 | fixedFiles[file] = status; |
| 60 | } |
| 61 | } |
| 62 | summarizeResults(results, fixedFiles); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Summarize the results of linting all files. |
no test coverage detected