Skip to content

Commit

Permalink
Merge pull request #234 from VisLab/revised-validator
Browse files Browse the repository at this point in the history
Revised validator
  • Loading branch information
VisLab authored Dec 23, 2024
2 parents 916236a + 2dccbff commit dcee6f0
Show file tree
Hide file tree
Showing 110 changed files with 26,713 additions and 18,073 deletions.
83 changes: 83 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
version: '2' # required to adjust maintainability checks

checks:
argument-count:
enabled: true
config:
threshold: 4
complex-logic:
enabled: true
config:
threshold: 4
file-lines:
enabled: true
config:
threshold: 300
method-complexity:
enabled: true
config:
threshold: 5
method-count:
enabled: true
config:
threshold: 20
method-lines:
enabled: true
config:
threshold: 50
nested-control-flow:
enabled: true
config:
threshold: 4
return-statements:
enabled: true
config:
threshold: 4
similar-code:
enabled: true
config:
threshold: #language-specific defaults. overrides affect all languages.
identical-code:
enabled: true
config:
threshold: #language-specific defaults. overrides affect all languages.

exclude_patterns:
- 'config/'
- 'db/'
- 'dist/'
- 'features/'
- '**/node_modules/'
- 'script/'
- '**/spec/'
- '**/test/'
- '**/tests/'
- '**/spec_tests/'
- '**/docs/'
- 'Tests/'
- '**/vendor/'
- '**/*_test.go'
- '**/*.d.ts'
- '**/*__init__.py'
- '**/*setup.py'
- '**/setup.cfg'
- '**/static/'
- '**/constants/'
- '**/deploy_hed/'
- '**/README*'
- '**/.gitignore'
- '**/LICENSE'
- '**/examples/'
- '**/*.yml'
- '**/*.yaml'
- '**/config_template.py'
- '**/*.txt'
- '**/*.html'
- '**/.coveragerc'
- '**/*.md'
- '**/*.rst'
- '**/templates/'
- '**/conf.py'
- '**/deprecated/'
- '**/versioneer.py'
- '**/_version.py'
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[codespell]
skip = datasets,.git,*.pdf,*.svg,deprecated,*.xml,*.mediawiki,*.omn,datasets
ignore-words-list = covert,hed,recuse,afterAll
ignore-words-list = covert,hed,recuse,afterAll,hertzs
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [master]
branches: [master, develop]
pull_request:
branches: [master]
branches: [master, develop]

