Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Karan-Palan
Copy link
Contributor

No description provided.

Signed-off-by: karan-palan <karanpalan007@gmail.com>
@Karan-Palan Karan-Palan marked this pull request as ready for review July 6, 2025 20:11
@Karan-Palan Karan-Palan changed the title feat(alterschema): [linter] add rule to remove empty then else Linter: add rule to remove empty then else Jul 6, 2025
: SchemaTransformRule{
"then_else_empty",
"`then` or `else` with an empty schema does not restrict "
"validation and is likely ineffective"} {};
Copy link
Member

@jviotti jviotti Jul 7, 2025

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"

Copy link
Member

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()) ||
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants