Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove duplicates in config warnings #6443

Merged
merged 6 commits into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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