diff --git a/bids-validator/utils/issues/list.js b/bids-validator/utils/issues/list.js index d9506ecbf..30f71011d 100644 --- a/bids-validator/utils/issues/list.js +++ b/bids-validator/utils/issues/list.js @@ -622,6 +622,12 @@ export default { reason: 'This dataset contains remote files. If you would like to validate with remote files, use the --remoteFiles option.', }, + 115: { + key: 'EMPTY_DATASET_NAME', + severity: 'warning', + reason: + 'The Name field of dataset_description.json is present but empty of visible characters.', + }, 123: { key: 'INVALID JSON ENCODING', severity: 'error', diff --git a/bids-validator/validators/bids/__tests__/checkDatasetDescription.spec.js b/bids-validator/validators/bids/__tests__/checkDatasetDescription.spec.js index 337a0d108..347723c5c 100644 --- a/bids-validator/validators/bids/__tests__/checkDatasetDescription.spec.js +++ b/bids-validator/validators/bids/__tests__/checkDatasetDescription.spec.js @@ -2,16 +2,55 @@ import { assert } from 'chai' import checkDatasetDescription from '../checkDatasetDescription' describe('checkDatasetDescription', () => { - describe('checkAuthorField', () => { - it('returns no issues with valid Authors field', () => { + describe('checkNameAndAuthorsFields', () => { + it('returns no issues with valid Name and Authors field', () => { + const validJsonContentsDict = { + '/dataset_description.json': { + Name: 'Electric Boots', + Authors: ['Benny', 'the Jets'], + }, + } + const issues = checkDatasetDescription(validJsonContentsDict) + assert.lengthOf(issues, 0) + }) + }) + describe('checkNameField', () => { + it('returns code 115 when Name is empty', () => { + const invalidJsonContentsDict = { + '/dataset_description.json': { + Name: '', + }, + } + const issues = checkDatasetDescription(invalidJsonContentsDict) + assert( + issues.findIndex((issue) => issue.code === 115) > -1, + 'issues include a code 115', + ) + }) + it('returns code 115 when name only contains whitespace', () => { + const invalidJsonContentsDict = { + '/dataset_description.json': { + Name: ' \t\r\n\f\v\u2003', + }, + } + const issues = checkDatasetDescription(invalidJsonContentsDict) + assert( + issues.findIndex((issue) => issue.code === 115) > -1, + 'issues include a code 115', + ) + }) + it('returns no issues with one non-whitespace character', () => { const validJsonContentsDict = { '/dataset_description.json': { + Name: ' \u2708 ', Authors: ['Benny', 'the Jets'], }, } const issues = checkDatasetDescription(validJsonContentsDict) assert.lengthOf(issues, 0) }) + }) + describe('checkAuthorField', () => { it('returns code 102 when there is only one author present', () => { const invalidJsonContentsDict = { '/dataset_description.json': { diff --git a/bids-validator/validators/bids/checkDatasetDescription.js b/bids-validator/validators/bids/checkDatasetDescription.js index 68db9f4c1..87f730a88 100644 --- a/bids-validator/validators/bids/checkDatasetDescription.js +++ b/bids-validator/validators/bids/checkDatasetDescription.js @@ -15,8 +15,9 @@ const checkDatasetDescription = (jsonContentsDict) => { } else { const datasetDescription = jsonContentsDict['/dataset_description.json'] - // check to ensure that the dataset description Authors are + // check to ensure that the dataset description fields are // properly formatted + issues = issues.concat(checkNameField(datasetDescription.Name)) issues = issues.concat(checkAuthorField(datasetDescription.Authors)) // if genetic info json present ensure mandatory GeneticDataset present @@ -33,6 +34,18 @@ const checkDatasetDescription = (jsonContentsDict) => { return issues } +const checkNameField = (name) => { + const issues = [] + // missing name will be caught by validation (later) + if (name !== undefined) { + const nonws = /\S/ + if (!name.match(nonws)) { + issues.push(new Issue({ code: 115 })) + } + } + return issues +} + const checkAuthorField = (authors) => { const issues = [] // because this test happens before schema validation,