Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@cliffy/command": "jsr:@effigies/[email protected]",
"@cliffy/table": "jsr:@effigies/[email protected]",
"@hed/validator": "npm:[email protected]",
"@ignore": "npm:ignore@6.0.2",
"@ignore": "npm:ignore@7.0.3",
"@libs/xml": "jsr:@libs/[email protected]",
"@mango/nifti": "npm:@bids/[email protected]",
"@std/assert": "jsr:@std/[email protected]",
Expand Down
16 changes: 12 additions & 4 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/user_guide/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ warnings, errors or ignored.
}
```

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

Expand Down
1 change: 0 additions & 1 deletion src/files/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class FileIgnoreRules {
config: string[],
addDefaults: boolean = true,
) {
// @ts-expect-error
this.#ignore = ignore()
if (addDefaults) {
this.#ignore.add(defaultIgnores)
Expand Down
10 changes: 10 additions & 0 deletions src/issues/datasetIssues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ Deno.test('DatasetIssues management class', async (t) => {
assertEquals(foundIssue[0].code, 'TEST_FILES_ERROR')
})

await t.step('get issues with glob pattern', () => {
const issues = new DatasetIssues()
issues.add({ code: 'TEST_FILES_ERROR', location: '/acq-mprage_T1w.json' }, 'Test issue')
issues.add({ code: 'TEST_FILES_ERROR', location: '/acq-memprage_T1w.json' }, 'Test issue')
issues.add({ code: 'TEST_FILES_ERROR', location: '/acq-mb1_bold.json' }, 'Test issue')
issues.add({ code: 'TEST_FILES_ERROR', location: '/acq-mb4_bold.json' }, 'Test issue')
const foundIssue = issues.get({ location: '*_bold.json' })
assertEquals(foundIssue.length, 2)
})

await t.step('test groupBy', () => {
const issues = new DatasetIssues()
issues.add({ code: 'NOT_INCLUDED', location: '/file_1' })
Expand Down
8 changes: 7 additions & 1 deletion src/issues/datasetIssues.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { default as ignore } from '@ignore'
import { nonSchemaIssues } from './list.ts'
import type { Issue, IssueDefinition, IssueFile, Severity } from '../types/issues.ts'
export type { Issue, IssueDefinition, IssueFile, Severity }
Expand Down Expand Up @@ -41,7 +42,12 @@ export class DatasetIssues {
if (!value) {
continue
}
found = found.filter((x) => x[key as keyof Issue] === value)
if (key === 'location' && typeof value === "string" && !value.startsWith('/')){
const key_ignore = ignore().add(value as string)
found = found.filter((x) => x[key] && key_ignore.ignores(x[key].slice(1, x[key].length)))
} else {
found = found.filter((x) => x[key as keyof Issue] === value)
}
}
return found
}
Expand Down
9 changes: 3 additions & 6 deletions src/validators/filenameIdentify.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assertEquals } from '@std/assert'
import { SEPARATOR_PATTERN } from '@std/path'
import { BIDSContext } from '../schema/context.ts'
import { _findRuleMatches, datatypeFromDirectory, hasMatch } from './filenameIdentify.ts'
import { BIDSFileDeno } from '../files/deno.ts'
Expand Down Expand Up @@ -67,12 +68,8 @@ Deno.test('test hasMatch', async (t) => {

await t.step('No match', async () => {
const tmpFile = Deno.makeTempFileSync()
const parts = tmpFile.split('/')
const file = new BIDSFileDeno(
parts.slice(0, parts.length - 1).join('/'),
parts[parts.length - 1],
ignore,
)
const [ dir, base ] = tmpFile.split(SEPARATOR_PATTERN)
const file = new BIDSFileDeno(dir, `/${base}`, ignore)

const context = new BIDSContext(file)
await hasMatch(schema, context)
Expand Down
Loading