Skip to content

Commit

Permalink
feat: Implement SIDECAR_WITHOUT_DATAFILE
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Aug 6, 2024
1 parent 08ee33b commit 6701584
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bids-validator/src/issues/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion bids-validator/src/validators/bids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -31,6 +31,7 @@ const perContextChecks: ContextCheckFunction[] = [

const perDSChecks: DSCheckFunction[] = [
(...args) => Promise.resolve(unusedStimulus(...args)),
(...args) => Promise.resolve(sidecarWithoutDatafile(...args)),
]

/**
Expand Down
16 changes: 16 additions & 0 deletions bids-validator/src/validators/internal/unusedFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 6701584

Please sign in to comment.