From d610cad10bd6d60db20496c07a56bc9aa2d10227 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 1 Jul 2020 14:58:16 +0200 Subject: [PATCH] Add a global "no heuristics" flag for validator debugging --- src/apply-validators.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/apply-validators.js b/src/apply-validators.js index f60192c..c4460e0 100644 --- a/src/apply-validators.js +++ b/src/apply-validators.js @@ -12,7 +12,12 @@ module.exports = function applyValidators(value, rules, context = {}) { let normalizedRules = normalizeRules(rules, { normalizeObjects: true }); let validator = composeRules.compose(normalizedRules); - let { errors, newValue } = validator(value, context); + // FIXME: Document this option! + let finalContext = (process.env.VALIDATEM_NO_HEURISTICS === "1") + ? { ...context, __validatemNoHeuristics: true } + : context; + + let { errors, newValue } = validator(value, finalContext); // NOTE: We mutate the error here, because Error objects are not safely cloneable for (let error of errors) {