File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,10 @@ export const bidsIssues: IssueDefinitionRecord = {
166166 severity : 'error' ,
167167 reason : 'A json sidecar file was found without a corresponding data file' ,
168168 } ,
169+ SIDECAR_FIELD_OVERRIDE : {
170+ severity : 'warning' ,
171+ reason : 'Sidecar files should not override values assigned at a higher level.' ,
172+ } ,
169173 BLACKLISTED_MODALITY : {
170174 severity : 'error' ,
171175 reason : 'The modality in this file is blacklisted through validator configuration.' ,
Original file line number Diff line number Diff line change 1- import { assert , assertObjectMatch } from '@std/assert'
1+ import { assert , assertEquals , assertObjectMatch } from '@std/assert'
22import type { DatasetIssues } from '../issues/datasetIssues.ts'
33import { BIDSContext } from './context.ts'
44import { dataFile , rootFileTree } from './fixtures.test.ts'
@@ -21,6 +21,12 @@ Deno.test('test context LoadSidecar', async (t) => {
2121 anatValue : 'anat' ,
2222 } )
2323 } )
24+ await t . step ( 'Warnings are emitted for overriding sidecar fields' , ( ) => {
25+ assertEquals (
26+ context . dataset . issues . get ( { code : 'SIDECAR_FIELD_OVERRIDE' } ) . length ,
27+ 2 ,
28+ )
29+ } )
2430} )
2531
2632Deno . test ( 'test context loadSubjects' , async ( t ) => {
Original file line number Diff line number Diff line change @@ -208,14 +208,26 @@ export class BIDSContext implements Context {
208208 }
209209 }
210210 for ( const file of sidecars ) {
211- const json = await loadJSON ( file ) . catch ( ( error ) => {
211+ const json = await loadJSON ( file ) . catch ( ( error ) : Record < string , unknown > => {
212212 if ( error . key ) {
213213 this . dataset . issues . add ( { code : error . key , location : file . path } )
214214 return { }
215215 } else {
216216 throw error
217217 }
218218 } )
219+ const overrides = Object . keys ( this . sidecar ) . filter ( ( x ) => Object . hasOwn ( json , x ) )
220+ for ( const key of overrides ) {
221+ if ( json [ key ] !== this . sidecar [ key ] ) {
222+ const overrideLocation = this . sidecarKeyOrigin [ key ]
223+ this . dataset . issues . add ( {
224+ code : 'SIDECAR_FIELD_OVERRIDE' ,
225+ subCode : key ,
226+ location : overrideLocation ,
227+ issueMessage : `Sidecar key defined in ${ file . path } overrides previous value (${ json [ key ] } ) from ${ overrideLocation } ` ,
228+ } )
229+ }
230+ }
219231 this . sidecar = { ...json , ...this . sidecar }
220232 Object . keys ( json ) . map ( ( x ) => this . sidecarKeyOrigin [ x ] ??= file . path )
221233 }
You can’t perform that action at this time.
0 commit comments