From 67015847933eddda8ceafff9eb5331cc0bfad621 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 5 Aug 2024 11:37:22 -0400 Subject: [PATCH] feat: Implement SIDECAR_WITHOUT_DATAFILE --- bids-validator/src/issues/list.ts | 4 ++++ bids-validator/src/validators/bids.ts | 3 ++- .../src/validators/internal/unusedFile.ts | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bids-validator/src/issues/list.ts b/bids-validator/src/issues/list.ts index 39be04ad3..5c80e51ea 100644 --- a/bids-validator/src/issues/list.ts +++ b/bids-validator/src/issues/list.ts @@ -123,6 +123,10 @@ export const bidsIssues: IssueDefinitionRecord = { reason: 'There are files in the /stimuli directory that are not utilized in any _events.tsv file.', }, + SIDECAR_WITHOUT_DATAFILE: { + severity: 'error', + reason: 'A json sidecar file was found without a corresponding data file', + }, } const hedIssues: IssueDefinitionRecord = { diff --git a/bids-validator/src/validators/bids.ts b/bids-validator/src/validators/bids.ts index 2f98b1f3e..1a1cd87cd 100644 --- a/bids-validator/src/validators/bids.ts +++ b/bids-validator/src/validators/bids.ts @@ -12,7 +12,7 @@ import { filenameIdentify } from './filenameIdentify.ts' import { filenameValidate } from './filenameValidate.ts' import { DatasetIssues } from '../issues/datasetIssues.ts' import { emptyFile } from './internal/emptyFile.ts' -import { unusedStimulus } from './internal/unusedFile.ts' +import { sidecarWithoutDatafile, unusedStimulus } from './internal/unusedFile.ts' import { BIDSContext, BIDSContextDataset } from '../schema/context.ts' import { parseOptions } from '../setup/options.ts' import { hedValidate } from './hed.ts' @@ -31,6 +31,7 @@ const perContextChecks: ContextCheckFunction[] = [ const perDSChecks: DSCheckFunction[] = [ (...args) => Promise.resolve(unusedStimulus(...args)), + (...args) => Promise.resolve(sidecarWithoutDatafile(...args)), ] /** diff --git a/bids-validator/src/validators/internal/unusedFile.ts b/bids-validator/src/validators/internal/unusedFile.ts index 03876b68b..ef1bb8d51 100644 --- a/bids-validator/src/validators/internal/unusedFile.ts +++ b/bids-validator/src/validators/internal/unusedFile.ts @@ -30,3 +30,19 @@ export function unusedStimulus( issues.addNonSchemaIssue('UNUSED_STIMULUS', unusedStimuli) } } + +const standalone_json = ['dataset_description.json', 'genetic_info.json'] + +export function sidecarWithoutDatafile( + schema: GenericSchema, + dsContext: BIDSContextDataset, + issues: DatasetIssues, +): void { + const unusedSidecars = [...walkFileTree(dsContext.tree)].filter( + (file) => (!file.viewed && file.name.endsWith('.json') && + !standalone_json.includes(file.name)), + ) + if (unusedSidecars.length) { + issues.addNonSchemaIssue('SIDECAR_WITHOUT_DATAFILE', unusedSidecars) + } +}