Skip to content

Commit 8808578

Browse files
authored
Merge pull request #231 from bids-standard/fix/truncate_opaque_trees
fix: Do not descend into pseudo-files or opaque directories when checking for unused files
2 parents 53e81c8 + 94e4add commit 8808578

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Added
10+
11+
- A bullet item for the Added category.
12+
13+
-->
14+
<!--
15+
### Changed
16+
17+
- A bullet item for the Changed category.
18+
19+
-->
20+
### Fixed
21+
22+
- Avoid descending into opaque directories (such as `*.zarr/`) when checking
23+
for unused sidecars. ([#227])
24+
25+
[#227]: https://github.com/bids-standard/bids-validator/issues/227
26+
27+
<!--
28+
### Deprecated
29+
30+
- A bullet item for the Deprecated category.
31+
32+
-->
33+
<!--
34+
### Removed
35+
36+
- A bullet item for the Removed category.
37+
38+
-->
39+
<!--
40+
### Security
41+
42+
- A bullet item for the Security category.
43+
44+
-->
45+
<!--
46+
### Infrastructure
47+
48+
- A bullet item for the Infrastructure category.
49+
50+
-->

src/bids-validator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ const errors = result.issues.get({ severity: 'error' })
66
if (errors.length) {
77
Deno.exit(16)
88
}
9+
Deno.exit(0)

src/validators/bids.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export async function validate(
124124
}
125125
await summary.update(context)
126126
}
127+
127128
for (const check of perDSChecks) {
128129
await check(schema as unknown as GenericSchema, dsContext)
129130
}

src/validators/internal/unusedFile.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ import type { GenericSchema } from '../../types/schema.ts'
22
import type { BIDSFile, FileTree } from '../../types/filetree.ts'
33
import type { BIDSContextDataset } from '../../schema/context.ts'
44

5-
function* walkFileTree(fileTree?: FileTree): Generator<BIDSFile> {
5+
function* walkFileTree(fileTree: FileTree, dsContext: BIDSContextDataset): Generator<BIDSFile> {
66
if (!fileTree) {
77
return
88
}
9+
910
for (const file of fileTree.files) {
1011
if (!file.ignored) {
1112
yield file
1213
}
1314
}
15+
1416
for (const dir of fileTree.directories) {
15-
if (!dir.ignored) {
16-
yield* walkFileTree(dir)
17+
if (!dir.ignored && !dsContext.isPseudoFile(dir) && !dsContext.isOpaqueDirectory(dir)) {
18+
yield* walkFileTree(dir, dsContext)
1719
}
1820
}
1921
}
@@ -23,7 +25,9 @@ export async function unusedStimulus(
2325
dsContext: BIDSContextDataset,
2426
) {
2527
const stimDir = dsContext.tree.get('stimuli') as FileTree
26-
const unusedStimuli = [...walkFileTree(stimDir)].filter((stimulus) => !stimulus.viewed)
28+
const unusedStimuli = [...walkFileTree(stimDir, dsContext)].filter((stimulus) =>
29+
!stimulus.viewed
30+
)
2731
if (unusedStimuli.length) {
2832
dsContext.issues.add({ code: 'UNUSED_STIMULUS', affects: unusedStimuli.map((s) => s.path) })
2933
}
@@ -35,7 +39,7 @@ export async function sidecarWithoutDatafile(
3539
schema: GenericSchema,
3640
dsContext: BIDSContextDataset,
3741
) {
38-
const unusedSidecars = [...walkFileTree(dsContext.tree)].filter(
42+
const unusedSidecars = [...walkFileTree(dsContext.tree, dsContext)].filter(
3943
(file) => (!file.viewed && file.name.endsWith('.json') &&
4044
!standalone_json.includes(file.name)),
4145
)

0 commit comments

Comments
 (0)