Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed implementation of HED validator #229

Merged
merged 14 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bids/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import castArray from 'lodash/castArray'
import semver from 'semver'

import { buildSchemas } from '../schema/init'
import { generateIssue, IssueError } from '../common/issues/issues'
import { IssueError } from '../common/issues/issues'
import { SchemaSpec, SchemasSpec } from '../schema/specs'

const alphabeticRegExp = new RegExp('^[a-zA-Z]+$')
Expand Down
21 changes: 17 additions & 4 deletions bids/types/basic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BidsHedIssue } from './issues'
import { generateIssue } from '../../common/issues/issues'

/**
* A BIDS file.
Expand Down Expand Up @@ -36,15 +37,27 @@ export class BidsFile {
return false
}

validate(hedSchemas) {
/**
* Validate this validator's tsv file
*
* @param {Schemas} schemas
* @returns {BidsIssue[]} Any issues found during validation of this TSV file.
*/
validate(schemas) {
if (!this.hasHedData()) {
return []
} else if (hedSchemas === null) {
return null
}
if (!schemas) {
BidsHedIssue.fromHedIssue(
generateIssue('genericError', {
message: 'BIDS file HED validation requires a HED schema, but the schema received was null.',
}),
{ path: this.file.file, relativePath: this.file.file },
)
}

try {
const validator = new this.validatorClass(this, hedSchemas)
const validator = new this.validatorClass(this, schemas)
return validator.validate()
} catch (internalError) {
return BidsHedIssue.fromHedIssues(internalError, this.file)
Expand Down
4 changes: 1 addition & 3 deletions bids/types/dataset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { fallbackDatasetDescription } from './json'

export class BidsDataset {
/**
* The dataset's event file data.
Expand All @@ -22,7 +20,7 @@ export class BidsDataset {
*/
datasetRootDirectory

constructor(eventData, sidecarData, datasetDescription = fallbackDatasetDescription, datasetRootDirectory = null) {
constructor(eventData, sidecarData, datasetDescription, datasetRootDirectory = null) {
this.eventData = eventData
this.sidecarData = sidecarData
this.datasetDescription = datasetDescription
Expand Down
2 changes: 1 addition & 1 deletion bids/types/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class BidsIssue {
* Determine if any of the passed issues are errors.
*
* @param {BidsIssue[]} issues A list of issues.
* @return {boolean} Whether any of the passed issues are errors (rather than warnings).
* @returns {boolean} Whether any of the passed issues are errors (rather than warnings).
*/
static anyAreErrors(issues) {
return issues.some((issue) => issue.isError())
Expand Down
Loading
Loading