Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 16, 2022
1 parent 96a9ed4 commit 4633841
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
14 changes: 7 additions & 7 deletions src/config/normalize/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const normalizePropValue = async function (
}

const value = config[name]
const args = [name, { configInfos, config: configPromises, command }]
const opts = { name, configInfos, config: configPromises, command }

const valueA = await addDefaultValue(value, defaultValue, args)
return await runPropNormalizer(valueA, normalize, args)
const valueA = await addDefaultValue(value, defaultValue, opts)
return await runPropNormalizer(valueA, normalize, opts)
}

// All config properties can be specified in `spyd.yml` (unlike CLI flags), for
Expand Down Expand Up @@ -78,7 +78,7 @@ const COMMAND_GROUPS = {
select: ['dev', 'remove', 'run', 'show'],
}

const addDefaultValue = async function (value, defaultValue, args) {
const addDefaultValue = async function (value, defaultValue, opts) {
if (value !== undefined) {
return value
}
Expand All @@ -87,13 +87,13 @@ const addDefaultValue = async function (value, defaultValue, args) {
return defaultValue
}

return await defaultValue(...args)
return await defaultValue(opts)
}

const runPropNormalizer = async function (value, normalize, args) {
const runPropNormalizer = async function (value, normalize, opts) {
return value === undefined || normalize === undefined
? value
: await runNormalizer(normalize, value, ...args)
: await runNormalizer(normalize, value, opts)
}

const mergeConfigProps = function (configProps) {
Expand Down
52 changes: 26 additions & 26 deletions src/config/normalize/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ export const CONFIG_PROPS = {
async default() {
return await getDefaultConfig()
},
normalize(value, name) {
normalize(value, { name }) {
const valueA = normalizeOptionalArray(value)
checkArrayItems(valueA, name, checkDefinedString)
return valueA
},
},
colors: {
commands: 'report',
normalize(value, name) {
normalize(value, { name }) {
checkBoolean(value, name)
},
},
Expand All @@ -49,15 +49,15 @@ export const CONFIG_PROPS = {
default() {
return getCwd()
},
normalize(value, name, { configInfos }) {
normalize(value, { name, configInfos }) {
checkDefinedString(value, name)
return normalizeConfigPath(value, name, configInfos)
},
},
delta: {
commands: 'delta',
default: 1,
normalize(value, name) {
normalize(value, { name }) {
return normalizeDelta(value, name)
},
},
Expand All @@ -66,20 +66,20 @@ export const CONFIG_PROPS = {
default() {
return !isTtyInput()
},
normalize(value, name) {
normalize(value, { name }) {
checkBoolean(value, name)
},
},
inputs: {
commands: 'combinations',
default: {},
normalize(value, name) {
normalize(value, { name }) {
checkObjectProps(value, name, checkJson)
},
},
limit: {
commands: 'report',
normalize(value, name) {
normalize(value, { name }) {
return recurseConfigSelectors(value, name, (childValue, childName) => {
checkInteger(childValue, childName)
return normalizeLimit(childValue, childName)
Expand All @@ -91,14 +91,14 @@ export const CONFIG_PROPS = {
default() {
return getDefaultId()
},
normalize(value, name) {
normalize(value, { name }) {
checkDefinedString(value, name)
validateMerge(value, name)
},
},
output: {
commands: 'report',
normalize(value, name, { configInfos }) {
normalize(value, { name, configInfos }) {
checkDefinedString(value, name)
return isOutputPath(value)
? normalizeConfigPath(value, name, configInfos)
Expand All @@ -108,14 +108,14 @@ export const CONFIG_PROPS = {
outliers: {
commands: 'run',
default: false,
normalize(value, name) {
normalize(value, { name }) {
recurseConfigSelectors(value, name, checkBoolean)
},
},
precision: {
commands: 'run',
default: 5,
normalize(value, name) {
normalize(value, { name }) {
return recurseConfigSelectors(value, name, (childValue, childName) => {
checkInteger(childValue, childName)
return normalizePrecision(childValue, childName)
Expand All @@ -124,14 +124,14 @@ export const CONFIG_PROPS = {
},
quiet: {
commands: 'run',
normalize(value, name) {
normalize(value, { name }) {
checkBoolean(value, name)
},
},
reporter: {
commands: 'report',
default: ['debug'],
async normalize(value, name, { config: { force } }) {
async normalize(value, { name, config: { force } }) {
if (await force) {
return []
}
Expand All @@ -152,7 +152,7 @@ export const CONFIG_PROPS = {
runner: {
commands: 'combinations',
default: ['node'],
normalize(value, name) {
normalize(value, { name }) {
const valueA = normalizeOptionalArray(value)
checkArrayLength(valueA, name)
checkArrayItems(valueA, name, checkDefinedString)
Expand All @@ -166,71 +166,71 @@ export const CONFIG_PROPS = {
save: {
commands: 'run',
default: false,
normalize(value, name) {
normalize(value, { name }) {
checkBoolean(value, name)
},
},
select: {
commands: 'select',
default: [],
normalize(value, name) {
normalize(value, { name }) {
const valueA = normalizeOptionalArray(value)
checkArrayItems(valueA, name, checkString)
return valueA
},
},
showDiff: {
commands: 'report',
normalize(value, name) {
normalize(value, { name }) {
recurseConfigSelectors(value, name, checkBoolean)
},
},
showMetadata: {
commands: 'report',
default(name, { command }) {
default({ command }) {
return METADATA_COMMANDS.has(command)
},
normalize(value, name) {
normalize(value, { name }) {
checkBoolean(value, name)
},
},
showPrecision: {
commands: 'report',
default: false,
normalize(value, name) {
normalize(value, { name }) {
recurseConfigSelectors(value, name, checkBoolean)
},
},
showSystem: {
commands: 'report',
normalize(value, name) {
normalize(value, { name }) {
checkBoolean(value, name)
},
},
showTitles: {
commands: 'report',
default: false,
normalize(value, name) {
normalize(value, { name }) {
recurseConfigSelectors(value, name, checkBoolean)
},
},
since: {
commands: 'history',
default: 1,
normalize(value, name) {
normalize(value, { name }) {
return normalizeDelta(value, name)
},
},
system: {
commands: 'combinations',
default: {},
normalize(value, name) {
normalize(value, { name }) {
checkObjectProps(value, name, checkDefinedString)
},
},
tasks: {
commands: 'combinations',
normalize(value, name, { configInfos }) {
normalize(value, { name, configInfos }) {
const valueA = normalizeOptionalArray(value)
return checkArrayItems(valueA, name, (childValue, childName) => {
checkDefinedString(childValue, childName)
Expand All @@ -241,7 +241,7 @@ export const CONFIG_PROPS = {
titles: {
commands: 'report',
default: {},
normalize(value, name) {
normalize(value, { name }) {
checkObjectProps(value, name, checkDefinedString)
},
},
Expand Down

0 comments on commit 4633841

Please sign in to comment.