Skip to content

Compact CTE formatting and apply table name format to CTE definitions#15

Merged
kinnell merged 1 commit into
mainfrom
cte-update
Apr 8, 2026
Merged

Compact CTE formatting and apply table name format to CTE definitions#15
kinnell merged 1 commit into
mainfrom
cte-update

Conversation

@kinnell
Copy link
Copy Markdown
Owner

@kinnell kinnell commented Apr 8, 2026

Description

This PR serves to simplify CTE formatting by removing the keyword-column-aligned padding and applying table name formatting to CTE definition names.

Previously, the with keyword was padded to the keyword column width (e.g. with ), CTE body lines were indented from the keyword column, the closing paren was placed at the keyword column, and subsequent CTE definitions were aligned to the keyword column. This produced deeply indented CTE bodies that drifted far to the right, especially with wider keyword column widths or nested CTEs.

The with prefix is now compact (with ), CTE body lines are indented by indent_spaces from column zero, and the closing paren sits at column zero. CTE definition names also now follow the table_name_format setting (PascalCase by default), matching how CTE references were already formatted in FROM clauses.

@kinnell kinnell self-assigned this Apr 8, 2026
@kinnell kinnell requested a review from Copilot April 8, 2026 20:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates how Common Table Expressions (CTEs) are rendered by SqlBeautifier, making WITH formatting compact (no keyword-column padding) and applying table_name_format to CTE definition names so CTE headers match how CTE references are formatted elsewhere (e.g., in FROM).

Changes:

  • Switch CTE rendering to a compact with prefix and indent CTE bodies by indent_spaces from column zero (with the closing ) at column zero).
  • Apply table_name_format to CTE definition names in WITH ... AS ( headers (while preserving quoted identifiers).
  • Update/extend specs and add changelog notes to reflect the new formatting behavior.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/sql_beautifier/cte_query.rb Implements compact WITH prefix and removes keyword-column-based indentation for CTE definitions/bodies.
lib/sql_beautifier/cte_definition.rb Formats CTE definition names using table_name_format (except for quoted identifiers).
spec/sql_beautifier/statement_splitter.spec.rb Updates splitter expectations to use non-generic CTE names and ensure CTE statements remain intact.
spec/sql_beautifier/formatter.spec.rb Updates CTE formatting expectations (header/body/paren positioning) and adds a DELETE+USING CTE integration case.
spec/sql_beautifier/cte_formatter.spec.rb Updates CTE formatter expectations for compact rendering and formatted CTE header names.
spec/sql_beautifier/create_table_as_formatter.spec.rb Adjusts CTE-related expectations embedded in CREATE TABLE AS formatting.
spec/sql_beautifier/configuration/trailing_semicolon.spec.rb Updates expected output for CTE formatting when trailing semicolons are configured.
spec/sql_beautifier/configuration/table_name_format.spec.rb Updates expectations so CTE headers also follow table_name_format.
spec/sql_beautifier/configuration/keyword_column_width.spec.rb Updates expectations to reflect keyword column width no longer affecting CTE header/body indentation.
spec/sql_beautifier/configuration/keyword_case.spec.rb Updates expected casing behavior for CTE keywords under keyword-case configs.
spec/sql_beautifier/configuration/indent_spaces.spec.rb Updates expected indentation behavior for CTE bodies under different indent_spaces values.
spec/sql_beautifier.spec.rb Updates end-to-end CTE formatting expectations and nested CTE-in-CTAS formatting.
CHANGELOG.md Documents the formatting and CTE-name formatting behavior changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/sql_beautifier/cte_definition.rb
@kinnell kinnell merged commit 4b5dac9 into main Apr 8, 2026
6 checks passed
@kinnell kinnell deleted the cte-update branch April 8, 2026 21:08
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.

2 participants