What is the reason to replace existing rule with new rule when longer? #13
-
Hi 👋 I'm failing to understand this particular piece of code here: if (errorMessageByKey[key]) {
const existingRule = errorMessageByKey[key];
/**
* If the new rule is longer than the existing rule,
* replace the existing rule with the new rule.
*/
errorMessageByKey[key] =
newError.length > existingRule.error.length
? errorObj
: existingRule;
} else {
errorMessageByKey[key] = errorObj;
} What is the intention? |
Beta Was this translation helpful? Give feedback.
Answered by
mattpocock
Apr 28, 2022
Replies: 1 comment 1 reply
-
The reason is that some errors are actually a subset of other errors - i.e: "{0} is bad" In that case, we want to choose the longer version of the same rule. HOWEVER - this code might not be needed any more, we should add tests in this area to check it out. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
eddyw
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The reason is that some errors are actually a subset of other errors - i.e:
"{0} is bad"
"{0} is bad because of something"
In that case, we want to choose the longer version of the same rule.
HOWEVER - this code might not be needed any more, we should add tests in this area to check it out.