Skip to content

fix(rules): keep SQLCLEAN013 and SQLCLEAN030 fixes meaning-preserving - #19

Merged
kvlonge merged 2 commits into
mainfrom
fix/safe-rewrites
Oct 31, 2026
Merged

kvlonge merged 2 commits into
mainfrom
fix/safe-rewrites

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Why

Two fixes sqlclean fix labels safe change what a query returns:

  • SQLCLEAN013 turns DISTINCT(price + tax) * 2 into DISTINCT price + tax * 2.
  • SQLCLEAN030 turns CASE WHEN a THEN TRUE AND b ELSE FALSE END into COALESCE(a, FALSE), dropping AND b.

SQLCLEAN003 also reports JOIN t ON (a = b OR c = d) as a join without a real condition, because it read only the tokens outside the parentheses.

Changes

  • SQLCLEAN013 offers its fix only when the parentheses hold the whole select item; otherwise the finding stays, without a fix.
  • SQLCLEAN030 reports only a CASE whose every branch returns exactly TRUE.
  • SQLCLEAN003 reads the tokens inside parentheses too, so a parenthesized condition counts while ON (1 = 1) is still reported.
  • The Rule reference lists the safe fixes of SQLCLEAN012, 015, 023 and 042, which it left out.

Verification

  • New regression cases for all three Rules fail on main and pass here.
  • make verify, make test-integration test-e2e, clippy on 1.95, fensu check and the hygiene scan all pass.
  • sqlclean fix --diff on the 013 and 030 examples leaves the SQL unchanged.

SQLCLEAN013 removed the parentheses of DISTINCT(price + tax) * 2, which
regrouped the expression as price + tax * 2. It now offers the fix only
when the parentheses hold the whole select item.

SQLCLEAN030 matched CASE WHEN a THEN TRUE AND b ELSE FALSE END and
rewrote it to COALESCE(a, FALSE), dropping AND b. It now reports only a
CASE whose every branch returns exactly TRUE.

The Rule reference also lists the safe fixes of SQLCLEAN012, 015, 023 and
042, which it omitted.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Deploying sqlclean with  Cloudflare Pages  Cloudflare Pages

Latest commit: 443587a
Status: ✅  Deploy successful!
Preview URL: https://efa797c2.sqlclean.pages.dev
Branch Preview URL: https://fix-safe-rewrites.sqlclean.pages.dev

View logs

SQLCLEAN003 read only the direct tokens after ON, so ON (a = b OR c = d) looked empty and was reported. It now reads nested tokens too, while ON (1 = 1) is still reported.
@kvlonge
kvlonge merged commit 3b9f539 into main Oct 31, 2026
17 checks passed
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