Support custom output file for converted JSON report
Problem:
Currently, the formatter only supports outputting results to a single, hardcoded file name (e.g., gl-codequality.json). This causes issues in an Nx monorepo setup, where multiple linting tasks can run in parallel (for different projects/packages). Since each task writes to the same file, the results are overwritten, and only the errors from the last completed task are preserved. This makes it impossible to collect and review all linting errors across projects.
In Nx, each project can define its own lint job in project.json, for example:
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"format": "gitlab",
"outputFile": "./quality/my-job-lint.json"
}
}
It would be very helpful to allow the output file name to be customized via an environment variable (e.g., ESLINT_CUSTOM_OUTPUT). This would enable each linting task to write its results to a unique file, preventing overwrites and supporting parallel execution in monorepos. It could look like this if you are okay with using env variable:
async function eslintFormatterGitLab(results, data) {
let outputPath = process.env.ESLINT_CODE_QUALITY_REPORT
const projectDir = process.env.CI_PROJECT_DIR ?? data.cwd
const jobName = process.env.CI_JOB_NAME
const issues = convert(results, data, projectDir)
const formattedIssues = `${JSON.stringify(issues, null, 2)}\n`;
if (process.env.ESLINT_CUSTOM_OUTPUT === 'true') {
return formattedIssues;
}
if (jobName || outputPath) {
const issues = convert(results, data, projectDir)
outputPath ||= await getOutputPath(projectDir, jobName)
const dir = dirname(outputPath)
await mkdir(dir, { recursive: true })
await writeFile(outputPath, formattedIssues)
}
return gitlabConsoleFormatter(results, projectDir)
}
Combining these individual reports into a single file can be handled as a separate step by the user or CI pipeline. This package does not need to provide functionality for merging the reports.