feat(linter): add forbid_empty_enum rule#2287
feat(linter): add forbid_empty_enum rule#2287Vaibhav701161 wants to merge 1 commit intosourcemeta:mainfrom
Conversation
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
8006bfe to
43d131d
Compare
|
Ah, cool. Thanks for raising this up! I'm now thinking whether this can be auto-fixable or not. Here is the thing:
Can you send a PR to the tests checking what happens with an empty
|
|
Good point ! If the tests confirm that an empty I'll report back once the test suite PR is up. |
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