Skip to content

Commit a54b4d7

Browse files
Fix amount of files
1 parent 082a84c commit a54b4d7

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/eslintJsonReportToJs.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import * as glob from '@actions/glob'
2-
import fs from 'fs'
3-
import path from 'path'
4-
import * as core from '@actions/core'
1+
import * as glob from '@actions/glob';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import * as core from '@actions/core';
55

6-
import type {ESLintReport} from './types'
6+
import type { ESLintReport } from './types';
77

88
/**
99
* Parses a single ESLint report file and returns its contents as a JavaScript object
@@ -12,28 +12,28 @@ import type {ESLintReport} from './types'
1212
*/
1313
function parseReportFile(reportFile: string): ESLintReport {
1414
try {
15-
const reportPath = path.resolve(reportFile)
15+
const reportPath = path.resolve(reportFile);
1616

1717
// Check if file exists before trying to read it
1818
if (!fs.existsSync(reportPath)) {
19-
throw new Error(`The report-json file "${reportFile}" could not be resolved.`)
19+
throw new Error(`The report-json file "${reportFile}" could not be resolved.`);
2020
}
2121

2222
// Read and parse the file in one operation
23-
const reportParsed = JSON.parse(fs.readFileSync(reportPath, 'utf-8'))
23+
const reportParsed = JSON.parse(fs.readFileSync(reportPath, 'utf-8'));
2424

2525
// Log success for debugging
26-
core.debug(`Successfully parsed report file: ${reportFile}`)
26+
core.debug(`Successfully parsed report file: ${reportFile}`);
2727

28-
return reportParsed
28+
return reportParsed;
2929
} catch (error) {
3030
// Provide more specific error messages based on error type
3131
if (error instanceof SyntaxError) {
32-
throw new Error(`Invalid JSON in report file "${reportFile}": ${error.message}`)
32+
throw new Error(`Invalid JSON in report file "${reportFile}": ${error.message}`);
3333
} else if (error instanceof Error) {
34-
throw new Error(`Error processing "${reportFile}": ${error.message}`)
34+
throw new Error(`Error processing "${reportFile}": ${error.message}`);
3535
} else {
36-
throw new Error(`Error parsing the report-json file "${reportFile}".`)
36+
throw new Error(`Error parsing the report-json file "${reportFile}".`);
3737
}
3838
}
3939
}
@@ -45,29 +45,31 @@ function parseReportFile(reportFile: string): ESLintReport {
4545
*/
4646
export default async function eslintJsonReportToJs(reportFilesGlob: string): Promise<ESLintReport> {
4747
// Log the start of processing
48-
core.debug(`Processing ESLint report files matching pattern: ${reportFilesGlob}`)
48+
core.debug(`Processing ESLint report files matching pattern: ${reportFilesGlob}`);
4949

5050
// Create globber with concurrency to improve performance on large numbers of files
51-
const globber = await glob.create(reportFilesGlob, {matchDirectories: false})
51+
const globber = await glob.create(reportFilesGlob, { matchDirectories: false });
5252

5353
// Get all matching files
54-
const files = await globber.glob()
54+
const files = await globber.glob();
55+
56+
const uniqueFiles = [...new Set(files)];
5557

5658
// Log number of files found
57-
core.debug(`Found ${files.length} ESLint report files to process`)
59+
core.debug(`Found ${files.length} ESLint report files to process`);
5860

59-
if (files.length === 0) {
60-
core.warning(`No ESLint report files found matching pattern: ${reportFilesGlob}`)
61-
return []
61+
if (uniqueFiles.length === 0) {
62+
core.warning(`No ESLint report files found matching pattern: ${reportFilesGlob}`);
63+
return [];
6264
}
6365

6466
// Process all files and flatten the results
6567
// Use Promise.all to process files in parallel if there are multiple
66-
if (files.length === 1) {
68+
if (uniqueFiles.length === 1) {
6769
// Optimize for common case of single file
68-
return parseReportFile(files[0])
70+
return parseReportFile(files[0]);
6971
} else {
7072
// Process multiple files in parallel
71-
return (await Promise.all(files.map(parseReportFile))).flat()
73+
return (await Promise.all(uniqueFiles.map(parseReportFile))).flat();
7274
}
7375
}

0 commit comments

Comments
 (0)