Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 29, 2022
1 parent 9f8da8d commit ab033ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/config/normalize/lib/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const callFunc = async function ({ func, input, info, hasInput, test }) {
// Most rule methods follow the same patterns:
// - Called with `input` and `info`
// - Optionally async
const callInputFunc = async function (userFunc, input, info) {
export const callInputFunc = async function (userFunc, input, info) {
try {
return await callUserFunc(userFunc.bind(undefined, input), info)
} catch (error) {
Expand Down
11 changes: 4 additions & 7 deletions src/config/normalize/lib/keywords/skip.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { callFunc } from '../call.js'
import { callInputFunc } from '../call.js'

// `undefined` definitions are always skipped because:
// - It allows any keyword to be disabled by setting `definition` to
Expand All @@ -20,7 +20,7 @@ export const shouldSkipKeyword = async function ({
return (
definition === undefined ||
(!undefinedInput && input === undefined) ||
(await hasSkippedTest({ test, input, info, undefinedInput }))
(await hasSkippedTest(test, input, info))
)
}

Expand All @@ -34,11 +34,8 @@ export const shouldSkipKeyword = async function ({
// specific value (e.g. `undefined` for `required|default` keywords), i.e.
// need to check the input during `test()` but should not pass it during
// `main()` nor the definition function
const hasSkippedTest = async function ({ test, input, info }) {
return (
test !== undefined &&
!(await callFunc({ func: test, input, info, hasInput: true }))
)
const hasSkippedTest = async function (test, input, info) {
return test !== undefined && !(await callInputFunc(test, input, info))
}

// Function definitions returning `undefined` are skipped, unless
Expand Down

0 comments on commit ab033ea

Please sign in to comment.