From f7b6249ccff353922bd543db46c538abcc0cd057 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 5 Aug 2024 22:54:22 -0400 Subject: [PATCH] feat: Prune derivatives from main file tree Once broken into separate trees that can be validated, we can save time and false positives by removing the derivatives directory from the main validation context. --- bids-validator/src/validators/bids.ts | 32 ++++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/bids-validator/src/validators/bids.ts b/bids-validator/src/validators/bids.ts index 1a1cd87cd..f45bbe064 100644 --- a/bids-validator/src/validators/bids.ts +++ b/bids-validator/src/validators/bids.ts @@ -70,21 +70,27 @@ export async function validate( issues.addNonSchemaIssue('MISSING_DATASET_DESCRIPTION', [] as IssueFile[]) } - let derivatives: FileTree[] = [] + const bidsDerivatives: FileTree[] = [] + const nonstdDerivatives: FileTree[] = [] fileTree.directories = fileTree.directories.filter((dir) => { - if (dir.name === 'derivatives') { - dir.directories.map((deriv) => { - if ( - deriv.files.some( - (file: BIDSFile) => file.name === 'dataset_description.json', - ) - ) { - derivatives.push(deriv) - } - }) + if (dir.name !== 'derivatives') { return true } - return true + for (const deriv of dir.directories) { + if ( + deriv.files.some( + (file: BIDSFile) => file.name === 'dataset_description.json', + ) + ) { + // New root for the derivative dataset + deriv.parent = undefined + bidsDerivatives.push(deriv) + } else { + nonstdDerivatives.push(deriv) + } + } + // Remove derivatives from the main fileTree + return false }) for await (const context of walkFileTree(fileTree, issues, dsContext)) { @@ -111,7 +117,7 @@ export async function validate( let derivativesSummary: Record = {} await Promise.allSettled( - derivatives.map(async (deriv) => { + bidsDerivatives.map(async (deriv) => { derivativesSummary[deriv.name] = await validate(deriv, options) return derivativesSummary[deriv.name] }),