Skip to content

Commit c9901bc

Browse files
authored
Merge pull request #574 from olgn/remove-async
remove async
2 parents a983cc0 + 2abc714 commit c9901bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1551
-1182
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"homepage": "https://github.com/bids-standard/bids-validator",
2929
"dependencies": {
3030
"ajv": "^6.5.2",
31-
"async": "^2.6.1",
3231
"bytes": "^3.0.0",
3332
"cliff": "^0.1.10",
3433
"colors": "^1.3.1",

tests/bval.spec.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
var assert = require('assert')
2-
var validate = require('../index')
1+
const assert = require('assert')
2+
const bval = require('../validators/bval/bval')
33

44
describe('bval', function() {
55
it('should allow proper bval contents', function() {
6-
var bval = '4 6 2 5 3 23 5'
7-
validate.bval({}, bval, function(issues) {
6+
const val = '4 6 2 5 3 23 5'
7+
bval({}, val, function(issues) {
88
assert.deepEqual(issues, [])
99
})
1010
})
1111

1212
it('should not allow more than one row', function() {
13-
var bval = '0 4 3 6 1 6 2 4 1\n 4 3 5 2 4 2 4 5'
14-
validate.bval({}, bval, function(issues) {
13+
const val = '0 4 3 6 1 6 2 4 1\n 4 3 5 2 4 2 4 5'
14+
bval({}, val, function(issues) {
1515
assert(issues.length == 1 && issues[0].code == 30)
1616
})
1717
})
1818

1919
it('should catch doublespace separators', function() {
20-
var bval = '4 6 2 5 3 23 5'
21-
validate.bval({}, bval, function(issues) {
20+
const val = '4 6 2 5 3 23 5'
21+
bval({}, val, function(issues) {
2222
assert(issues.length == 1 && issues[0].code == 47)
2323
})
2424
})
2525

2626
it('should not allow undefined bvals', function() {
27-
const bval = undefined
28-
validate.bval({}, bval, function(issues) {
27+
const val = undefined
28+
bval({}, val, function(issues) {
2929
assert(issues.length == 1 && issues[0].code == 89)
3030
})
3131
})
3232

3333
it('should not allow bvals of types other than string', function() {
34-
const bval = [0, 1, 2, 3]
35-
validate.bval({}, bval, function(issues) {
34+
const val = [0, 1, 2, 3]
35+
bval({}, val, function(issues) {
3636
assert(issues.length == 1 && issues[0].code == 89)
3737
})
3838
})
3939

4040
it('should not allow bvecs to be submitted in place of bval', function() {
41-
const bvec = '4 6 7\n 2 3 4\n 4 5 6'
42-
validate.bval({}, bvec, function(issues) {
41+
const val = '4 6 7\n 2 3 4\n 4 5 6'
42+
bval({}, val, function(issues) {
4343
assert(issues.length == 1 && issues[0].code == 30)
4444
})
4545
})

tests/bvec.spec.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
var assert = require('assert')
2-
var validate = require('../index')
2+
const bvec = require('../validators/bvec/bvec')
33

44
describe('bvec', function() {
55
it('should allow valid bvec contents', function() {
6-
var bvec = '4 6 2 5\n3 2 3 5\n6 4 3 5'
7-
validate.bvec({}, bvec, function(issues) {
6+
const vec = '4 6 2 5\n3 2 3 5\n6 4 3 5'
7+
bvec({}, vec, function(issues) {
88
assert.deepEqual(issues, [])
99
})
1010
})
1111

1212
it('should not allow more or less than 3 rows', function() {
13-
var bvec = '0 4 3 6 1 6 2 4\n 4 3 5 2 4 2 4 5'
14-
validate.bvec({}, bvec, function(issues) {
13+
let vec = '0 4 3 6 1 6 2 4\n 4 3 5 2 4 2 4 5'
14+
bvec({}, vec, function(issues) {
1515
assert(issues.length == 1 && issues[0].code == 31)
1616
})
1717

18-
bvec =
18+
vec =
1919
'0 4 3 6 1 6 2 4\n 4 3 5 2 4 2 4 5\n 4 3 5 2 4 2 4 5\n 4 3 5 2 4 2 4 5'
20-
validate.bvec({}, bvec, function(issues) {
20+
bvec({}, vec, function(issues) {
2121
assert(issues.length == 1 && issues[0].code == 31)
2222
})
2323
})
2424

2525
it('should not allow rows of inconsistent length', function() {
26-
var bvec = '0 4 3 6 1 6 4\n 4 3 4 2 4 5\n 4 3 5 2 4 2 4 5'
27-
validate.bvec({}, bvec, function(issues) {
26+
const vec = '0 4 3 6 1 6 4\n 4 3 4 2 4 5\n 4 3 5 2 4 2 4 5'
27+
bvec({}, vec, function(issues) {
2828
assert(issues.length == 1 && issues[0].code == 46)
2929
})
3030
})
3131

3232
it('should catch doublespace separators', function() {
33-
var bvec = '4 6 2 5\n3 2 3 5\n6 4 3 5'
34-
validate.bvec({}, bvec, function(issues) {
33+
const vec = '4 6 2 5\n3 2 3 5\n6 4 3 5'
34+
bvec({}, vec, function(issues) {
3535
assert(issues.length == 1 && issues[0].code == 47)
3636
})
3737
})
3838

3939
it('should not allow undefined bvecs', function() {
40-
const bvec = undefined
41-
validate.bvec({}, bvec, function(issues) {
40+
const vec = undefined
41+
bvec({}, vec, function(issues) {
4242
assert(issues.length == 1 && issues[0].code == 88)
4343
})
4444
})
4545

4646
it('should not allow bvecs of types other than string', function() {
47-
const bvec = [0, 1, 2, 3]
48-
validate.bvec({}, bvec, function(issues) {
47+
const vec = [0, 1, 2, 3]
48+
bvec({}, vec, function(issues) {
4949
assert(issues.length == 1 && issues[0].code == 88)
5050
})
5151
})
5252

5353
it('should not allow bvals to be submitted in place of bvec', function() {
54-
const bval = '4 6 7'
55-
validate.bvec({}, bval, function(issues) {
54+
const vec = '4 6 7'
55+
bvec({}, vec, function(issues) {
5656
assert(issues.length == 1 && issues[0].code == 31)
5757
})
5858
})

tests/events.spec.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ describe('Events', function() {
1313
]
1414

1515
it('all files in the /stimuli folder should be included in an _events.tsv file', function() {
16-
const issues = []
17-
1816
// stimuli.events will have all of the
1917
// files included in the stim_file column of every _events.tsv file.
2018
// stimuli.directory will have all of the
@@ -23,22 +21,20 @@ describe('Events', function() {
2321
events: ['/stimuli/images/red-square.jpg'],
2422
directory: [{ relativePath: '/stimuli/images/blue-square.jpg' }],
2523
}
26-
validate.Events.validateEvents([], stimuli, [], {}, issues)
24+
const issues = validate.Events.validateEvents([], stimuli, [], {})
2725
assert(issues.length === 1 && issues[0].code === 77)
2826
})
2927

3028
it('should not throw issues if all files in the /stimuli folder are included in an _events.tsv file', function() {
31-
const issues = []
3229
const stimuli = {
3330
events: ['/stimuli/images/red-square.jpg'],
3431
directory: [{ relativePath: '/stimuli/images/red-square.jpg' }],
3532
}
36-
validate.Events.validateEvents([], stimuli, [], {}, issues)
33+
const issues = validate.Events.validateEvents([], stimuli, [], {})
3734
assert(issues.length === 0)
3835
})
3936

4037
it('should throw an issue if the onset of the last event in _events.tsv is more than TR * number of volumes in corresponding nifti header', function() {
41-
const issues = []
4238
const events = [
4339
{
4440
file: { path: '/sub01/sub01_task-test_events.tsv' },
@@ -52,12 +48,16 @@ describe('Events', function() {
5248
},
5349
}
5450

55-
validate.Events.validateEvents(events, [], headers, jsonDictionary, issues)
51+
const issues = validate.Events.validateEvents(
52+
events,
53+
[],
54+
headers,
55+
jsonDictionary,
56+
)
5657
assert(issues.length === 1 && issues[0].code === 85)
5758
})
5859

5960
it('should throw an issue if the onset of the last event in _events.tsv is less than .5 * TR * number of volumes in corresponding nifti header', function() {
60-
const issues = []
6161
const events = [
6262
{
6363
file: { path: '/sub01/sub01_task-test_events.tsv' },
@@ -71,12 +71,16 @@ describe('Events', function() {
7171
},
7272
}
7373

74-
validate.Events.validateEvents(events, [], headers, jsonDictionary, issues)
74+
const issues = validate.Events.validateEvents(
75+
events,
76+
[],
77+
headers,
78+
jsonDictionary,
79+
)
7580
assert(issues.length === 1 && issues[0].code === 86)
7681
})
7782

7883
it('should not throw any issues if the onset of the last event in _events.tsv is a reasonable value', function() {
79-
const issues = []
8084
const events = [
8185
{
8286
file: { path: '/sub01/sub01_task-test_events.tsv' },
@@ -90,7 +94,12 @@ describe('Events', function() {
9094
},
9195
}
9296

93-
validate.Events.validateEvents(events, [], headers, jsonDictionary, issues)
97+
const issues = validate.Events.validateEvents(
98+
events,
99+
[],
100+
headers,
101+
jsonDictionary,
102+
)
94103
assert.deepEqual(issues, [])
95104
})
96105
})

tests/tsv.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ describe('TSV', function() {
205205
size: 11845,
206206
}
207207
var issues = []
208-
validate.TSV.checkphenotype(
208+
validate.TSV.checkPhenotype(
209209
phenotypeParticipants,
210210
summary,
211211
issues,

utils/files/collectDirectoryStatistics.js renamed to utils/files/collectDirectorySize.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
const async = require('async')
21
const fs = require('fs')
32

4-
const collectDirectoryStatistics = (fileList, summary) => {
5-
async.eachOfLimit(fileList, 200, function(file) {
3+
const collectDirectorySize = fileList => {
4+
let size = 0
5+
const keys = Object.keys(fileList)
6+
keys.forEach(key => {
7+
const file = fileList[key]
68
// collect file stats
79
if (typeof window !== 'undefined' && file.size) {
8-
summary.size += file.size
10+
size += file.size
911
} else {
1012
file.stats = getFileStats(file)
11-
summary.size += file.stats.size
13+
size += file.stats.size
1214
}
1315
})
16+
return size
1417
}
1518

1619
const getFileStats = file => {
@@ -25,4 +28,4 @@ const getFileStats = file => {
2528
return stats
2629
}
2730

28-
module.exports = collectDirectoryStatistics
31+
module.exports = collectDirectorySize

utils/files/illegalCharacterTest.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const async = require('async')
21
const Issue = require('../../utils/issues').Issue
32

43
const re = {
@@ -15,8 +14,11 @@ const illegalchar_regex_list = [
1514
[re.ses_re, 63, 'ses name contains illegal character:'],
1615
]
1716

18-
const illegalCharacterTest = (fileList, issues) => {
19-
async.eachOfLimit(fileList, 200, function(file) {
17+
const illegalCharacterTest = fileList => {
18+
const issues = []
19+
const fileKeys = Object.keys(fileList)
20+
fileKeys.forEach(key => {
21+
const file = fileList[key]
2022
const completename = file.relativePath
2123
if (
2224
!(
@@ -42,6 +44,7 @@ const illegalCharacterTest = (fileList, issues) => {
4244
})
4345
}
4446
})
47+
return issues
4548
}
4649

4750
module.exports = illegalCharacterTest

utils/files/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const readDir = require('./readDir')
88
const potentialLocations = require('./potentialLocations')
99
const generateMergedSidecarDict = require('./generateMergedSidecarDict')
1010
const getBFileContent = require('./getBFileContent')
11-
const collectDirectoryStatistics = require('./collectDirectoryStatistics')
11+
const collectDirectorySize = require('./collectDirectorySize')
1212
const illegalCharacterTest = require('./illegalCharacterTest')
1313

1414
// public API ---------------------------------------------------------------------
@@ -22,7 +22,7 @@ var fileUtils = {
2222
generateMergedSidecarDict: generateMergedSidecarDict,
2323
potentialLocations: potentialLocations,
2424
getBFileContent: getBFileContent,
25-
collectDirectoryStatistics: collectDirectoryStatistics,
25+
collectDirectorySize: collectDirectorySize,
2626
illegalCharacterTest: illegalCharacterTest,
2727
}
2828

utils/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var json = require('./json')
88
var modalities = require('./modalities')
99
var options = require('./options')
1010
var type = require('./type')
11+
const collectSummary = require('./summary/collectSummary')
1112

1213
module.exports = {
1314
array: array,
@@ -19,4 +20,5 @@ module.exports = {
1920
modalities: modalities,
2021
options: options,
2122
type: type,
23+
collectSummary: collectSummary,
2224
}

utils/summary/collectModalities.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const type = require('../type')
2+
3+
const collectModalities = fileList => {
4+
const modalities = []
5+
const keys = Object.keys(fileList)
6+
keys.forEach(key => {
7+
const file = fileList[key]
8+
const path = file.relativePath
9+
const pathParts = path.split('_')
10+
const suffix = pathParts[pathParts.length - 1]
11+
12+
// check modality by data file extension ...
13+
// and capture data files for later sanity checks (when available)
14+
if (type.file.isModality(file.name)) {
15+
// collect modality summary
16+
const modality = suffix.slice(0, suffix.indexOf('.'))
17+
if (modalities.indexOf(modality) === -1) {
18+
modalities.push(modality)
19+
}
20+
}
21+
})
22+
return modalities
23+
}
24+
25+
module.exports = collectModalities

0 commit comments

Comments
 (0)