Skip to content

Commit

Permalink
fix: Remove duplicates in config warnings (#6443)
Browse files Browse the repository at this point in the history
  • Loading branch information
kashyapkaki authored May 15, 2023
1 parent baae2d6 commit 7ade93d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions workspaces/config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,21 +524,28 @@ class Config {
}

const typeDesc = typeDescription(type)
const oneOrMore = typeDesc.indexOf(Array) !== -1
const mustBe = typeDesc
.filter(m => m !== undefined && m !== Array)
const oneOf = mustBe.length === 1 && oneOrMore ? ' one or more'
: mustBe.length > 1 && oneOrMore ? ' one or more of:'
: mustBe.length > 1 ? ' one of:'
: ''
const msg = 'Must be' + oneOf
const msg = 'Must be' + this.#getOneOfKeywords(mustBe, typeDesc)
const desc = mustBe.length === 1 ? mustBe[0]
: mustBe.filter(m => m !== Array)
.map(n => typeof n === 'string' ? n : JSON.stringify(n))
.join(', ')
: [...new Set(mustBe.map(n => typeof n === 'string' ? n : JSON.stringify(n)))].join(', ')
log.warn('invalid config', msg, desc)
}

#getOneOfKeywords (mustBe, typeDesc) {
let keyword
if (mustBe.length === 1 && typeDesc.includes(Array)) {
keyword = ' one or more'
} else if (mustBe.length > 1 && typeDesc.includes(Array)) {
keyword = ' one or more of:'
} else if (mustBe.length > 1) {
keyword = ' one of:'
} else {
keyword = ''
}
return keyword
}

#loadObject (obj, where, source, er = null) {
// obj is the raw data read from the file
const conf = this.data.get(where)
Expand Down

0 comments on commit 7ade93d

Please sign in to comment.