Repository navigation
fix(rules): keep SQLCLEAN013 and SQLCLEAN030 fixes meaning-preserving - #19
Merged
Merged
Conversation
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.
Deploying sqlclean with
|
| Latest commit: |
443587a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://efa797c2.sqlclean.pages.dev |
| Branch Preview URL: | https://fix-safe-rewrites.sqlclean.pages.dev |
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.
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.
Why
Two fixes
sqlclean fixlabels safe change what a query returns:SQLCLEAN013turnsDISTINCT(price + tax) * 2intoDISTINCT price + tax * 2.SQLCLEAN030turnsCASE WHEN a THEN TRUE AND b ELSE FALSE ENDintoCOALESCE(a, FALSE), droppingAND b.SQLCLEAN003also reportsJOIN t ON (a = b OR c = d)as a join without a real condition, because it read only the tokens outside the parentheses.Changes
SQLCLEAN013offers its fix only when the parentheses hold the whole select item; otherwise the finding stays, without a fix.SQLCLEAN030reports only a CASE whose every branch returns exactlyTRUE.SQLCLEAN003reads the tokens inside parentheses too, so a parenthesized condition counts whileON (1 = 1)is still reported.SQLCLEAN012,015,023and042, which it left out.Verification
make verify,make test-integration test-e2e, clippy on 1.95,fensu checkand the hygiene scan all pass.sqlclean fix --diffon the 013 and 030 examples leaves the SQL unchanged.