File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -111,9 +111,9 @@ export default class Formatter {
111
111
112
112
// Opening parentheses increase the block indent level and start a new line
113
113
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
115
115
const previousToken = tokens [ index - 1 ] ;
116
- if ( previousToken && previousToken . type !== sqlTokenTypes . WHITESPACE ) {
116
+ if ( previousToken && previousToken . type !== sqlTokenTypes . WHITESPACE && previousToken . type !== sqlTokenTypes . OPEN_PAREN ) {
117
117
query = _ . trimEnd ( query ) ;
118
118
}
119
119
query += tokens [ index ] . value ;
Original file line number Diff line number Diff line change @@ -355,6 +355,22 @@ export default function behavesLikeSqlFormatter(language) {
355
355
) ;
356
356
} ) ;
357
357
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
+
358
374
it ( "formats single-char operators" , function ( ) {
359
375
expect ( format ( "foo = bar" ) ) . toBe ( "foo = bar\n" ) ;
360
376
expect ( format ( "foo < bar" ) ) . toBe ( "foo < bar\n" ) ;
You can’t perform that action at this time.
0 commit comments