MCPcopy
hub / github.com/ampproject/amphtml / runLinter

Function runLinter

build-system/tasks/lint.js:27–63  ·  view source on GitHub ↗

* Runs the linter on the given set of files. * @param {Array } filesToLint * @return {Promise }

(filesToLint)

Source from the content-addressed store, hash-verified

25 * @return {Promise<void>}
26 */
27async 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.

Callers 1

lintFunction · 0.85

Calls 8

logLocalDevFunction · 0.85
greenFunction · 0.85
logOnSameLineFunction · 0.85
logOnSameLineLocalDevFunction · 0.85
yellowFunction · 0.85
cyanFunction · 0.85
summarizeResultsFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected