aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/config/eslintReport.cjs
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2023-04-09 00:53:53 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2023-04-09 00:53:53 +0200
commitc3fcc1ae3d2f680a973e66c138d9be7ae22eee26 (patch)
tree6a30b2478a30747cd7a2522acdff941394dea4e7 /subprojects/frontend/config/eslintReport.cjs
parentbuild: always prefer slf4j instead of log4j 1.x (diff)
downloadrefinery-c3fcc1ae3d2f680a973e66c138d9be7ae22eee26.tar.gz
refinery-c3fcc1ae3d2f680a973e66c138d9be7ae22eee26.tar.zst
refinery-c3fcc1ae3d2f680a973e66c138d9be7ae22eee26.zip
build: refactor frontend build
* Always write ESLint output to a file in addition to the console to make the lintFrontend task cacheable in Gradle (according to the output file). * Make sure frontend task inputs are declared properly for caching. * Make sure Typescript type checking is incremental. * Do not use @tsconfig, because both Vite and SonarScanner have problems with extending tsconfig files from Yarn PnP modules.
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);