-
-
Notifications
You must be signed in to change notification settings - Fork 6
Linter: add rule to remove empty then else #1819
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: karan-palan <karanpalan007@gmail.com>
: SchemaTransformRule{ | ||
"then_else_empty", | ||
"`then` or `else` with an empty schema does not restrict " | ||
"validation and is likely ineffective"} {}; |
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.
"likely ineffective" is wrong. It is not likely. It does nothing, in all cases.
For consistency with other rules, can you make the message: "Setting the then
or else
keywords to the empty schema does not add any further constraint"
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.
Actually, just to make the error simpler by just talking about a single keyword, can you split this rule into two? One of then
and one for else
similar to how we catch then
without if
and else
without if
?
"http://json-schema.org/draft-07/schema#"}) && | ||
schema.is_object() && schema.defines("if") && | ||
((schema.defines("then") && schema.at("then").is_object() && | ||
schema.at("then").empty()) || |
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.
As in the other PR, remember that schemas can be either objects or boolean. You are missing checking if then
or else
are set to true
, which is also equivalent to the empty schema (and tests for those)
…er object and boolean schemas both Signed-off-by: karan-palan <karanpalan007@gmail.com>
Signed-off-by: karan-palan <karanpalan007@gmail.com>
Signed-off-by: karan-palan <karanpalan007@gmail.com>
Signed-off-by: karan-palan <karanpalan007@gmail.com>
@jviotti, The tests are passing locally, I'll look into the failing checks and resolve them. Ptal if you have some comments till then ![]() |
schema.defines("then") && is_schema(schema.at("then")) && | ||
((schema.at("then").is_object() && schema.at("then").empty()) || | ||
(schema.at("then").is_boolean() && schema.at("then").to_boolean() && | ||
!(schema.at("if").is_boolean() && schema.at("if").to_boolean()))); |
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.
Is this line really necessary? I guess the rule applies independently of if
(and even if if
is not there?)
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, is it to avoid conflicts with the other rule that removes dangling then
/else
without if
? I'm still not sure why you check for if
being a boolean. Maybe just the schema.defines("if")
is enough?
schema.defines("else") && is_schema(schema.at("else")) && | ||
((schema.at("else").is_object() && schema.at("else").empty()) || | ||
(schema.at("else").is_boolean() && schema.at("else").to_boolean() && | ||
!(schema.at("if").is_boolean() && schema.at("if").to_boolean()))); |
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.
Same comment as below
No description provided.