Skip to content

Commit 7ade93d

Browse files
authored
fix: Remove duplicates in config warnings (#6443)
1 parent baae2d6 commit 7ade93d

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

workspaces/config/lib/index.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -524,21 +524,28 @@ class Config {
524524
}
525525

526526
const typeDesc = typeDescription(type)
527-
const oneOrMore = typeDesc.indexOf(Array) !== -1
528527
const mustBe = typeDesc
529528
.filter(m => m !== undefined && m !== Array)
530-
const oneOf = mustBe.length === 1 && oneOrMore ? ' one or more'
531-
: mustBe.length > 1 && oneOrMore ? ' one or more of:'
532-
: mustBe.length > 1 ? ' one of:'
533-
: ''
534-
const msg = 'Must be' + oneOf
529+
const msg = 'Must be' + this.#getOneOfKeywords(mustBe, typeDesc)
535530
const desc = mustBe.length === 1 ? mustBe[0]
536-
: mustBe.filter(m => m !== Array)
537-
.map(n => typeof n === 'string' ? n : JSON.stringify(n))
538-
.join(', ')
531+
: [...new Set(mustBe.map(n => typeof n === 'string' ? n : JSON.stringify(n)))].join(', ')
539532
log.warn('invalid config', msg, desc)
540533
}
541534

535+
#getOneOfKeywords (mustBe, typeDesc) {
536+
let keyword
537+
if (mustBe.length === 1 && typeDesc.includes(Array)) {
538+
keyword = ' one or more'
539+
} else if (mustBe.length > 1 && typeDesc.includes(Array)) {
540+
keyword = ' one or more of:'
541+
} else if (mustBe.length > 1) {
542+
keyword = ' one of:'
543+
} else {
544+
keyword = ''
545+
}
546+
return keyword
547+
}
548+
542549
#loadObject (obj, where, source, er = null) {
543550
// obj is the raw data read from the file
544551
const conf = this.data.get(where)

0 commit comments

Comments
 (0)