Skip to content

Commit ddc8fd6

Browse files
committed
fix: format indent is not honored for all tokens
Ensure that the indent is applied correctly to all tokens Resolves: #272
1 parent 1315e84 commit ddc8fd6

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 6.3.1
4+
5+
Dec 15, 2025
6+
7+
- Fix indent for query format
8+
39
## 6.3.0
410

511
Nov 27, 2025

src/formatter/formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export class Formatter {
214214
*/
215215
formatClause(clause: string): string {
216216
if (this.enabled) {
217-
return this.options.newLineAfterKeywords ? `\n${clause}\n\t` : `\n${clause}`;
217+
return this.options.newLineAfterKeywords ? `\n${clause}\n${this.getIndent()}` : `\n${clause}`;
218218
}
219219
return ` ${clause}`;
220220
}

test/test-cases-for-format.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ ORDER BY GROUPING(Type),
233233
testCase: 10,
234234
soql: `SELECT Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Account.Name, (SELECT Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Contact.LastName FROM Account.Contacts WHERE Id = '123' OR Id = '456' OR pimped = TRUE), baz, (SELECT Id FROM account WHERE Boo.baz = 'bar'), bax, bar FROM Account WHERE Id IN (SELECT AccountId FROM Contact WHERE LastName LIKE 'apple%') AND Foo = 'bar' OR Baz = 'boom' AND Id IN (SELECT AccountId FROM Opportunity WHERE isClosed = TRUE) ORDER BY GROUPING(Type), GROUPING(Id, BillingCountry), Name DESC NULLS FIRST, Id ASC NULLS LAST`,
235235
formatOptions: { fieldMaxLineLength: 170, fieldSubqueryParensOnOwnLine: false },
236-
formattedSoql: `SELECT Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Account.Name,
236+
formattedSoql:
237+
`SELECT Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Account.Name,
237238
\t(SELECT Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Id, Name, Foo, Bar, Baz, Bax, aaa, bbb, ccc, ddd, Contact.LastName
238239
\tFROM Account.Contacts
239240
\tWHERE Id = '123'
@@ -309,8 +310,7 @@ WHERE Name LIKE 'a%'
309310
},
310311
{
311312
testCase: 12,
312-
soql:
313-
'SELECT AccountNumber, (SELECT AccountNumber FROM ChildAccounts WHERE CreatedDate = 2017-04-05T10:41:42.000+0000) FROM Account WHERE CreatedDate >= 2017-04-05T10:41:42.000+0000 AND CreatedDate <= 2017-05-05T10:41:42.000+0000',
313+
soql: 'SELECT AccountNumber, (SELECT AccountNumber FROM ChildAccounts WHERE CreatedDate = 2017-04-05T10:41:42.000+0000) FROM Account WHERE CreatedDate >= 2017-04-05T10:41:42.000+0000 AND CreatedDate <= 2017-05-05T10:41:42.000+0000',
314314
formatOptions: { newLineAfterKeywords: true, fieldMaxLineLength: 1 },
315315
formattedSoql: `SELECT
316316
\tAccountNumber,
@@ -427,6 +427,23 @@ FROM Event
427427
\tTYPEOF What WHEN Account THEN Phone, NumberOfEmployees WHEN Opportunity THEN Amount, CloseDate ELSE Name, Email END,
428428
\tName
429429
FROM Event
430+
`.trim(),
431+
},
432+
{
433+
testCase: 18,
434+
soql: `SELECT Id, Name, Account__pc, CurrencyIsoCode, Description FROM Account WHERE percent__c IN (1, 3, 4, 5) AND PersonOtherCity NOT IN ('zurich')`,
435+
formatOptions: { newLineAfterKeywords: true, fieldMaxLineLength: 1, numIndent: 2 },
436+
formattedSoql: `SELECT
437+
\t\tId,
438+
\t\tName,
439+
\t\tAccount__pc,
440+
\t\tCurrencyIsoCode,
441+
\t\tDescription
442+
FROM
443+
\t\tAccount
444+
WHERE
445+
\t\tpercent__c IN (1, 3, 4, 5)
446+
\t\tAND PersonOtherCity NOT IN ('zurich')
430447
`.trim(),
431448
},
432449
];

0 commit comments

Comments
 (0)