-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created 'OR' rule #48
Conversation
I forgot to push a file
If I understand the context, I think it shouldn't be a |
} else if (type === "and") { | ||
validatedConfig.rules[i] = validate<AndRule>(rule, andRuleSchema, { message }); | ||
} else if (type === "and" || type === "or") { | ||
validatedConfig.rules[i] = validate<AndRule>(rule, otherRulesSchema, { message }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda feels like these rules can be joined so the validation would work in one execution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid I don't follow. What do you mean by joined? Could you please show me an example?
I want to keep the "else" to throw if the rule is invalid, but overall, I don't worry much about removing the hardcoded code as, maybe with one or two exception, I don't think we will be adding more cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, you validate config
, and then validate each rule independently.
Can't we just join it all in a single schema to validate in one call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, I see your point.
It is because the "Basic" rule has different parameters, so I thought it would be easier to do:
if (rule.type === "basic")
basicCheck();
else if (rule.type !== "basic")
notBasicCheck();
And that's is simply because I don't know how to make a conditional rule with JOI in which:
- If the type string has the value
basic
it should use a particular schema type - if the type string does not have the value
basic
it needs to have a different schema validating it.
I don't know how to do a conditional check like that. If you do know, please let me know, as I have spend some time researching that and decided to go for the simplest solution instead of fighting for the most elegant one.
I'll be merging this PR as the union should be handled in a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean like Joi.alternatives()
?
const BasicSchema = Joi.object({
type: "basic",
data: Joi.object({a: Joi.string()})
});
const NonBasicSchema = Joi.object({
// I'm personally more inclined to have positive checks instead
type: Joi.any().not("basic"),
data: Joi.object({b: Joi.string()})
});
Joi.alternatives().try(BasicSchema, NonBasicSchema);
Co-authored-by: Przemek Rzad <roopert7@gmail.com>
Hello, and welcome to Javier's list of new changes. Today, we have a new feature: The OR rule
List of changes
OR
ruleOR
rule fails, it shows all the users it needs a review but it only shows the amount of missing reviews using the sub condition with the minimum amount of reviews needed.AND
as they share logic and structure.