Skip to content

Commit

Permalink
feat: Prune derivatives from main file tree
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
effigies committed Aug 6, 2024
1 parent 6701584 commit f7b6249
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions bids-validator/src/validators/bids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -111,7 +117,7 @@ export async function validate(

let derivativesSummary: Record<string, ValidationResult> = {}
await Promise.allSettled(
derivatives.map(async (deriv) => {
bidsDerivatives.map(async (deriv) => {
derivativesSummary[deriv.name] = await validate(deriv, options)
return derivativesSummary[deriv.name]
}),
Expand Down

0 comments on commit f7b6249

Please sign in to comment.