@@ -81,6 +81,11 @@ export type SarifShortDescription = {
8181 text : string ;
8282}
8383
84+ type ValidateParams = {
85+ dataPath : string ;
86+ rulesPath : string ;
87+ }
88+
8489const formatOutput = ( { result, rulesNames, dataNames } : FormatOutputParams ) : SarifReport => {
8590 const dataPattern = / D A T A _ S T D I N \[ ( \d + ) \] / g;
8691 const rulesPattern = / R U L E S _ S T D I N \[ ( \d + ) \] \/ D E F A U L T / g;
@@ -90,7 +95,7 @@ const formatOutput = ({ result, rulesNames, dataNames }: FormatOutputParams): Sa
9095 const fileIndex = parseInt ( index , 10 ) - 1 ;
9196 const fileName = dataNames [ fileIndex ] ;
9297
93- return fileName ? fileName . split ( isWindows ? '\\' : '/' ) . join ( '' ) : match ;
98+ return fileName ? ( isWindows ? fileName . split ( '\\' ) . join ( '/' ) : fileName ) : match ;
9499 } ) . replace ( rulesPattern , ( match : string , index : string ) => {
95100 const ruleIndex = parseInt ( index , 10 ) - 1 ;
96101 const ruleName = rulesNames [ ruleIndex ] ;
@@ -104,31 +109,26 @@ const formatOutput = ({ result, rulesNames, dataNames }: FormatOutputParams): Sa
104109 return JSON . parse ( output ) ;
105110} ;
106111
107- async function readFiles ( dirPath : string , supportedExtensions : string [ ] ) : Promise < TraversalResult > {
108- const fileNames : string [ ] = [ ] ;
109- const fileContents : string [ ] = [ ] ;
110-
111- const files = await fs . promises . readdir ( dirPath , { withFileTypes : true } ) ;
112- const readPromises = files . map ( async ( file ) => {
113- const filePath = path . join ( dirPath , file . name ) ;
114- if ( ! file . isDirectory ( ) && supportedExtensions . includes ( path . extname ( filePath ) ) ) {
115- const content = await fs . promises . readFile ( filePath , 'utf8' ) ;
116- fileNames . push ( filePath ) ;
117- fileContents . push ( content ) ;
118- }
119- } ) ;
120- await Promise . all ( readPromises ) ;
121-
122- return {
123- fileContents,
124- fileNames,
125- } ;
126- }
127-
128- type ValidateParams = {
129- dataPath : string ;
130- rulesPath : string ;
131- }
112+ async function readFiles ( dirPath : string , supportedExtensions : string [ ] ) : Promise < TraversalResult > {
113+ const fileNames : string [ ] = [ ] ;
114+ const fileContents : string [ ] = [ ] ;
115+
116+ const files = await fs . promises . readdir ( dirPath , { withFileTypes : true } ) ;
117+ const readPromises = files . map ( async ( file ) => {
118+ const filePath = path . join ( dirPath , file . name ) ;
119+ if ( ! file . isDirectory ( ) && supportedExtensions . includes ( path . extname ( filePath ) ) ) {
120+ const content = await fs . promises . readFile ( filePath , 'utf8' ) ;
121+ fileNames . push ( filePath ) ;
122+ fileContents . push ( content ) ;
123+ }
124+ } ) ;
125+ await Promise . all ( readPromises ) ;
126+
127+ return {
128+ fileContents,
129+ fileNames,
130+ } ;
131+ }
132132
133133export const validate = async ( { rulesPath, dataPath } : ValidateParams ) : Promise < SarifReport > => {
134134 const rulesResult = await readFiles ( rulesPath , RULE_FILE_SUPPORTED_EXTENSIONS ) ;
0 commit comments