Skip to content

Commit

Permalink
Validate config selectors are not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 16, 2022
1 parent 91875c4 commit 9415902
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/config/select/normalize.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import isPlainObj from 'is-plain-obj'
import mapObj from 'map-obj'

import { UserError } from '../../error/main.js'

// If a configuration property uses selectors, normalization must be applied
// recursively.
export const normalizeConfigSelectors = function (
Expand All @@ -12,6 +14,8 @@ export const normalizeConfigSelectors = function (
return normalizer(configValue, propName, propName)
}

validateConfigSelector(configValue, propName)

return mapObj(configValue, (selector, value) => [
selector,
normalizer(value, propName, `${propName}.${selector}`),
Expand All @@ -23,6 +27,14 @@ export const isConfigSelector = function (configValue, propName) {
return SELECTABLE_PROPS.has(propName) && isPlainObj(configValue)
}

const validateConfigSelector = function (configValue, propName) {
if (Object.keys(configValue).length === 0) {
throw new UserError(
`'${propName}' must have at least one property when using configuration selectors.`,
)
}
}

// List of properties which can use configuration selectors
// We should avoid any properties which:
// - Are not combination-specific
Expand Down

0 comments on commit 9415902

Please sign in to comment.