Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Aug 22, 2025

This pull request refactors and enhances the SQL formatter block logic, focusing on improved handling of condition loop directives, block spacing rules, and better support for array/list SQL constructs. The changes increase code maintainability, readability, and extensibility, especially around comment and directive formatting and array/list parsing.

Condition Loop Directive Handling

  • Added new logic to detect if an element appears immediately after a condition loop end, and incorporated this into spacing decisions for more accurate formatting of SQL blocks with loop directives. [1] [2]
  • Introduced helper methods to fetch the last block with a condition loop directive and refactored related logic for clarity and reuse.

Spacing and Indentation Refactoring

  • Refactored the spacing builder for directive block comments, consolidating spacing rules and using helper constants for improved readability and maintainability. [1] [2] [3]
  • Fixed the issue so that the test data in the IN clause, which is enclosed within a conditional loop directive, does not break into a new line.
    Also, corrected the calculation of indentation for subqueries used in conditional expressions.

Array/List Block Support

  • Added new block types (SqlArrayListGroupBlock, SqlArrayWordBlock) and logic to correctly parse and format SQL array/list constructs, including handling of escape characters and block relationships. [1] [2] [3]

Block Construction and Child Block Parsing

  • Refactored block construction to pass the previous non-whitespace block, enabling context-sensitive block creation (e.g., for array/list detection and function name handling). [1] [2] [3]

Function Name and Keyword Handling

  • Improved logic to distinguish between function names followed by parentheses and keywords, ensuring correct block type assignment and formatting.

These changes collectively improve the formatter’s ability to handle complex SQL structures, especially those involving conditional logic and arrays/lists, while making the codebase easier to maintain and extend.

xterao and others added 26 commits August 20, 2025 19:16
Fix subquery formatting under conditional directives
…parison-operators

Fix SQL formatting rules for JSON columns
…t-formatting-function-in-condition-directive

Formatting of SQL Function Parameters with Keyword Elements
@xterao xterao added this to the 2.1.2 Release milestone Aug 22, 2025
@xterao xterao self-assigned this Aug 22, 2025
@github-actions github-actions bot added the fix Bug fixes label Aug 22, 2025
@xterao xterao linked an issue Aug 22, 2025 that may be closed by this pull request
@xterao xterao merged commit 1bfffff into main Aug 22, 2025
5 checks passed
@xterao xterao deleted the fix/sql-formatter branch August 22, 2025 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect SQL Format

2 participants