feat(linter): add const_and_enum_conflict rule#2290
Open
AcEKaycgR wants to merge 1 commit intosourcemeta:mainfrom
Open
feat(linter): add const_and_enum_conflict rule#2290AcEKaycgR wants to merge 1 commit intosourcemeta:mainfrom
AcEKaycgR wants to merge 1 commit intosourcemeta:mainfrom
Conversation
There was a problem hiding this comment.
2 issues found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="test/alterschema/alterschema_lint_2019_09_test.cc">
<violation number="1" location="test/alterschema/alterschema_lint_2019_09_test.cc:4512">
P2: New const_and_enum_conflict tests do not assert both diagnostic keyword locations, so regressions in secondary-location reporting would go undetected.</violation>
</file>
<file name="test/alterschema/alterschema_lint_2020_12_test.cc">
<violation number="1" location="test/alterschema/alterschema_lint_2020_12_test.cc:9682">
P2: New `const_and_enum_conflict` tests do not assert the diagnostic’s dual keyword locations, so regressions in secondary-location reporting would go undetected.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
|
||
| EXPECT_FALSE(result.first); | ||
| EXPECT_EQ(traces.size(), 1); | ||
| EXPECT_LINT_TRACE(traces, 0, "", "const_and_enum_conflict", |
There was a problem hiding this comment.
P2: New const_and_enum_conflict tests do not assert the diagnostic’s dual keyword locations, so regressions in secondary-location reporting would go undetected.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/alterschema/alterschema_lint_2020_12_test.cc, line 9682:
<comment>New `const_and_enum_conflict` tests do not assert the diagnostic’s dual keyword locations, so regressions in secondary-location reporting would go undetected.</comment>
<file context>
@@ -9664,3 +9664,77 @@ TEST(AlterSchema_lint_2020_12, object_oneof_required_not_required_6) {
+
+ EXPECT_FALSE(result.first);
+ EXPECT_EQ(traces.size(), 1);
+ EXPECT_LINT_TRACE(traces, 0, "", "const_and_enum_conflict",
+ "The `const` and `enum` keywords are mutually exclusive; "
+ "use one or the other, not both",
</file context>
074cd14 to
be2a9a0
Compare
Signed-off-by: AcE <kintan0108@gmail.com>
be2a9a0 to
d8c5e5d
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:
const_and_enum_conflict.The rule detects schemas that declare both
constandenumkeywords simultaneously.{ "const": 1, "enum": [1, 2, 3] }Using both
constandenumtogether is redundant and contradictory.constis equivalent to a single-valueenum, so having both is always an authoring mistake and should be reported to the user.The rule emits a diagnostic when:
constis definedenumis definedThe diagnostic points to both the
constandenumkeyword locations.This rule is non auto-fixable because the correct resolution depends on the schema author's intent (whether to keep
constorenum).Implementation
The rule follows the existing alterschema linter architecture:
src/extension/alterschema/linter/const_and_enum_conflict.halterschema.ccThe rule checks:
constkeyword is definedenumkeyword is definedNote: The rule only applies from Draft 6 onward, as
constwas introduced in Draft 6.If 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:
constandenumare presentconstis presentenumis presentproperties)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
@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.
cc @Karan-Palan
Note: PR description and test structure follow the same format as 2287 for consistency.