Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Apr 15, 2025

I adjusted the indentation of AND and OR blocks based on the sequence of keywords:

  • When an AND follows an OR, it should be indented further than the OR.
  • If the same keyword appears consecutively, align them so that the keywords line up on the right.
  • If conditions are grouped in a subgroup, the OR is indented by one additional space compared to the AND.
AND status = 1
OR id =3
   AND name = /* name */'test'
AND status = 1
OR id =3
OR name = /* name */'test'

I also adjusted the indentation of comment blocks that indicate condition directives or loop directives to match the indentation of the block directly below them:

  • Comment blocks placed before or after AND/OR should have the same indentation as AND/OR.
  • The end block should be aligned with its corresponding comment block.
  • Loop blocks should be aligned at the same indentation level as other columns/lines (e.g., within INSERT or UPDATE).
AND status = 1
/*%if div== 2*/
OR id =3
   AND name = /* name */'test'
/*%end*/
INSERT INTO /*# tableName */
            (x1
             , x2
             /*%for entity : entities */
             , /*# entity.itemIdentifier */
             /*%end*/
             , x3
             , x4)

Finally, I refined where spaces are added:

  • Always insert a space before the closing parenthesis of a subgroup representing a subquery.
  • Insert spaces before and after conditional expressions.

@xterao xterao added the bug Something isn't working label Apr 15, 2025
@xterao xterao self-assigned this Apr 15, 2025
@github-actions github-actions bot added the fix Bug fixes label Apr 15, 2025
@xterao xterao linked an issue Apr 15, 2025 that may be closed by this pull request
@xterao xterao added this to the 0.6.0 Release milestone Apr 15, 2025
@xterao xterao merged commit b176773 into main Apr 15, 2025
5 checks passed
@xterao xterao deleted the fix/sql-formatter-second-option-indent branch April 15, 2025 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix indentation around AND and OR

2 participants