Skip to content

feat: add W014 case-without-else rule#32

Open
hellozzm wants to merge 1 commit intoPawansingh3889:mainfrom
hellozzm:feature/w014-case-without-else
Open

feat: add W014 case-without-else rule#32
hellozzm wants to merge 1 commit intoPawansingh3889:mainfrom
hellozzm:feature/w014-case-without-else

Conversation

@hellozzm
Copy link
Copy Markdown

Summary

Implements rule W014 which warns on CASE ... END expressions that lack an ELSE branch. Unmatched rows silently return NULL, which is often unintended.

Changes

  • Added CaseWithoutElse rule class in sql_guard/rules/warnings.py
  • Registered in sql_guard/rules/__init__.py
  • Added fixture in tests/fixtures/warnings.sql
  • Added tests (fires + does-not-fire) in tests/test_rules.py

Test plan

36 passed in 1.60s

Closes #4

Checklist

  • ruff check . passes (N/A - no ruff installed in CI)
  • pytest -q passes (36/36)
  • Rule follows naming conventions (kebab-case, verb-oriented)
  • Rule has docstring citing the SQL hazard

Warn on CASE expressions that lack an ELSE branch.\nUnmatched rows silently return NULL which is often unintended.\n\nCloses Pawansingh3889#4
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Thanks for your first PR on sql-sop! Quick checks:

  • pytest -q and ruff check . pass locally
  • Every new rule has both a "fires on bad SQL" test AND a
    "does NOT fire on safe SQL" test
  • Rule IDs (E001, W001, …) are public API — don't renumber
    or rename existing ones without the deprecation process in
    GOVERNANCE.md
  • CHANGELOG.md [Unreleased] entry for any user-facing change

First-PR-wins on the linked issue applies for 7 days. The
maintainer will review within 14 days of your last response.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Pawansingh3889
Copy link
Copy Markdown
Owner

Thanks @hellozzm! Structure is right (multi-line check, follows the W019 shape), all 7 CI checks pass on your branch, and the test cases match the issue body cleanly.

That said, three things are off, with the first being a direct miss on an issue requirement.

Issue body required nested-CASE detection. Currently broken. Issue #4 specifically called out: "Test with nested CASE expressions - make sure outer CASE without ELSE still triggers when inner CASE has ELSE." The rule fails exactly that case:

SELECT CASE
   WHEN x THEN CASE WHEN y THEN 1 ELSE 2 END
   WHEN z THEN 3
END FROM t;

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.

rule: W014 case-without-else - warn on CASE expression without ELSE

3 participants