Skip to content

Commit de1629a

Browse files
authored
fix: Consistent use of quotes in output (#405)
Also use template literals in code instead of string concatenation Co-authored-by: Marc-Aurèle DARCHE <[email protected]>
1 parent 18d9115 commit de1629a

4 files changed

Lines changed: 19 additions & 26 deletions

File tree

packages/convict/src/main.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function flatten(obj, useProperties) {
9191
if (useProperties) {
9292
if ('_cvtProperties' in val) {
9393
val = val._cvtProperties
94-
key = key + '._cvtProperties'
94+
key = `${key}._cvtProperties`
9595
} else {
9696
entries.push([key, val])
9797
continue
@@ -102,7 +102,7 @@ function flatten(obj, useProperties) {
102102
// Don't filter out empty objects
103103
if (subkeys.length > 0) {
104104
subkeys.forEach(function(subkey) {
105-
stack.push(key + '.' + subkey)
105+
stack.push(`${key}.${subkey}`)
106106
})
107107
continue
108108
}
@@ -147,8 +147,7 @@ function validate(instance, schema, strictValidation) {
147147
throw new Error('missing')
148148
}
149149
} catch (e) {
150-
const err = new Error("configuration param '" + name
151-
+ "' missing from config, did you override its parent?")
150+
const err = new Error(`configuration param '${name}' missing from config, did you override its parent?`)
152151
errors.missing.push(err)
153152
return
154153
}
@@ -159,7 +158,7 @@ function validate(instance, schema, strictValidation) {
159158
if (schemaItem.format === 'object' || typeof schemaItem.default === 'object') {
160159
Object.keys(flatInstance)
161160
.filter(function(key) {
162-
return key.lastIndexOf(name + '.', 0) === 0
161+
return key.lastIndexOf(`${name}.`, 0) === 0
163162
}).forEach(function(key) {
164163
delete flatInstance[key]
165164
})
@@ -179,8 +178,7 @@ function validate(instance, schema, strictValidation) {
179178

180179
if (strictValidation) {
181180
Object.keys(flatInstance).forEach(function(name) {
182-
const err = new Error("configuration param '" + name
183-
+ "' not declared in the schema")
181+
const err = new Error(`configuration param '${name}' not declared in the schema`)
184182
errors.undeclared.push(err)
185183
})
186184
}
@@ -190,8 +188,8 @@ function validate(instance, schema, strictValidation) {
190188

191189
// helper for asserting that a value is in the list of valid options
192190
function contains(options, x) {
193-
assert(options.indexOf(x) !== -1, 'must be one of the possible values: ' +
194-
JSON.stringify(options))
191+
assert(options.indexOf(x) !== -1,
192+
`must be one of the possible values: ${JSON.stringify(options)}`)
195193
}
196194

197195
const BUILT_INS_BY_NAME = {
@@ -209,7 +207,7 @@ const BUILT_INS = BUILT_IN_NAMES.map(function(name) {
209207

210208
function normalizeSchema(name, node, props, fullName, env, argv, sensitive) {
211209
if (name === '_cvtProperties') {
212-
throw new Error("'" + fullName + "': '_cvtProperties' is reserved word of convict.")
210+
throw new Error(`'${fullName}': '_cvtProperties' is reserved word of convict.`)
213211
}
214212

215213
// If the current schema node is not a config property (has no "default"), recursively normalize it.
@@ -219,8 +217,7 @@ function normalizeSchema(name, node, props, fullName, env, argv, sensitive) {
219217
_cvtProperties: {}
220218
}
221219
Object.keys(node).forEach(function(k) {
222-
normalizeSchema(k, node[k], props[name]._cvtProperties, fullName + '.' +
223-
k, env, argv, sensitive)
220+
normalizeSchema(k, node[k], props[name]._cvtProperties, `${fullName}.${k}`, env, argv, sensitive)
224221
})
225222
return
226223
} else if (typeof node !== 'object' || Array.isArray(node) ||
@@ -242,8 +239,7 @@ function normalizeSchema(name, node, props, fullName, env, argv, sensitive) {
242239
// associate this property with a command-line argument
243240
if (o.arg) {
244241
if (argv[o.arg]) {
245-
throw new Error("'" + fullName + "' reuses a command-line argument: " +
246-
o.arg)
242+
throw new Error(`'${fullName}' reuses a command-line argument: ${o.arg}`)
247243
}
248244
argv[o.arg] = fullName
249245
}
@@ -263,16 +259,14 @@ function normalizeSchema(name, node, props, fullName, env, argv, sensitive) {
263259
const Format = typeof format === 'string' ? BUILT_INS_BY_NAME[format] : format
264260
newFormat = function(x) {
265261
assert(Object.prototype.toString.call(x) ==
266-
Object.prototype.toString.call(new Format()),
267-
'must be of type ' + Format.name)
262+
Object.prototype.toString.call(new Format()), `must be of type ${Format.name}`)
268263
}
269264
o.format = Format.name.toLowerCase()
270265

271266
} else if (typeof format === 'string') {
272267
// store declared type
273268
if (!types[format]) {
274-
throw new Error("'" + fullName + "' uses an unknown format type: " +
275-
format)
269+
throw new Error(`'${fullName}' uses an unknown format type: ${format}`)
276270
}
277271

278272
// use a predefined type
@@ -286,8 +280,7 @@ function normalizeSchema(name, node, props, fullName, env, argv, sensitive) {
286280
newFormat = format
287281

288282
} else if (format && typeof format !== 'function') {
289-
throw new Error("'" + fullName +
290-
"': `format` must be a function or a known format type.")
283+
throw new Error(`'${fullName}': "format" must be a function or a known format type.`)
291284
}
292285

293286
if (!newFormat && !format) {
@@ -450,7 +443,7 @@ function walk(obj, path, initializeMissing) {
450443
} else if (k in obj) {
451444
obj = obj[k]
452445
} else {
453-
throw new Error("cannot find configuration param '" + path + "'")
446+
throw new Error(`cannot find configuration param '${path}'`)
454447
}
455448
}
456449
}
@@ -730,10 +723,10 @@ convict.addFormat = function(name, validate, coerce) {
730723
name = name.name
731724
}
732725
if (typeof validate !== 'function') {
733-
throw new Error('Validation function for ' + name + ' must be a function.')
726+
throw new Error(`Validation function for '${name}' must be a function.`)
734727
}
735728
if (coerce && typeof coerce !== 'function') {
736-
throw new Error('Coerce function for ' + name + ' must be a function.')
729+
throw new Error(`Coerce function for '${name}' must be a function.`)
737730
}
738731
types[name] = validate
739732
if (coerce) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Coerce function for invalidCoercer must be a function.
1+
Coerce function for 'invalidCoercer' must be a function.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'invalidFormat': `format` must be a function or a known format type.
1+
'invalidFormat': "format" must be a function or a known format type.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Validation function for invalidValidator must be a function.
1+
Validation function for 'invalidValidator' must be a function.

0 commit comments

Comments
 (0)