aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/config/eslintReport.cjs
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/config/eslintReport.cjs')
-rw-r--r--subprojects/frontend/config/eslintReport.cjs52
1 files changed, 52 insertions, 0 deletions
diff --git a/subprojects/frontend/config/eslintReport.cjs b/subprojects/frontend/config/eslintReport.cjs
new file mode 100644
index 00000000..5bf6a041
--- /dev/null
+++ b/subprojects/frontend/config/eslintReport.cjs
@@ -0,0 +1,52 @@
1const { writeFile } = require('node:fs/promises');
2const path = require('node:path');
3const { Readable } = require('node:stream');
4const { pipeline } = require('node:stream/promises');
5
6const { ESLint } = require('eslint');
7
8const rootDir = path.join(__dirname, '..');
9
10/**
11 * Write ESLint report to console.
12 *
13 * @param cli {import('eslint').ESLint} The ESLint CLI.
14 * @param report {import('eslint').ESLint.LintResult[]} The ESLint report.
15 * @return {Promise<void>} A promise that resolves when the report is finished.
16 */
17async function reportToConsole(cli, report) {
18 const stylishFormatter = await cli.loadFormatter('stylish');
19 const output = new Readable();
20 output.push(await stylishFormatter.format(report));
21 output.push(null);
22 return pipeline(output, process.stdout);
23}
24
25/**
26 * Write ESLint report to the <code>build</code> directory.
27 *
28 * @param cli {import('eslint').ESLint} The ESLint CLI.
29 * @param report {import('eslint').ESLint.LintResult[]} The ESLint report.
30 * @return {Promise<void>} A promise that resolves when the report is finished.
31 */
32async function reportToJson(cli, report) {
33 const jsonFormatter = await cli.loadFormatter('json');
34 const json = await jsonFormatter.format(report);
35 const reportPath = path.join(rootDir, 'build', 'eslint.json');
36 return writeFile(reportPath, json, 'utf-8');
37}
38
39async function createReport() {
40 const cli = new ESLint({
41 useEslintrc: true,
42 cwd: rootDir,
43 });
44 const report = await cli.lintFiles('.');
45 await Promise.all([reportToConsole(cli, report), reportToJson(cli, report)]);
46
47 if (report.some((entry) => entry.errorCount > 0)) {
48 process.exitCode = 1;
49 }
50}
51
52createReport().catch(console.error);