Skip to content

Commit be1894d

Browse files
author
Sergei Garin
committed
build
1 parent a54b4d7 commit be1894d

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

dist/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56307,21 +56307,22 @@ async function eslintJsonReportToJs(reportFilesGlob) {
5630756307
const globber = await glob.create(reportFilesGlob, { matchDirectories: false });
5630856308
// Get all matching files
5630956309
const files = await globber.glob();
56310+
const uniqueFiles = [...new Set(files)];
5631056311
// Log number of files found
5631156312
core.debug(`Found ${files.length} ESLint report files to process`);
56312-
if (files.length === 0) {
56313+
if (uniqueFiles.length === 0) {
5631356314
core.warning(`No ESLint report files found matching pattern: ${reportFilesGlob}`);
5631456315
return [];
5631556316
}
5631656317
// Process all files and flatten the results
5631756318
// Use Promise.all to process files in parallel if there are multiple
56318-
if (files.length === 1) {
56319+
if (uniqueFiles.length === 1) {
5631956320
// Optimize for common case of single file
5632056321
return parseReportFile(files[0]);
5632156322
}
5632256323
else {
5632356324
// Process multiple files in parallel
56324-
return (await Promise.all(files.map(parseReportFile))).flat();
56325+
return (await Promise.all(uniqueFiles.map(parseReportFile))).flat();
5632556326
}
5632656327
}
5632756328
exports["default"] = eslintJsonReportToJs;

src/eslintJsonReportToJs.ts

Lines changed: 22 additions & 22 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,31 +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()
5555

56-
const uniqueFiles = [...new Set(files)];
56+
const uniqueFiles = [...new Set(files)]
5757

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

6161
if (uniqueFiles.length === 0) {
62-
core.warning(`No ESLint report files found matching pattern: ${reportFilesGlob}`);
63-
return [];
62+
core.warning(`No ESLint report files found matching pattern: ${reportFilesGlob}`)
63+
return []
6464
}
6565

6666
// Process all files and flatten the results
6767
// Use Promise.all to process files in parallel if there are multiple
6868
if (uniqueFiles.length === 1) {
6969
// Optimize for common case of single file
70-
return parseReportFile(files[0]);
70+
return parseReportFile(files[0])
7171
} else {
7272
// Process multiple files in parallel
73-
return (await Promise.all(uniqueFiles.map(parseReportFile))).flat();
73+
return (await Promise.all(uniqueFiles.map(parseReportFile))).flat()
7474
}
7575
}

0 commit comments

Comments
 (0)