Skip to content

Commit 4e2978d

Browse files
authored
Merge pull request #134 from bpinsard/enh/config_wildcards
enable wildcards in paths for config files
2 parents bd92283 + d20d588 commit 4e2978d

File tree

7 files changed

+35
-13
lines changed

7 files changed

+35
-13
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@cliffy/command": "jsr:@effigies/[email protected]",
3333
"@cliffy/table": "jsr:@effigies/[email protected]",
3434
"@hed/validator": "npm:[email protected]",
35-
"@ignore": "npm:ignore@6.0.2",
35+
"@ignore": "npm:ignore@7.0.3",
3636
"@libs/xml": "jsr:@libs/[email protected]",
3737
"@mango/nifti": "npm:@bids/[email protected]",
3838
"@std/assert": "jsr:@std/[email protected]",

deno.lock

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/user_guide/command-line.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ warnings, errors or ignored.
8484
}
8585
```
8686

87+
When a configuration specifies `location` without leading `/` it is interpreted
88+
as a glob pattern following gitignore syntax.
8789
The issues are partial matches of the [Issues] that the validator accumulates.
8890
Pass the `--json` flag to see the issues in detail.
8991

src/files/ignore.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export class FileIgnoreRules {
3131
config: string[],
3232
addDefaults: boolean = true,
3333
) {
34-
// @ts-expect-error
3534
this.#ignore = ignore()
3635
if (addDefaults) {
3736
this.#ignore.add(defaultIgnores)

src/issues/datasetIssues.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ Deno.test('DatasetIssues management class', async (t) => {
2525
assertEquals(foundIssue[0].code, 'TEST_FILES_ERROR')
2626
})
2727

28+
await t.step('get issues with glob pattern', () => {
29+
const issues = new DatasetIssues()
30+
issues.add({ code: 'TEST_FILES_ERROR', location: '/acq-mprage_T1w.json' }, 'Test issue')
31+
issues.add({ code: 'TEST_FILES_ERROR', location: '/acq-memprage_T1w.json' }, 'Test issue')
32+
issues.add({ code: 'TEST_FILES_ERROR', location: '/acq-mb1_bold.json' }, 'Test issue')
33+
issues.add({ code: 'TEST_FILES_ERROR', location: '/acq-mb4_bold.json' }, 'Test issue')
34+
const foundIssue = issues.get({ location: '*_bold.json' })
35+
assertEquals(foundIssue.length, 2)
36+
})
37+
2838
await t.step('test groupBy', () => {
2939
const issues = new DatasetIssues()
3040
issues.add({ code: 'NOT_INCLUDED', location: '/file_1' })

src/issues/datasetIssues.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { default as ignore } from '@ignore'
12
import { nonSchemaIssues } from './list.ts'
23
import type { Issue, IssueDefinition, IssueFile, Severity } from '../types/issues.ts'
34
export type { Issue, IssueDefinition, IssueFile, Severity }
@@ -41,7 +42,12 @@ export class DatasetIssues {
4142
if (!value) {
4243
continue
4344
}
44-
found = found.filter((x) => x[key as keyof Issue] === value)
45+
if (key === 'location' && typeof value === "string" && !value.startsWith('/')){
46+
const key_ignore = ignore().add(value as string)
47+
found = found.filter((x) => x[key] && key_ignore.ignores(x[key].slice(1, x[key].length)))
48+
} else {
49+
found = found.filter((x) => x[key as keyof Issue] === value)
50+
}
4551
}
4652
return found
4753
}

src/validators/filenameIdentify.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { assertEquals } from '@std/assert'
2+
import { SEPARATOR_PATTERN } from '@std/path'
23
import { BIDSContext } from '../schema/context.ts'
34
import { _findRuleMatches, datatypeFromDirectory, hasMatch } from './filenameIdentify.ts'
45
import { BIDSFileDeno } from '../files/deno.ts'
@@ -67,12 +68,8 @@ Deno.test('test hasMatch', async (t) => {
6768

6869
await t.step('No match', async () => {
6970
const tmpFile = Deno.makeTempFileSync()
70-
const parts = tmpFile.split('/')
71-
const file = new BIDSFileDeno(
72-
parts.slice(0, parts.length - 1).join('/'),
73-
parts[parts.length - 1],
74-
ignore,
75-
)
71+
const [ dir, base ] = tmpFile.split(SEPARATOR_PATTERN)
72+
const file = new BIDSFileDeno(dir, `/${base}`, ignore)
7673

7774
const context = new BIDSContext(file)
7875
await hasMatch(schema, context)

0 commit comments

Comments
 (0)