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'
5
5
6
- import type { ESLintReport } from './types' ;
6
+ import type { ESLintReport } from './types'
7
7
8
8
/**
9
9
* Parses a single ESLint report file and returns its contents as a JavaScript object
@@ -12,28 +12,28 @@ import type { ESLintReport } from './types';
12
12
*/
13
13
function parseReportFile ( reportFile : string ) : ESLintReport {
14
14
try {
15
- const reportPath = path . resolve ( reportFile ) ;
15
+ const reportPath = path . resolve ( reportFile )
16
16
17
17
// Check if file exists before trying to read it
18
18
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.` )
20
20
}
21
21
22
22
// 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' ) )
24
24
25
25
// Log success for debugging
26
- core . debug ( `Successfully parsed report file: ${ reportFile } ` ) ;
26
+ core . debug ( `Successfully parsed report file: ${ reportFile } ` )
27
27
28
- return reportParsed ;
28
+ return reportParsed
29
29
} catch ( error ) {
30
30
// Provide more specific error messages based on error type
31
31
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 } ` )
33
33
} else if ( error instanceof Error ) {
34
- throw new Error ( `Error processing "${ reportFile } ": ${ error . message } ` ) ;
34
+ throw new Error ( `Error processing "${ reportFile } ": ${ error . message } ` )
35
35
} else {
36
- throw new Error ( `Error parsing the report-json file "${ reportFile } ".` ) ;
36
+ throw new Error ( `Error parsing the report-json file "${ reportFile } ".` )
37
37
}
38
38
}
39
39
}
@@ -45,31 +45,31 @@ function parseReportFile(reportFile: string): ESLintReport {
45
45
*/
46
46
export default async function eslintJsonReportToJs ( reportFilesGlob : string ) : Promise < ESLintReport > {
47
47
// 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 } ` )
49
49
50
50
// 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 } )
52
52
53
53
// Get all matching files
54
- const files = await globber . glob ( ) ;
54
+ const files = await globber . glob ( )
55
55
56
- const uniqueFiles = [ ...new Set ( files ) ] ;
56
+ const uniqueFiles = [ ...new Set ( files ) ]
57
57
58
58
// 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` )
60
60
61
61
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 [ ]
64
64
}
65
65
66
66
// Process all files and flatten the results
67
67
// Use Promise.all to process files in parallel if there are multiple
68
68
if ( uniqueFiles . length === 1 ) {
69
69
// Optimize for common case of single file
70
- return parseReportFile ( files [ 0 ] ) ;
70
+ return parseReportFile ( files [ 0 ] )
71
71
} else {
72
72
// Process multiple files in parallel
73
- return ( await Promise . all ( uniqueFiles . map ( parseReportFile ) ) ) . flat ( ) ;
73
+ return ( await Promise . all ( uniqueFiles . map ( parseReportFile ) ) ) . flat ( )
74
74
}
75
75
}
0 commit comments