diff --git a/tests/nii.spec.js b/tests/nii.spec.js index b7436fbb0..4358aa296 100644 --- a/tests/nii.spec.js +++ b/tests/nii.spec.js @@ -152,14 +152,17 @@ describe('NIFTI', function() { }) validate.NIFTI(null, file, jsonContentsDict, {}, [], [], function(issues) { assert( - issues.some(issue => ( - issue.reason === 'Invalid filetype: IntendedFor should point to the .nii[.gz] files.' && - issue.evidence === 'func/sub-15_task-mixedeventrelatedprobe_run-05_bold.json' - )), + issues.some( + issue => + issue.reason === + 'Invalid filetype: IntendedFor should point to the .nii[.gz] files.' && + issue.evidence === + 'func/sub-15_task-mixedeventrelatedprobe_run-05_bold.json', + ), ) }) }) - + it('should generate warning if files listed in IntendedFor of fieldmap json do not exist', function() { var file = { name: 'sub-09_ses-test_run-01_fieldmap.nii.gz', @@ -187,7 +190,7 @@ describe('NIFTI', function() { }) validate.NIFTI(null, file, jsonContentsDict, {}, [], [], function(issues) { assert( - (issues.length === 3 && issues[0].code == 17 && issues[1].code == 37), + issues.length === 3 && issues[0].code == 17 && issues[1].code == 37, ) }) }) diff --git a/validators/nifti/nii.js b/validators/nifti/nii.js index 3d15b2d35..5c652c546 100644 --- a/validators/nifti/nii.js +++ b/validators/nifti/nii.js @@ -429,7 +429,7 @@ module.exports = function NIFTI( typeof mergedDictionary['IntendedFor'] == 'string' ? [mergedDictionary['IntendedFor']] : mergedDictionary['IntendedFor'] - + for (let key = 0; key < intendedFor.length; key++) { const intendedForFile = intendedFor[key] checkIfIntendedExists(intendedForFile, fileList, issues, file) @@ -486,9 +486,11 @@ function checkIfIntendedExists(intendedForFile, fileList, issues, file) { let onTheList = false for (let key2 in fileList) { - const filePath = fileList[key2].relativePath - if (filePath === intendedForFileFull) { - onTheList = true + if (key2) { + const filePath = fileList[key2].relativePath + if (filePath === intendedForFileFull) { + onTheList = true + } } } if (!onTheList) { @@ -519,8 +521,7 @@ function checkIfValidFiletype(intendedForFile, issues, file) { new Issue({ file: file, code: 37, - reason: - `Invalid filetype: IntendedFor should point to the .nii[.gz] files.`, + reason: `Invalid filetype: IntendedFor should point to the .nii[.gz] files.`, evidence: intendedForFile, }), )