Compact CTE formatting and apply table name format to CTE definitions#15
Merged
Conversation
There was a problem hiding this comment.
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
withprefix and indent CTE bodies byindent_spacesfrom column zero (with the closing)at column zero). - Apply
table_name_formatto CTE definition names inWITH ... 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.
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.
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
withkeyword 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
withprefix is now compact (with), CTE body lines are indented byindent_spacesfrom column zero, and the closing paren sits at column zero. CTE definition names also now follow thetable_name_formatsetting (PascalCase by default), matching how CTE references were already formatted inFROMclauses.