Skip to content

Commit fab8b80

Browse files
committedDec 13, 2023
Indent Conditional SOQL Expressions in Parentheses
1 parent 400065c commit fab8b80

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed
 

‎formatter/format_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,43 @@ func TestSOQL(t *testing.T) {
313313
Start__c = YESTERDAY
314314
)
315315
]`},
316+
317+
{
318+
`[
319+
SELECT
320+
Name
321+
FROM
322+
My_Object__c
323+
WHERE
324+
Type__c = 'Virtual' AND
325+
(
326+
Start__c = TODAY OR
327+
Start__c = N_DAYS_AGO:7 OR
328+
Start__c = N_DAYS_AGO:14 OR
329+
Start__c = N_DAYS_AGO:21 OR
330+
Start__c <= N_DAYS_AGO:28
331+
) AND
332+
Status__c = 'Confirmed'
333+
ORDER BY
334+
Start__c
335+
];`, `[
336+
SELECT
337+
Name
338+
FROM
339+
My_Object__c
340+
WHERE
341+
Type__c = 'Virtual' AND
342+
(
343+
Start__c = TODAY OR
344+
Start__c = N_DAYS_AGO:7 OR
345+
Start__c = N_DAYS_AGO:14 OR
346+
Start__c = N_DAYS_AGO:21 OR
347+
Start__c <= N_DAYS_AGO:28
348+
) AND
349+
Status__c = 'Confirmed'
350+
ORDER BY
351+
Start__c
352+
]`},
316353
}
317354
for _, tt := range tests {
318355
input := antlr.NewInputStream(tt.input)

‎formatter/visitors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ func (v *FormatVisitor) VisitLogicalExpression(ctx *parser.LogicalExpressionCont
947947
func (v *FormatVisitor) VisitConditionalExpression(ctx *parser.ConditionalExpressionContext) interface{} {
948948
switch {
949949
case ctx.LogicalExpression() != nil:
950-
return fmt.Sprintf("(%s)", v.visitRule(ctx.LogicalExpression()))
950+
return fmt.Sprintf("(\n%s\n)", v.indent(v.visitRule(ctx.LogicalExpression()).(string)))
951951
case ctx.FieldExpression() != nil:
952952
return v.visitRule(ctx.FieldExpression())
953953
}

0 commit comments

Comments
 (0)