Skip to content

Commit 80352df

Browse files
authored
Merge PR #350: Fix BETWEEN..AND formatting in tabular style
2 parents 61672f3 + 6f61005 commit 80352df

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/formatter/ExpressionFormatter.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export default class ExpressionFormatter {
125125
WS.SPACE,
126126
this.show(node.expr1),
127127
WS.SPACE,
128-
this.show(node.andToken),
128+
this.showNonTabular(node.andToken),
129129
WS.SPACE,
130130
this.show(node.expr2),
131131
WS.SPACE
@@ -369,7 +369,12 @@ export default class ExpressionFormatter {
369369
}
370370
}
371371

372-
// don't call this directly, always use show() instead.
372+
// Like show(), but skips tabular formatting
373+
private showNonTabular(token: Token): string {
374+
return this.showToken(token);
375+
}
376+
377+
// don't call this directly, always use show() or showNonTabular() instead.
373378
private showToken(token: Token): string {
374379
if (isReserved(token)) {
375380
switch (this.cfg.keywordCase) {

test/options/indentStyle.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ export default function supportsIndentStyle(format: FormatFn) {
118118
;
119119
`);
120120
});
121+
122+
// Regression test for issue #341
123+
it('formats BETWEEN..AND', () => {
124+
expect(
125+
format('SELECT * FROM tbl WHERE id BETWEEN 1 AND 5000;', { indentStyle: 'tabularLeft' })
126+
).toBe(dedent`
127+
SELECT *
128+
FROM tbl
129+
WHERE id BETWEEN 1 AND 5000;
130+
`);
131+
});
121132
});
122133

123134
describe('indentStyle: tabularRight', () => {
@@ -165,5 +176,19 @@ export default function supportsIndentStyle(format: FormatFn) {
165176
].join('\n')
166177
);
167178
});
179+
180+
// Regression test for issue #341
181+
it('formats BETWEEN..AND', () => {
182+
expect(
183+
format('SELECT * FROM tbl WHERE id BETWEEN 1 AND 5000;', { indentStyle: 'tabularRight' })
184+
).toBe(
185+
[
186+
// ...comment to force multi-line array...
187+
' SELECT *',
188+
' FROM tbl',
189+
' WHERE id BETWEEN 1 AND 5000;',
190+
].join('\n')
191+
);
192+
});
168193
});
169194
}

0 commit comments

Comments
 (0)