Skip to content

Commit 5342e41

Browse files
authored
Merge pull request #1485 from rwblair/1484_readme_error
update missing readme check to allow extensions.
2 parents e93b653 + e8b468b commit 5342e41

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

bids-validator/utils/issues/list.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,4 +1119,10 @@ export default {
11191119
severity: 'error',
11201120
reason: 'Inconsistent TIFF file type and extension',
11211121
},
1122+
228: {
1123+
key: 'MULTIPLE_README_FILES',
1124+
severity: 'error',
1125+
reason:
1126+
'A BIDS dataset MUST NOT contain more than one `README` file (with or without extension) at its root directory.',
1127+
},
11221128
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { assert } from 'chai'
2+
import checkReadme from '../checkReadme'
3+
4+
describe('checkReadme', () => {
5+
it('returns issues with multiple readme files', () => {
6+
const fileList = {
7+
'/README': {
8+
name: 'README',
9+
path: '/ds-999/README',
10+
relativePath: '/README',
11+
stats: { size: 155 },
12+
},
13+
'/README.md': {
14+
name: 'README.md',
15+
path: '/ds-999/README.md',
16+
relativePath: '/README.md',
17+
stats: { size: 155 },
18+
},
19+
}
20+
const issues = checkReadme(fileList)
21+
assert.lengthOf(issues, 1)
22+
assert.equal(issues[0].code, 228)
23+
})
24+
it('returns issues with multiple small readme files', () => {
25+
const fileList = {
26+
'/README': {
27+
name: 'README',
28+
path: '/ds-999/README',
29+
relativePath: '/README',
30+
stats: { size: 100 },
31+
},
32+
'/README.md': {
33+
name: 'README.md',
34+
path: '/ds-999/README.md',
35+
relativePath: '/README.md',
36+
stats: { size: 100 },
37+
},
38+
}
39+
const issues = checkReadme(fileList)
40+
assert.lengthOf(issues, 3)
41+
const codes = issues.map(issue => issue.code)
42+
assert.equal(codes.filter(x => x === 213).length, 2)
43+
assert.equal(codes.filter(x => x === 228).length, 1)
44+
})
45+
it('returns no issues on readme with extension', () => {
46+
const fileList = {
47+
'/README.md': {
48+
name: 'README.md',
49+
path: '/ds-999/README.md',
50+
relativePath: '/README.md',
51+
stats: { size: 155 },
52+
},
53+
}
54+
const issues = checkReadme(fileList)
55+
assert.lengthOf(issues, 0)
56+
})
57+
it('returns issue on no readme', () => {
58+
const fileList = {
59+
'/bad.md': {
60+
name: 'bad.md',
61+
path: '/ds-999/bad.md',
62+
relativePath: '/bad.md',
63+
stats: { size: 155 },
64+
},
65+
}
66+
const issues = checkReadme(fileList)
67+
assert.lengthOf(issues, 1)
68+
assert.equal(issues[0].code, 101)
69+
})
70+
})

bids-validator/validators/bids/checkReadme.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ const Issue = require('../../utils').issues.Issue
44

55
const checkReadme = fileList => {
66
const issues = []
7-
const readmeFile = Array.from(Object.values(fileList)).find(
8-
file => file.relativePath && file.relativePath == '/README',
7+
const readmeFiles = Array.from(Object.values(fileList)).filter(
8+
file => file.relativePath && file.relativePath.startsWith('/README'),
99
)
10-
if (readmeFile) {
10+
11+
readmeFiles.map(readmeFile => {
1112
const size = !isNode ? readmeFile.size : readmeFile.stats.size
1213
const failsSizeRequirement = size <= 150
1314
if (failsSizeRequirement) {
14-
issues.push(new Issue({ code: 213 }))
15+
issues.push(new Issue({ code: 213, file: readmeFile }))
1516
}
16-
} else {
17+
})
18+
if (readmeFiles.length > 1) {
19+
issues.push(new Issue({ code: 228 }))
20+
} else if (readmeFiles.length === 0) {
1721
issues.push(new Issue({ code: 101 }))
1822
}
1923
return issues

0 commit comments

Comments
 (0)