From f5e32888bfe8ed0cf5caf7f86ed7401e3585e213 Mon Sep 17 00:00:00 2001 From: Alexander Jones Date: Fri, 20 Oct 2023 15:41:37 -0500 Subject: [PATCH] Refactor similar code in convertHedIssuesToBidsIssues --- bids/validate.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/bids/validate.js b/bids/validate.js index 55ac89c6..5aedecbb 100644 --- a/bids/validate.js +++ b/bids/validate.js @@ -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) }