Skip to content

Commit 8dbbb3f

Browse files
authored
Merge PR #414: Fix tabular style formatting of LIMIT clause
2 parents c18fd8b + dae9da8 commit 8dbbb3f

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/formatter/ExpressionFormatter.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,17 @@ export default class ExpressionFormatter {
170170
this.layout.add(WS.NEWLINE, WS.INDENT, this.showKw(node.name));
171171
this.layout.indentation.increaseTopLevel();
172172

173-
if (node.offset) {
173+
if (isTabularStyle(this.cfg)) {
174+
this.layout.add(WS.SPACE);
175+
} else {
174176
this.layout.add(WS.NEWLINE, WS.INDENT);
177+
}
178+
179+
if (node.offset) {
175180
this.layout = this.formatSubExpression(node.offset);
176181
this.layout.add(WS.NO_SPACE, ',', WS.SPACE);
177182
this.layout = this.formatSubExpression(node.count);
178183
} else {
179-
this.layout.add(WS.NEWLINE, WS.INDENT);
180184
this.layout = this.formatSubExpression(node.count);
181185
}
182186
this.layout.indentation.decreaseTopLevel();

src/formatter/tabularStyle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function isTabularToken(type: TokenType): boolean {
3535
type === TokenType.RESERVED_COMMAND ||
3636
type === TokenType.RESERVED_SELECT ||
3737
type === TokenType.RESERVED_SET_OPERATION ||
38-
type === TokenType.RESERVED_JOIN
38+
type === TokenType.RESERVED_JOIN ||
39+
type === TokenType.LIMIT
3940
);
4041
}

test/features/limiting.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ export default function supportsLimiting(format: FormatFn, types: LimitingTypes)
4949
6;
5050
`);
5151
});
52+
53+
// Regression test for #412
54+
it('formats LIMIT in tabular style', () => {
55+
const result = format('SELECT * FROM tbl LIMIT 5, 6;', { indentStyle: 'tabularLeft' });
56+
expect(result).toBe(dedent`
57+
SELECT *
58+
FROM tbl
59+
LIMIT 5, 6;
60+
`);
61+
});
5262
}
5363

5464
if (types.limit && types.offset) {

0 commit comments

Comments
 (0)