Skip to content

Commit

Permalink
Diagnostics: Enclose valid options in quotes to improve their readabi…
Browse files Browse the repository at this point in the history
…lity (`""`)

(Same for valid parent blocks.)
  • Loading branch information
afflerbach committed May 27, 2022
1 parent 268df13 commit db86e16
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const REGEXES = {
boolean: /^(true|false)$/
}

function makeQuotedList(array) {
return array.map(option => `"${option}"`).join(", ")
}

const CheckOK = {ok: true}

function CheckFailed(message, severity) {
Expand All @@ -31,7 +35,7 @@ function getHint(allowedParents) {
case 1:
return `Parent must be "${allowedParents[0]}".`
default:
return `\nValid parent blocks: ${allowedParents.join(", ")}`
return `\nValid parent blocks: ${makeQuotedList(allowedParents)}`
}
}

Expand Down Expand Up @@ -96,7 +100,7 @@ function checkAttributeValue(name, value) {
}

if (element.options?.length && !isTemplate && !element.options.includes(stringValue)) {
const allowedValues = element.options.sort().join(", ")
const allowedValues = makeQuotedList(element.options.sort())
return CheckFailed(`Invalid value for "${name}", must be one of: ${allowedValues}`)
}
} else if (REGEXES.number.test(value) && type !== "number") {
Expand Down

0 comments on commit db86e16

Please sign in to comment.