feat(linter): add forbid_empty_enum rule#2287
Open
Vaibhav701161 wants to merge 1 commit intosourcemeta:mainfrom
Open
feat(linter): add forbid_empty_enum rule#2287Vaibhav701161 wants to merge 1 commit intosourcemeta:mainfrom
Vaibhav701161 wants to merge 1 commit intosourcemeta:mainfrom
Conversation
Author
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
8006bfe to
43d131d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new lint rule:
forbid_empty_enum.The rule detects schemas declaring an empty
enumarray.{ "enum": [] }An empty
enummakes the schema unsatisfiable because no instance can ever match it.This is usually an authoring mistake and should be reported to the user.
The rule emits a diagnostic when:
enumexistsThe diagnostic points to the
enumkeyword location.This rule is non auto-fixable because the correct resolution depends on the schema author's intent.
Implementation
The rule follows the existing alterschema linter architecture:
src/extension/alterschema/linter/forbid_empty_enum.halterschema.ccSOURCESlist in the alterschema CMake configurationThe rule checks:
enumkeyword is definedenumis an arrayIf these conditions are met the rule returns:
Tests
Tests were added across supported dialects using the existing lint testing utilities.
The following scenarios are covered:
enumenumcontains valuesenumis absentproperties)All tests follow the patterns used by existing lint rule tests.
Related Work
This rule addresses one of the pending lint rules listed in:
Refs: #1975