Skip to content

Commit

Permalink
Improve normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 16, 2022
1 parent 332fdfd commit cd0537f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/config/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,18 @@ const checkString = function (value, name) {
}

export const checkStringsObject = function (value, name) {
checkObject(value, name)
Object.entries(value).forEach(([childName, propValue]) => {
checkString(propValue, `${name}.${childName}`)
})
}

export const checkJsonDeepObject = function (value, name) {
checkObject(value, name)
Object.entries(value).forEach(([childName, propValue]) => {
checkJsonObject(propValue, `${name}.${childName}`)
})
}

export const checkJsonObject = function (value, name) {
checkObject(value, name)
Object.entries(value).forEach(([childName, propValue]) => {
checkJson(propValue, `${name}.${childName}`)
})
Expand Down
7 changes: 4 additions & 3 deletions src/config/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { normalizePrecision } from '../run/precision.js'
import {
checkBoolean,
checkInteger,
checkStringsObject,
normalizeOptionalArray,
checkArrayLength,
checkStringArray,
checkDefinedStringArray,
checkDefinedString,
checkObject,
checkStringsObject,
checkJsonObject,
} from './check.js'
import { validateConfigSelector, isConfigSelector } from './select/normalize.js'
Expand Down Expand Up @@ -71,7 +72,7 @@ const validateTitles = function (value, name) {
}

const NORMALIZERS = {
inputs: [checkJsonObject],
inputs: [checkObject, checkJsonObject],
limit: [checkInteger, normalizeLimit],
merge: [validateMerge],
outliers: [checkBoolean],
Expand All @@ -82,7 +83,7 @@ const NORMALIZERS = {
showDiff: [checkBoolean],
showPrecision: [checkBoolean],
showTitles: [checkBoolean],
system: [checkStringsObject],
system: [checkObject, checkStringsObject],
tasks: [normalizeOptionalArray, checkDefinedStringArray],
titles: [validateTitles],
}
3 changes: 2 additions & 1 deletion src/config/plugin/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cleanObject } from '../../utils/clean.js'
import { pick } from '../../utils/pick.js'
import { checkJsonDeepObject } from '../check.js'
import { checkObject, checkJsonDeepObject } from '../check.js'
import { mergeConfigs } from '../merge/main.js'

// Retrieve plugin configuration object.
Expand Down Expand Up @@ -47,6 +47,7 @@ export const addPluginsConfig = function ({
topProps,
}) {
const pluginsConfig = config[configProp]
checkObject(pluginsConfig, configProp)
checkJsonDeepObject(pluginsConfig, configProp)
return plugins.map((plugin) =>
addPluginConfig({ plugin, pluginsConfig, config, topProps }),
Expand Down

0 comments on commit cd0537f

Please sign in to comment.