Skip to content

feat!: preserve line breaks between consecutive comments in pretty mode#7770

Merged
tobymao merged 2 commits into
mainfrom
fix/comments-pretty-mode-newlines
Jun 20, 2026
Merged

feat!: preserve line breaks between consecutive comments in pretty mode#7770
tobymao merged 2 commits into
mainfrom
fix/comments-pretty-mode-newlines

Conversation

@tobymao

@tobymao tobymao commented Jun 20, 2026

Copy link
Copy Markdown
Owner

When multiple comments are attached to the same expression (e.g., from consecutive -- comment lines before a SELECT), they were joined with spaces even in pretty mode. Now they are joined with the generator's separator (newline in pretty mode, space otherwise).

Additionally, _replace_line_breaks is applied per-comment content rather than post-join, so newlines between separate comments get proper SQL indentation while newlines within a single multi-line comment remain as sentinels to prevent extra indentation.

Closes #7764

When multiple comments were attached to the same expression (e.g., from
consecutive -- comment lines before a SELECT), they were joined with
spaces even in pretty mode. Now they are joined with the generator's
separator (newline in pretty mode, space otherwise).

Additionally, _replace_line_breaks is applied per-comment content rather
than post-join, so newlines between separate comments get proper SQL
indentation while newlines within a single multi-line comment remain as
sentinels to prevent extra indentation.

Closes #7764
@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

SQLGlot Integration Test Results

✅ All tests passed

Comparing:

  • this branch (sqlglot:fix/comments-pretty-mode-newlines @ sqlglot 1ab36c6)
  • baseline (main @ sqlglot 12eba76)

Overall

main: 192428 total, 153523 passed (pass rate: 79.8%)

sqlglot:fix/comments-pretty-mode-newlines: 190119 total, 151503 passed (pass rate: 79.7%)

Transitions:
No change

Dialect pair changes: 0 previous results not found, 1 current results not found

✅ All tests passed

Comment thread tests/test_transpile.py Outdated
Leading/separated comments still join with self.sep() (newlines in pretty
mode), which is safe since they all precede the same token. Trailing
comments must stay space-joined to avoid detaching later comments onto
the next node when re-parsed.

Co-authored-by: George Sittas <georgesittas@gmail.com>
@tobymao tobymao merged commit 5ad2add into main Jun 20, 2026
8 checks passed
@tobymao tobymao deleted the fix/comments-pretty-mode-newlines branch June 20, 2026 18:23
@betodealmeida

Copy link
Copy Markdown
Contributor

Thank you!

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.

Comments in different lines combined into a single line

3 participants