Add ability to use different filters in findSarifFilesInDir

This commit is contained in:
Michael B. Gale
2025-06-17 14:21:41 +01:00
parent 320f7b0fd6
commit 22444a650f
3 changed files with 14 additions and 5 deletions

View File

@@ -376,14 +376,21 @@ export interface UploadResult {
sarifID: string;
}
const qualityIsSarif = (name: string) => name.endsWith(".quality.sarif");
const defaultIsSarif = (name: string) =>
name.endsWith(".sarif") && !qualityIsSarif(name);
// Recursively walks a directory and returns all SARIF files it finds.
// Does not follow symlinks.
export function findSarifFilesInDir(sarifPath: string): string[] {
export function findSarifFilesInDir(
sarifPath: string,
isSarif: (name: string) => boolean = defaultIsSarif,
): string[] {
const sarifFiles: string[] = [];
const walkSarifFiles = (dir: string) => {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isFile() && entry.name.endsWith(".sarif")) {
if (entry.isFile() && isSarif(entry.name)) {
sarifFiles.push(path.resolve(dir, entry.name));
} else if (entry.isDirectory()) {
walkSarifFiles(path.resolve(dir, entry.name));