Skip to content

Commit

Permalink
Add isError method to Issue class
Browse files Browse the repository at this point in the history
This parallels the method in BidsIssue of the same name,

The static method Issue.issueListWithValidStatus was also documented.
  • Loading branch information
happy5214 committed Oct 1, 2024
1 parent 33e598f commit 808892b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion common/issues/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ export class Issue {
this.generateMessage()
}

/**
* Whether this issue is an error.
*
* @returns {boolean}
*/
isError() {
return this.level === 'error'
}

/**
* Override of {@link Object.prototype.toString}.
*
Expand Down Expand Up @@ -118,8 +127,14 @@ export class Issue {
this.message = `${this.level.toUpperCase()}: [${this.hedCode}] ${message} (${hedSpecLink}.)`
}

/**
* Return a tuple with a boolean denoting overall validity and all issues.
*
* @param {Issue[]} issues A list of issues.
* @returns {[boolean, Issue[]]} Whether the validation succeeded (i.e. any errors were found), and all issues (both errors and warnings).
*/
static issueListWithValidStatus(issues) {
return [!issues.some((issue) => issue.level === 'error'), issues]
return [!issues.some((issue) => issue.isError()), issues]
}
}

Expand Down

0 comments on commit 808892b

Please sign in to comment.