Repository navigation
Fix non-converging indentation of adjacent string constants - #411
Merged
darold merged 2 commits intoSep 19, 2026
Merged
Conversation
Adjacent string constants separated by a newline are tokenized as a
single token whose inner whitespace is kept verbatim, then _add_token
prefixes $sp to every constant it holds. Since $sp is a single space
when the token is not at the start of a line, the whitespace already
produced by a previous run was never normalized and one space was
appended on every run, so the output never converged.
Rebuild the separators instead: a single space when the constants are
on the same line, the current indentation after a newline.
Before, formatting three times in a row:
SELECT concat('a' , x , ' AU '
'b') AS lib
SELECT concat('a' , x , ' AU '
'b') AS lib
SELECT concat('a' , x , ' AU '
'b') AS lib
After:
SELECT
concat('a', x, ' AU '
'b') AS lib
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.
What
Fix: adjacent string constants separated by a newline (implicit concatenation) gained one space of indentation on every run, so the output never converged.
Fixes #410.
Before
Formatting the same input three times in a row:
After
Stable from the first run, and the continuation line now follows the current indentation instead of staying at column 1.
Why
tokenize_sqlkeeps consecutive constants in a single token and preserves the whitespace between them verbatim (the rule commentedpreserved multiple constants with newline)._add_tokenthen prefixed$spto every constant of that token without normalizing the whitespace already present.$spis a single space when the token is not at the start of a line, so each run appended one more space to what the previous run had produced.The fix rebuilds the separators rather than prefixing them: a single space when the constants are on the same line, the current indentation after a newline. That makes the result independent of the input spacing, which is what idempotency requires.
Tests