Skip to content

Commit 1579397

Browse files
committed
Merge branch 'double-parens-storm'
2 parents acd77b6 + 331ba3b commit 1579397

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/core/Formatter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ export default class Formatter {
111111

112112
// Opening parentheses increase the block indent level and start a new line
113113
formatOpeningParentheses(tokens, index, query) {
114-
// Take out the preceding space unless there was whitespace there in the original query
114+
// Take out the preceding space unless there was whitespace there in the original query or another opening parens
115115
const previousToken = tokens[index - 1];
116-
if (previousToken && previousToken.type !== sqlTokenTypes.WHITESPACE) {
116+
if (previousToken && previousToken.type !== sqlTokenTypes.WHITESPACE && previousToken.type !== sqlTokenTypes.OPEN_PAREN) {
117117
query = _.trimEnd(query);
118118
}
119119
query += tokens[index].value;

test/behavesLikeSqlFormatter.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,22 @@ export default function behavesLikeSqlFormatter(language) {
355355
);
356356
});
357357

358+
it("formats long double parenthized queries to multiple lines", function() {
359+
const result = format("((foo = '0123456789-0123456789-0123456789-0123456789'))");
360+
expect(result).toBe(
361+
"(\n" +
362+
" (\n" +
363+
" foo = '0123456789-0123456789-0123456789-0123456789'\n" +
364+
" )\n" +
365+
")\n"
366+
);
367+
});
368+
369+
it("formats short double parenthized queries to one line", function() {
370+
const result = format("((foo = 'bar'))");
371+
expect(result).toBe("((foo = 'bar'))\n");
372+
});
373+
358374
it("formats single-char operators", function() {
359375
expect(format("foo = bar")).toBe("foo = bar\n");
360376
expect(format("foo < bar")).toBe("foo < bar\n");

0 commit comments

Comments
 (0)