diff --git a/bids-validator/src/issues/list.ts b/bids-validator/src/issues/list.ts index 8d31a9cc8..aebcf77d1 100644 --- a/bids-validator/src/issues/list.ts +++ b/bids-validator/src/issues/list.ts @@ -36,11 +36,19 @@ export const filenameIssues: IssueDefinitionRecord = { }, JSON_KEY_REQUIRED: { severity: 'error', - reason: "A data file's JSON sidecar is missing a key listed as required.", + reason: 'A JSON flle is missing a key listed as required.', }, JSON_KEY_RECOMMENDED: { severity: 'warning', - reason: 'A data files JSON sidecar is missing a key listed as recommended.', + reason: 'A JSON file is missing a key listed as recommended.', + }, + SIDECAR_KEY_REQUIRED: { + severity: 'error', + reason: "A data file's JSON sidecar is missing a key listed as required.", + }, + SIDECAR_KEY_RECOMMENDED: { + severity: 'warning', + reason: "A data file's JSON sidecar is missing a key listed as recommended.", }, TSV_ERROR: { severity: 'error', diff --git a/bids-validator/src/schema/applyRules.ts b/bids-validator/src/schema/applyRules.ts index 0e1231ac7..afb42cf4e 100644 --- a/bids-validator/src/schema/applyRules.ts +++ b/bids-validator/src/schema/applyRules.ts @@ -412,6 +412,10 @@ function evalJsonCheck( schema: GenericSchema, schemaPath: string, ): void { + const sidecarRule: bool = schemaPath.match(/rules\.sidecar/) + // Sidecar rules apply specifically to data files, as JSON files cannot have sidecars + // Count on other JSON rules to use selectors to match the correct files + if (context.extension === '.json' && sidecarRule) return for (const [key, requirement] of Object.entries(rule.fields)) { const severity = getFieldSeverity(requirement, context) // @ts-expect-error @@ -425,19 +429,22 @@ function evalJsonCheck( files: [{ ...context.file }], }) } else if (severity === 'error') { - context.issues.addNonSchemaIssue('JSON_KEY_REQUIRED', [ + context.issues.addNonSchemaIssue(sidecar ? 'SIDECAR_KEY_REQUIRED' : 'JSON_KEY_REQUIRED', [ { ...context.file, evidence: `missing ${keyName} as per ${schemaPath}`, }, ]) } else if (severity === 'warning') { - context.issues.addNonSchemaIssue('JSON_KEY_RECOMMENDED', [ - { - ...context.file, - evidence: `missing ${keyName} as per ${schemaPath}`, - }, - ]) + context.issues.addNonSchemaIssue( + sidecar ? 'SIDECAR_KEY_RECOMMENDED' : 'JSON_KEY_RECOMMENDED', + [ + { + ...context.file, + evidence: `missing ${keyName} as per ${schemaPath}`, + }, + ], + ) } } } diff --git a/bids-validator/src/schema/context.ts b/bids-validator/src/schema/context.ts index d7d0c37d0..7d830e70b 100644 --- a/bids-validator/src/schema/context.ts +++ b/bids-validator/src/schema/context.ts @@ -125,6 +125,9 @@ export class BIDSContext implements Context { * json sidecars found. */ async loadSidecar(fileTree?: FileTree) { + if (this.extension === '.json') { + return + } if (!fileTree) { fileTree = this.fileTree }