File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
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 @@ -216,6 +216,20 @@ export class BIDSContext implements Context {
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+ // @ts -ignore
222+ if ( json [ key ] !== this . sidecar [ key ] ) {
223+ const overrideLocation = this . sidecarKeyOrigin [ key ]
224+ this . dataset . issues . add ( {
225+ code : 'SIDECAR_FIELD_OVERRIDE' ,
226+ subCode : key ,
227+ location : overrideLocation ,
228+ // @ts -ignore
229+ issueMessage : `Sidecar key defined in ${ file . path } overrides previous value (${ json [ key ] } ) from ${ overrideLocation } ` ,
230+ } )
231+ }
232+ }
219233 this . sidecar = { ...json , ...this . sidecar }
220234 Object . keys ( json ) . map ( ( x ) => this . sidecarKeyOrigin [ x ] ??= file . path )
221235 }
You can’t perform that action at this time.
0 commit comments