Skip to content

feat(linter): add forbid_empty_enum rule#2287

Open
Vaibhav701161 wants to merge 1 commit intosourcemeta:mainfrom
Vaibhav701161:feat/linter-forbid-empty-enum
Open

feat(linter): add forbid_empty_enum rule#2287
Vaibhav701161 wants to merge 1 commit intosourcemeta:mainfrom
Vaibhav701161:feat/linter-forbid-empty-enum

Conversation

@Vaibhav701161
Copy link

Summary

This PR introduces a new lint rule: forbid_empty_enum.

The rule detects schemas declaring an empty enum array.

{
  "enum": []
}

An empty enum makes 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:

  • enum exists
  • the value is an array
  • the array is empty

The diagnostic points to the enum keyword 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:

  • implemented as a header-only rule in
    src/extension/alterschema/linter/forbid_empty_enum.h
  • registered in alterschema.cc
  • added to the SOURCES list in the alterschema CMake configuration

The rule checks:

  • schema node is an object
  • enum keyword is defined
  • enum is an array
  • array length is zero

If these conditions are met the rule returns:

APPLIES_TO_KEYWORDS("enum")

Tests

Tests were added across supported dialects using the existing lint testing utilities.

The following scenarios are covered:

  1. Rule fires for an empty enum
  2. Rule does not fire when enum contains values
  3. Rule does not fire when enum is absent
  4. Rule fires inside nested subschemas (e.g. inside properties)

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

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 8 files

@Vaibhav701161
Copy link
Author

@jviotti Could you please review this pull request when you have a moment?

If the approach looks good, I’d be happy to continue implementing additional linting rules listed in #1975.

Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
@Vaibhav701161 Vaibhav701161 force-pushed the feat/linter-forbid-empty-enum branch from 8006bfe to 43d131d Compare March 7, 2026 15:36
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.

1 participant