Skip to content

Commit

Permalink
Refactor similar code in convertHedIssuesToBidsIssues
Browse files Browse the repository at this point in the history
  • Loading branch information
happy5214 committed Oct 20, 2023
1 parent ee66f21 commit f5e3288
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions bids/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,24 @@ class BidsHedValidator {
*/
function convertHedIssuesToBidsIssues(hedIssues, file, extraParameters) {
if (hedIssues instanceof IssueError) {
if (extraParameters) {
Object.assign(hedIssues.issue.parameters, extraParameters)
hedIssues.issue.generateMessage()
}
return [new BidsHedIssue(hedIssues.issue, file)]
return [convertHedIssueToBidsIssue(hedIssues.issue, file, extraParameters)]
} else {
return hedIssues.map((hedIssue) => {
if (extraParameters) {
Object.assign(hedIssue.parameters, extraParameters)
hedIssue.generateMessage()
}
return new BidsHedIssue(hedIssue, file)
})
return hedIssues.map((hedIssue) => convertHedIssueToBidsIssue(hedIssue, file, extraParameters))
}
}

/**
* Convert a single HED issue into a BIDS-compatible issue.
*
* @param {Issue} hedIssue One HED-format issue.
* @param {Object} file A BIDS-format file object used to generate a {@link BidsHedIssue} object.
* @param {Object?} extraParameters Any extra parameters to inject into the {@link Issue} object.
* @returns {BidsHedIssue} The passed issue in BIDS-compatible format.
*/
function convertHedIssueToBidsIssue(hedIssue, file, extraParameters) {
if (extraParameters) {
Object.assign(hedIssue.parameters, extraParameters)
hedIssue.generateMessage()
}
return new BidsHedIssue(hedIssue, file)
}

0 comments on commit f5e3288

Please sign in to comment.