Repository navigation
fix: keep strings and comments intact when re-indenting expression macro bodies - #1496
Merged
Merged
Conversation
…cro bodies The dedent that removes the formatting SELECT from an expression macro or scalar function body tracked quotes on its own: it knew only doubled quotes as escapes and `--` as a comment. On Snowflake, a multi-line string after a backslash-escaped quote lost indentation inside the string on every run, changing its value. An apostrophe in a `//` comment opened a phantom string, the lines inside a block comment lost two spaces per run, and a block comment kept on the SELECT line set the body's indent. The dedent now reads the formatted SQL with the dialect's own lexical rules: a line that starts inside a string or comment keeps its text, and the body's indent comes from its first line of code. The DuckShop edge-case macro now opens with a block comment.
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
After
sqb formatlays out an expression macro or scalar function body, it re-indents the body by tracking quotes itself. That tracker knew only doubled quotes as escapes and--as a comment, so on Snowflake:'O\'Brien) lost indentation inside the string on every run, changing its value;//comment opened a phantom string, and later lines kept the wrong indent;--checknever settled;SELECTline set the body's indent to zero.Changes
dialect_lexical_syntaxscanner). A line that starts inside a string or comment keeps its text; the indent comes from the first line of code.Verification
//comments, block comments and a comment on theSELECTline; the escaped-quote cases fail without the fix.sqb format,--checkand compile.--checkclean.cargo test -p sqlbuild-rules, the format tests, clippy andfensu checkpass.