Skip to content

【Formatter】Control Indentation for Nested Conditional and Loop Directives #155

@xterao

Description

@xterao

Control Indentation for Nested Conditional and Loop Directives

Improve the readability of SQL templates that use deeply nested control structures by controlling indentation based on the nesting level of conditional (/%if/) and loop (/%for/) directives.

Pattern ①: Indent Increases with Nesting Level

WHERE id = 1
   OR name = 'name'
      -- comment
      AND title = 'title'
      /*%for id : ids */       -- Parent directive (indent base)
      AND name = 'name'
        /*%if id_has_next */   -- Child directive
        OR sub = 'sub'
        /*%end */
      /*%end */

Pattern ②: Uniform Indentation Regardless of Nesting

WHERE id = 1
   OR name = 'name'
      -- comment
      AND title = 'title'
      /*%for id : ids */       -- Parent directive (indent base)
      AND name = 'name'
      /*%if id_has_next */     -- Child directive (no added indent)
      OR sub = 'sub'
      /*%end */ 
      /*%end */

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions