Skip to content

Commit

Permalink
feat(eval): Distinguish JSON rules from sidecar rules
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Jul 30, 2024
1 parent 93868ab commit 3a07bca
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
12 changes: 10 additions & 2 deletions bids-validator/src/issues/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 14 additions & 7 deletions bids-validator/src/schema/applyRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}`,
},
],
)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions bids-validator/src/schema/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 3a07bca

Please sign in to comment.