jobs:
Build:
Expand Down Expand Up @@ -43,8 +43,9 @@ jobs:
- name: Download dependencies
run: npm ci
- name: Test & publish code coverage
uses: paambaati/codeclimate-action@v8.0.0
uses: paambaati/codeclimate-action@v9.0.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
config: .codeclimate.yml
coverageCommand: ./node_modules/.bin/jest --coverage --testPathIgnorePatterns=spec_tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dist/
spec_tests/*.txt
spec_tests/temp*.json
spec_tests/temp.spec.js
tests/temp.spec.js

# Unit test / coverage reports
htmlcov/
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# hed-validator

This package contains a JavaScript validator for HED (hierarchical event descriptor) strings.
This package contains a JavaScript validator for HED (Hierarchical Event Descriptor) strings.

[HED](https://www.hedtags.org/) is a system for annotating events using comma-separated path strings.
Any type of event can be annotated using HED-type syntax.
Expand Down Expand Up @@ -57,3 +57,8 @@ To use the `hed-validator`, you must install the npm `hed-validator` package and

A sample of current `hed-validator` usage can be found in the BIDS validator in
[`hed.js`](https://github.com/bids-standard/bids-validator/blob/5dfc3938ea8ce128c7db295e7bebc8eed2de1ce6/bids-validator/validators/hed.js).

## Repository notes:

The `develop` branch is now the default branch. All changes to the repository should
be done as PRs (pull requests) to the `develop` branch.
8 changes: 3 additions & 5 deletions bids/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import buildBidsSchemas from './schema'
import validateBidsDataset from './validate'
import { BidsJsonFile, BidsSidecar } from './types/json'
import { BidsEventFile, BidsTabularFile, BidsTsvFile } from './types/tsv'
import { BidsTabularFile, BidsTsvFile } from './types/tsv'
import BidsDataset from './types/dataset'
import { BidsHedIssue, BidsIssue } from './types/issues'
import BidsHedSidecarValidator from './validator/bidsHedSidecarValidator'
import BidsHedTsvValidator from './validator/bidsHedTsvValidator'
import BidsHedSidecarValidator from './validator/sidecarValidator'
import BidsHedTsvValidator from './validator/tsvValidator'

export {
BidsDataset,
BidsTsvFile,
BidsEventFile,
BidsTabularFile,
BidsJsonFile,
BidsSidecar,
Expand All @@ -25,7 +24,6 @@ export {
export default {
BidsDataset,
BidsTsvFile,
BidsEventFile,
BidsTabularFile,
BidsJsonFile,
BidsSidecar,
Expand Down
10 changes: 5 additions & 5 deletions bids/schema.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import castArray from 'lodash/castArray'
import semver from 'semver'

import { buildSchemas } from '../validator/schema/init'
import { generateIssue, IssueError } from '../common/issues/issues'
import { SchemaSpec, SchemasSpec } from '../common/schema/types'
import { buildSchemas } from '../schema/init'
import { IssueError } from '../common/issues/issues'
import { SchemaSpec, SchemasSpec } from '../schema/specs'

const alphabeticRegExp = new RegExp('^[a-zA-Z]+$')

Expand Down Expand Up @@ -31,7 +31,7 @@ export async function buildBidsSchemas(datasetDescription, schemaDefinition) {
* @returns {SchemasSpec|null} The schema specification to be used to build the schemas, or null if the specification is missing.
* @throws {IssueError} If the schema specification is invalid.
*/
function buildSchemasSpec(datasetDescription, schemaDefinition) {
export function buildSchemasSpec(datasetDescription, schemaDefinition) {
if (schemaDefinition) {
return validateSchemasSpec(schemaDefinition)
} else if (datasetDescription.jsonData?.HEDVersion) {
Expand Down Expand Up @@ -104,4 +104,4 @@ function splitLibraryAndVersion(schemaVersion, originalVersion) {
return [library, version]
}

export default buildBidsSchemas
//export default buildBidsSchemas
21 changes: 17 additions & 4 deletions bids/types/basic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BidsHedIssue } from './issues'
import { generateIssue } from '../../common/issues/issues'

/**
* A BIDS file.
Expand Down Expand Up @@ -36,15 +37,27 @@ export class BidsFile {
return false
}

validate(hedSchemas) {
/**
* Validate this validator's tsv file
*
* @param {Schemas} schemas
* @returns {BidsIssue[]} Any issues found during validation of this TSV file.
*/
validate(schemas) {
if (!this.hasHedData()) {
return []
} else if (hedSchemas === null) {
return null
}
if (!schemas) {
BidsHedIssue.fromHedIssue(
generateIssue('genericError', {
message: 'BIDS file HED validation requires a HED schema, but the schema received was null.',
}),
{ path: this.file.file, relativePath: this.file.file },
)
}

try {
const validator = new this.validatorClass(this, hedSchemas)
const validator = new this.validatorClass(this, schemas)
return validator.validate()
} catch (internalError) {
return BidsHedIssue.fromHedIssues(internalError, this.file)
Expand Down
4 changes: 1 addition & 3 deletions bids/types/dataset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { fallbackDatasetDescription } from './json'

export class BidsDataset {
/**
* The dataset's event file data.
Expand All @@ -22,7 +20,7 @@ export class BidsDataset {
*/
datasetRootDirectory

constructor(eventData, sidecarData, datasetDescription = fallbackDatasetDescription, datasetRootDirectory = null) {
constructor(eventData, sidecarData, datasetDescription, datasetRootDirectory = null) {
this.eventData = eventData
this.sidecarData = sidecarData
this.datasetDescription = datasetDescription
Expand Down
2 changes: 1 addition & 1 deletion bids/types/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class BidsIssue {
* Determine if any of the passed issues are errors.
*
* @param {BidsIssue[]} issues A list of issues.
* @return {boolean} Whether any of the passed issues are errors (rather than warnings).
* @returns {boolean} Whether any of the passed issues are errors (rather than warnings).
*/
static anyAreErrors(issues) {
return issues.some((issue) => issue.isError())
Expand Down
Loading

0 comments on commit dcee6f0

Please sign in to comment.