diff --git a/spec_tests/jsonTests.spec.js b/spec_tests/jsonTests.spec.js index a53c5454..5d3b7e69 100644 --- a/spec_tests/jsonTests.spec.js +++ b/spec_tests/jsonTests.spec.js @@ -169,9 +169,8 @@ describe('HED validation using JSON tests', () => { assert.instanceOf(parsedTsv, Map, `${events} cannot be parsed`) const bidsTsv = new BidsTsvFile( `events`, - parsedTsv, { relativePath: 'combo test tsv' }, - [], + parsedTsv, JSON.parse(side), defManager, ) @@ -191,7 +190,7 @@ describe('HED validation using JSON tests', () => { defManager.addDefinitions(defList) const parsedTsv = parseTSV(events) assert.instanceOf(parsedTsv, Map, `${events} cannot be parsed`) - const bidsTsv = new BidsTsvFile(`events`, parsedTsv, { relativePath: 'events test' }, [], {}, defManager) + const bidsTsv = new BidsTsvFile(`events`, { relativePath: 'events test' }, parsedTsv, {}, defManager) eventsIssues = bidsTsv.validate(hedSchema) } catch (e) { eventsIssues = [convertIssue(e)] @@ -206,7 +205,7 @@ describe('HED validation using JSON tests', () => { try { const defManager = new DefinitionManager() defManager.addDefinitions(defList) - const bidsSide = new BidsSidecar(`sidecar`, JSON.parse(side), { relativePath: 'bidsFile test' }, defManager) + const bidsSide = new BidsSidecar(`sidecar`, { relativePath: 'bidsFile test' }, JSON.parse(side), defManager) issues = bidsSide.validate(hedSchema) } catch (e) { issues = [convertIssue(e)] @@ -224,7 +223,7 @@ describe('HED validation using JSON tests', () => { defManager.addDefinitions(defList) const parsedTsv = parseTSV(hTsv) assert.instanceOf(parsedTsv, Map, `${str} cannot be parsed`) - const bidsTsv = new BidsTsvFile(`string`, parsedTsv, { relativePath: 'string test tsv' }, [], {}, defManager) + const bidsTsv = new BidsTsvFile(`string`, { relativePath: 'string test tsv' }, parsedTsv, {}, defManager) stringIssues = bidsTsv.validate(hedSchema) } catch (e) { stringIssues = [convertIssue(e)] diff --git a/src/bids/tsvParser.js b/src/bids/tsvParser.js index 61aae6bb..46557b6e 100644 --- a/src/bids/tsvParser.js +++ b/src/bids/tsvParser.js @@ -13,7 +13,7 @@ const isContentfulRow = (row) => row && !/^\s*$/.test(row) * Parse a TSV file. * * @param {string} contents The contents of a TSV file. - * @returns {Map[]} The parsed contents of the TSV file. + * @returns {Map} The parsed contents of the TSV file. */ export function parseTSV(contents) { const columns = new Map() @@ -40,7 +40,7 @@ export function parseTSV(contents) { * Convert parsed TSV file data from the old BIDS format to the new BIDS format. * * @param {{headers: string[], rows: string[][]}} oldParsedTsv Parsed TSV data using the old format - * @returns {Map[]} The parsed contents of the TSV file, using the new format. + * @returns {Map} The parsed contents of the TSV file, using the new format. */ export function convertParsedTSVData(oldParsedTsv) { const columns = new Map() diff --git a/src/bids/types/file.js b/src/bids/types/file.js index c13602f0..78788e11 100644 --- a/src/bids/types/file.js +++ b/src/bids/types/file.js @@ -10,11 +10,13 @@ export class BidsFile { * @type {string} */ name + /** - * The file object representing this file data. + * The Object representing this file data. * This is used to generate {@link BidsIssue} objects. - * @type {object} + * @type {Object} */ + file /** * The validator class used to validate this file. @@ -25,8 +27,8 @@ export class BidsFile { /** * * @param {string} name - The name of the file -- used for messages. - * @param {object} file - The representation of the file for error messages. - * @param validatorClass + * @param {Object} file - The representation of the file for error messages. + * @param {BidsValidator} validatorClass - The validator class corresponding to this file. */ constructor(name, file, validatorClass) { this.name = name @@ -34,15 +36,6 @@ export class BidsFile { this._validatorClass = validatorClass } - /** - * Determine whether this file has any HED data. - * - * @returns {boolean} - True if this file has HED data. - */ - hasHedData() { - return false - } - /** * Validate this validator's tsv file. * @@ -50,7 +43,7 @@ export class BidsFile { * @returns {BidsIssue[]} - Any issues found during validation of this TSV file. */ validate(schemas) { - if (!this.hasHedData()) { + if (!this.hasHedData) { return [] } if (!schemas) { @@ -72,7 +65,7 @@ export class BidsFile { /** * The validator class used to validate this file. - * @returns {*} + * @returns {BidsValidator} */ get validatorClass() { return this._validatorClass diff --git a/src/bids/types/json.js b/src/bids/types/json.js index 7753fdbe..37e8a62a 100644 --- a/src/bids/types/json.js +++ b/src/bids/types/json.js @@ -16,11 +16,17 @@ const ILLEGAL_SIDECAR_KEYS = new Set(['hed', 'n/a']) export class BidsJsonFile extends BidsFile { /** * This file's JSON data. - * @type {object} + * @type {Object} */ jsonData - constructor(name, jsonData, file) { + /** + * + * @param {string} name - The name of the JSON file. + * @param {Object} file - The object representing this file. + * @param {Object} jsonData - The JSON data for this file. + */ + constructor(name, file, jsonData) { super(name, file, BidsHedSidecarValidator) this.jsonData = jsonData } @@ -32,31 +38,37 @@ export class BidsSidecar extends BidsJsonFile { * @type {Map} */ sidecarKeys + /** * The extracted HED data for this bidsFile (string --> string | Object: string, string * @type {Map} */ hedData + /** - * The parsed HED data for this bidsFile (string --> ParsedHedString | Map: string --> ParsedHedString + * The parsed HED data for this bidsFile (string --> ParsedHedString | Map: string --> ParsedHedString). * @type {Map} */ parsedHedData + /** * The extracted HED value strings. * @type {string[]} */ hedValueStrings + /** * The extracted HED categorical strings. * @type {string[]} */ hedCategoricalStrings + /** - * The mapping of column splice references (string --> Set of string) + * The mapping of column splice references (string --> Set of string). * @type {Map} */ columnSpliceMapping + /** * The set of column splice references. * @type {Set} @@ -64,7 +76,7 @@ export class BidsSidecar extends BidsJsonFile { columnSpliceReferences /** - * The object that manages definitions + * The object that manages definitions. * @type {DefinitionManager} */ definitions @@ -73,12 +85,12 @@ export class BidsSidecar extends BidsJsonFile { * Constructor. * * @param {string} name The name of the bidsFile file. - * @param {Object} sidecarData The raw JSON data. * @param {Object} file The file object representing this file. + * @param {Object} sidecarData The raw JSON data. * @param {DefinitionManager } defManager - The external definitions to use */ - constructor(name, sidecarData = {}, file, defManager = null) { - super(name, sidecarData, file) + constructor(name, file, sidecarData = {}, defManager = undefined) { + super(name, file, sidecarData) this.columnSpliceMapping = new Map() this.columnSpliceReferences = new Set() this._setDefinitions(defManager) @@ -168,7 +180,7 @@ export class BidsSidecar extends BidsJsonFile { * * @returns {boolean} */ - hasHedData() { + get hasHedData() { return this.sidecarKeys.size > 0 } diff --git a/src/bids/types/tsv.js b/src/bids/types/tsv.js index b0e18d14..2a8ce3aa 100644 --- a/src/bids/types/tsv.js +++ b/src/bids/types/tsv.js @@ -12,7 +12,7 @@ import { IssueError } from '../../issues/issues' export class BidsTsvFile extends BidsFile { /** * This file's parsed TSV data. - * @type {Map[]} + * @type {Map} */ parsedTsv /** @@ -20,11 +20,7 @@ export class BidsTsvFile extends BidsFile { * @type {string[]} */ hedColumnHedStrings - /** - * The list of potential JSON sidecars. - * @type {string[]} - */ - potentialSidecars + /** * The pseudo-bidsFile object representing the merged bidsFile data. * @type {BidsSidecar} @@ -34,16 +30,13 @@ export class BidsTsvFile extends BidsFile { /** * Constructor. * - * @todo This interface is provisional and subject to modification in version 4.0.0. - * - * @param {string} name The name of the TSV file. - * @param {{headers: string[], rows: string[][]|Map[]|string} tsvData This file's TSV data. - * @param {object} file The file object representing this file. - * @param {string[]} potentialSidecars The list of potential JSON sidecars. - * @param {object} mergedDictionary The merged bidsFile data. - * @param {DefinitionManager} defManager - */ - constructor(name, tsvData, file, potentialSidecars = [], mergedDictionary = {}, defManager) { + * @param {string} name - The name of the TSV file. + * @param {Object} file - The file object representing this file. + * @param {{headers: string[], rows: string[][]}|Map|string} tsvData - This file's TSV data. + * @param {Object} mergedDictionary - The merged bidsFile data. + * @param {DefinitionManager} defManager - The definition manager for this file. + */ + constructor(name, file, tsvData, mergedDictionary = {}, defManager = undefined) { super(name, file, BidsHedTsvValidator) if (typeof tsvData === 'string') { @@ -56,8 +49,7 @@ export class BidsTsvFile extends BidsFile { IssueError.generateAndThrow('internalError', { message: 'parsedTsv has an invalid type' }) } - this.potentialSidecars = potentialSidecars - this.mergedSidecar = new BidsSidecar(name, mergedDictionary, this.file, defManager) + this.mergedSidecar = new BidsSidecar(name, this.file, mergedDictionary, defManager) this._parseHedColumn() } @@ -73,12 +65,10 @@ export class BidsTsvFile extends BidsFile { /** * Determine whether this file has any HED data. * - * @todo To be replaced with property in version 4.0.0. - * * @returns {boolean} */ - hasHedData() { - return this.parsedTsv.has('HED') || this.mergedSidecar.hasHedData() + get hasHedData() { + return this.parsedTsv.has('HED') || this.mergedSidecar.hasHedData } /** @@ -139,7 +129,7 @@ export class BidsTsvElement { } /** - * Override of {@link Object.prototype.toString}. + * Override of {@link object.prototype.toString}. * * @returns {string} */ diff --git a/src/bids/utils.js b/src/bids/utils.js index a6a61e39..b12f327e 100644 --- a/src/bids/utils.js +++ b/src/bids/utils.js @@ -1,7 +1,7 @@ /** * Determine whether a bidsFile value has HED data. * - * @param {object} sidecarValue A BIDS bidsFile value. + * @param {Object} sidecarValue A BIDS bidsFile value. * @returns {boolean} Whether the bidsFile value has HED data. */ export const sidecarValueHasHed = function (sidecarValue) { diff --git a/src/bids/validator/tsvValidator.js b/src/bids/validator/tsvValidator.js index 6033bc56..b9b5e2c7 100644 --- a/src/bids/validator/tsvValidator.js +++ b/src/bids/validator/tsvValidator.js @@ -414,7 +414,7 @@ export class BidsHedTsvParser { columnMap.set('HED', rowCells.get('HED')) } - if (!this.tsvFile.mergedSidecar.hasHedData()) { + if (!this.tsvFile.mergedSidecar.hasHedData) { return columnMap } diff --git a/src/parser/definitionChecker.js b/src/parser/definitionChecker.js index 0d625b3f..eb524b09 100644 --- a/src/parser/definitionChecker.js +++ b/src/parser/definitionChecker.js @@ -1,8 +1,8 @@ import { generateIssue } from '../issues/issues' import { getTagListString } from './parseUtils' -import Set from 'lodash/_Set' const DEFINITION_TAGS = new Set(['Definition', 'Def', 'Def-expand']) + const DEF_GROUP_TAGS = new Set(['Definition', 'Def-expand']) export class DefinitionChecker { @@ -10,7 +10,6 @@ export class DefinitionChecker { * Check Def-expand or definition syntax for compatible tags and number of groups * @param {ParsedHedString} hedString - A group to check for Def-expand syntax. */ - constructor(hedString) { this.hedString = hedString this.definitionTags = this.hedString.tags.filter((tag) => tag.schemaTag.name === 'Definition') @@ -158,33 +157,4 @@ export class DefinitionChecker { } return [] } - - // _checkDefinitionSyntax(parsedString) { - // - // // This checks whether there are any definitions in the string if the definition is allowed. - // const definitionContextIssues = this._checkDefinitionContext(parsedString) - // if (definitionContextIssues.length > 0) { - // return definitionContextIssues - // } - // - // // If - // const definitionStructureIssues = this._checkDefinitionStructure(parsedString) - // return definitionStructureIssues - // } - // - // - // - - // return issues - // const definitionTags = parsedString.tags.filter((tag) => tag.schemaTag.name === 'Definition') - // if (definitionTags.length > 0) { - // return [ - // generateIssue('illegalDefinitionContext', { - // definition: getTagListString(definitionTags), - // string: parsedString.hedString, - // }), - // ] - // } - // return [] - // } } diff --git a/src/parser/parsedHedTag.js b/src/parser/parsedHedTag.js index c14f6995..e09ed89f 100644 --- a/src/parser/parsedHedTag.js +++ b/src/parser/parsedHedTag.js @@ -5,7 +5,7 @@ import TagConverter from './tagConverter' import { ReservedChecker } from './reservedChecker' const TWO_LEVEL_TAGS = new Set(['Definition', 'Def', 'Def-expand']) -const allowedRegEx = /^[^{}\,]*$/ +const allowedRegEx = /^[^{},]*$/ /** * A parsed HED tag. diff --git a/src/parser/reservedChecker.js b/src/parser/reservedChecker.js index a2c60b89..1d8d6fa5 100644 --- a/src/parser/reservedChecker.js +++ b/src/parser/reservedChecker.js @@ -40,7 +40,7 @@ export class ReservedChecker { * Perform syntactical checks on the provided HED string to detect violations. * * @param {ParsedHedString} hedString - The HED string to be checked. - * @returns {Issue[]} An array of issues if violations are found otherwise, an empty array. + * @returns {Issue[]} - An array of issues if violations are found otherwise, an empty array. */ checkHedString(hedString) { const checks = [ diff --git a/src/schema/containers.js b/src/schema/containers.js index 75ab12d9..a90d6331 100644 --- a/src/schema/containers.js +++ b/src/schema/containers.js @@ -38,7 +38,7 @@ export class Schema { /** * Constructor. * - * @param {object} xmlData The schema XML data. + * @param {Object} xmlData The schema XML data. * @param {SchemaEntries} entries A collection of schema entries. */ constructor(xmlData, entries) { diff --git a/src/schema/init.js b/src/schema/init.js index d45b56e0..89257dce 100644 --- a/src/schema/init.js +++ b/src/schema/init.js @@ -10,7 +10,7 @@ import { Schema, Schemas } from './containers' /** * Build a single schema container object from an XML file. * - * @param {object} xmlData The schema's XML data + * @param {Object} xmlData The schema's XML data * @returns {Schema} The HED schema object. */ const buildSchemaObject = function (xmlData) { @@ -23,7 +23,7 @@ const buildSchemaObject = function (xmlData) { /** * Build a single merged schema container object from one or more XML files. * - * @param {object[]} xmlData The schemas' XML data. + * @param {Object[]} xmlData The schemas' XML data. * @returns {Schema} The HED schema object. */ const buildSchemaObjects = function (xmlData) { diff --git a/src/schema/parser.js b/src/schema/parser.js index f741ae93..89add5c5 100644 --- a/src/schema/parser.js +++ b/src/schema/parser.js @@ -124,7 +124,7 @@ export default class SchemaParser { * * NOTE: This method cannot be merged into {@link getElementTagValue} because it is used as a first-class object. * - * @param {object} element An XML element. + * @param {Object} element An XML element. * @returns {string} The name of the element. */ getElementTagName(element) { @@ -134,7 +134,7 @@ export default class SchemaParser { /** * Extract a value from an XML element. * - * @param {object} element An XML element. + * @param {Object} element An XML element. * @param {string} tagName The tag value to extract. * @returns {string} The value of the tag in the element. */ diff --git a/src/utils/xml2js.js b/src/utils/xml2js.js index 627b1649..1ecfab79 100644 --- a/src/utils/xml2js.js +++ b/src/utils/xml2js.js @@ -1,8 +1,8 @@ /** * Recursively set a field on each node of the tree pointing to the node's parent. * - * @param {object} node The child node. - * @param {object} parent The parent node. + * @param {Object} node The child node. + * @param {Object} parent The parent node. */ const setNodeParent = function (node, parent) { // Assume that we've already run this function if so. @@ -19,8 +19,8 @@ const setNodeParent = function (node, parent) { /** * Handle top level of parent-setting recursion before passing to setNodeParent. * - * @param {object} node The child node. - * @param {object} parent The parent node. + * @param {Object} node The child node. + * @param {Object} parent The parent node. */ export const setParent = function (node, parent) { if (node.schema) { diff --git a/src/utils/xpath.js b/src/utils/xpath.js index df5788e4..7cb5aac8 100644 --- a/src/utils/xpath.js +++ b/src/utils/xpath.js @@ -11,9 +11,9 @@ const childToParent = { /** * Execute an XPath query on an xml2js object. * - * @param {object} element An xml2js element. + * @param {Object} element An xml2js element. * @param {string} query An XPath query. - * @returns {object[]} An array of xml2js elements matching the query. + * @returns {Object[]} An array of xml2js elements matching the query. */ export const find = function (element, query) { const { elementName, attributeName } = parseXPath(query) @@ -33,7 +33,7 @@ export const find = function (element, query) { * This is a minimal parser only suitable for this package. * * @param {string} query An XPath query. - * @returns {object} The parsed search parameters. + * @returns {Object} The parsed search parameters. */ const parseXPath = function (query) { const nodeQuery = /^\/\/(\w+)$/ @@ -58,10 +58,10 @@ const parseXPath = function (query) { /** * Search for children of an element with a given name and attribute. * - * @param {object} element An xml2js element. + * @param {Object} element An xml2js element. * @param {string} elementName The element name. * @param {string} attributeName The attribute name. - * @returns {object[]} An array of xml2js elements with the given name and attribute. + * @returns {Object[]} An array of xml2js elements with the given name and attribute. */ const search = function (element, elementName, attributeName) { let result = [] diff --git a/tests/bidsTests.spec.js b/tests/bidsTests.spec.js index 45d76702..992c2ffe 100644 --- a/tests/bidsTests.spec.js +++ b/tests/bidsTests.spec.js @@ -56,8 +56,11 @@ describe('BIDS validation', () => { const sidecarName = test.testname + '.json' const bidsSidecar = new BidsSidecar( 'thisOne', + { + relativePath: sidecarName, + path: sidecarName, + }, test.sidecar, - { relativePath: sidecarName, path: sidecarName }, defManager1, ) assert.instanceOf(bidsSidecar, BidsSidecar, 'Test') @@ -72,9 +75,11 @@ describe('BIDS validation', () => { defManager2.addDefinitions(defList) const bidsTsv = new BidsTsvFile( test.testname, + { + relativePath: eventName, + path: eventName, + }, parsedTsv, - { relativePath: eventName, path: eventName }, - [], {}, defManager2, ) @@ -86,9 +91,11 @@ describe('BIDS validation', () => { defManager3.addDefinitions(defList) const bidsTsvSide = new BidsTsvFile( test.testname, + { + relativePath: eventName, + path: eventName, + }, parsedTsv, - { relativePath: eventName, path: eventName }, - [], test.sidecar, defManager3, ) diff --git a/tests/schemaBuildTests.spec.js b/tests/schemaBuildTests.spec.js index c2275c10..c8bb140c 100644 --- a/tests/schemaBuildTests.spec.js +++ b/tests/schemaBuildTests.spec.js @@ -41,10 +41,14 @@ describe('Schema build validation', () => { afterAll(() => {}) async function testSchema(test) { - const desc = new BidsJsonFile('/dataset_description.json', test.schemaVersion, { - relativePath: '/dataset_description.json', - path: '/dataset_description.json', - }) + const desc = new BidsJsonFile( + '/dataset_description.json', + { + relativePath: '/dataset_description.json', + path: '/dataset_description.json', + }, + test.schemaVersion, + ) let schema = undefined let caughtError = null try { diff --git a/tests/schemaSpecTests.spec.js b/tests/schemaSpecTests.spec.js index b2891d1a..21b8cb1f 100644 --- a/tests/schemaSpecTests.spec.js +++ b/tests/schemaSpecTests.spec.js @@ -29,10 +29,14 @@ describe('Schema validation', () => { describe.each(schemaSpecTestData)('$name : $description', ({ name, tests }) => { const validateSpec = function (test) { - const desc = new BidsJsonFile('/dataset_description.json', test.schemaVersion, { - relativePath: '/dataset_description.json', - path: '/dataset_description.json', - }) + const desc = new BidsJsonFile( + '/dataset_description.json', + { + relativePath: '/dataset_description.json', + path: '/dataset_description.json', + }, + test.schemaVersion, + ) let schemaSpec = null let caughtError = null try {