Skip to content

lint: add oneof_min_branches rule#886

Open
AcEKaycgR wants to merge 1 commit into
sourcemeta:mainfrom
AcEKaycgR:feat/linter-oneof_min_branches
Open

lint: add oneof_min_branches rule#886
AcEKaycgR wants to merge 1 commit into
sourcemeta:mainfrom
AcEKaycgR:feat/linter-oneof_min_branches

Conversation

@AcEKaycgR

@AcEKaycgR AcEKaycgR commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new lint rule oneof_min_branches that fires when oneOf is present with fewer than 2 branches. A single-branch oneOf is redundant and a zero-branch oneOf is unsatisfiable.

Applies to Draft 4, 6, 7, 2019-09, and 2020-12.

Changes

  • src/alterschema/linter/oneof_min_branches.h - new rule
  • src/alterschema/alterschema.cc - rule registered for all five dialects
  • src/alterschema/CMakeLists.txt - header added
  • test/alterschema/alterschema_lint_draft4_test.cc - tests added
  • test/alterschema/alterschema_lint_draft6_test.cc - tests added
  • test/alterschema/alterschema_lint_draft7_test.cc - tests added
  • test/alterschema/alterschema_lint_2019_09_test.cc - tests added
  • test/alterschema/alterschema_lint_2020_12_test.cc - tests added

Part of sourcemeta/core#1975.

Review in cubic

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 8 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread test/alterschema/alterschema_lint_draft4_test.cc
Comment thread test/alterschema/alterschema_lint_2019_09_test.cc
@augmentcode

augmentcode Bot commented Jun 27, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Adds a new linter rule oneof_min_branches that flags schemas using oneOf with fewer than 2 branches (redundant with 1 branch; unsatisfiable with 0).

Changes:

  • Introduced src/alterschema/linter/oneof_min_branches.h implementing a non-mutating SchemaTransformRule that checks oneOf array size across Draft 4/6/7, 2019-09, and 2020-12 vocabularies.
  • Registered the new rule in src/alterschema/alterschema.cc so it runs as part of the linter bundle for all supported dialects.
  • Updated src/alterschema/CMakeLists.txt to include the new header in the library build.
  • Added dialect-specific tests verifying no lint for a 2-branch oneOf and a lint trace for a 1-branch oneOf.
  • Adjusted an existing 2020-12 test to account for the additional lint trace emitted by the new rule.

Technical Notes: The rule reports against the oneOf keyword and is gated by applicator vocabularies, so it only fires for dialects where oneOf is applicable.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/alterschema/linter/oneof_min_branches.h
Comment thread test/alterschema/alterschema_lint_2019_09_test.cc Outdated

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/alterschema/linter/oneof_min_branches.h

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread test/alterschema/alterschema_lint_2019_09_test.cc
@AcEKaycgR AcEKaycgR force-pushed the feat/linter-oneof_min_branches branch 3 times, most recently from 7fba29e to 552c753 Compare June 27, 2026 17:20
Signed-off-by: AcE <kintan0108@gmail.com>
@AcEKaycgR AcEKaycgR force-pushed the feat/linter-oneof_min_branches branch from 552c753 to f6faa01 Compare June 27, 2026 17:31
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