Skip to content

Incorrect Formatting of EXISTS Clause Inside Conditional Directives #403

@xterao

Description

@xterao

Describe the bug
When an EXISTS clause is used inside a conditional directive following a WHERE clause, the subquery is formatted incorrectly, causing unintended line breaks.

Example (current behavior):

WHERE
       /*%if filterByHighPerformers */
       EXISTS
       ( SELECT 1 
                  FROM performance_reviews pr 
                 WHERE pr.employee_id = e.id
                   /*%if reviewPeriod != null */
                   AND pr.review_date BETWEEN /* reviewPeriod.startDate */'2023-01-01' AND /* reviewPeriod.endDate */'2023-12-31'
                   /*%end*/
                   /*%if minScore != null */
                   AND pr.performance_score >= /* minScore */4.0
                   /*%end*/ )
       /*%else*/

The formatter forces a line break after the EXISTS keyword, separating it unnecessarily from the following parenthesis and subquery. This makes the SQL less readable and inconsistent compared to standard formatting expectations.

Expected behavior
The EXISTS keyword should remain on the same line as the opening parenthesis of the subquery, e.g.:

WHERE
       /*%if filterByHighPerformers */
       EXISTS ( SELECT 1
                  FROM performance_reviews pr
                 WHERE pr.employee_id = e.id
                   /*%if reviewPeriod != null */
                   AND pr.review_date BETWEEN /* reviewPeriod.startDate */'2023-01-01' AND /* reviewPeriod.endDate */'2023-12-31'
                   /*%end*/
                   /*%if minScore != null */
                   AND pr.performance_score >= /* minScore */4.0
                   /*%end*/ )
       /*%else*/

Desktop :

  • IDEA Version : 2024.3.6
  • Doma Tools Version : 2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions