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 */