Skip to content

Commit 67f4174

Browse files
authored
Merge PR #477: Make alwaysDenseOperators config to also work with :: and : operators
2 parents b33245b + d0d2071 commit 67f4174

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/formatter/ExpressionFormatter.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,10 @@ export default class ExpressionFormatter {
267267
}
268268

269269
private formatOperator({ text }: OperatorNode) {
270-
// special operator
271-
if (text === ':') {
272-
this.layout.add(WS.NO_SPACE, text, WS.SPACE);
273-
return;
274-
} else if (text === '::') {
275-
this.layout.add(WS.NO_SPACE, text);
276-
return;
277-
}
278-
279-
// other operators
280270
if (this.cfg.denseOperators || this.dialectCfg.alwaysDenseOperators?.includes(text)) {
281271
this.layout.add(WS.NO_SPACE, text);
272+
} else if (text === ':') {
273+
this.layout.add(WS.NO_SPACE, text, WS.SPACE);
282274
} else {
283275
this.layout.add(text, WS.SPACE);
284276
}

src/languages/postgresql/postgresql.formatter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expandPhrases } from 'src/expandPhrases';
2+
import { DialectFormatOptions } from 'src/formatter/ExpressionFormatter';
23
import Formatter from 'src/formatter/Formatter';
34
import Tokenizer from 'src/lexer/Tokenizer';
45
import { functions } from './postgresql.functions';
@@ -355,4 +356,8 @@ export default class PostgreSqlFormatter extends Formatter {
355356
],
356357
});
357358
}
359+
360+
formatOptions(): DialectFormatOptions {
361+
return { alwaysDenseOperators: ['::'] };
362+
}
358363
}

src/languages/redshift/redshift.formatter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expandPhrases } from 'src/expandPhrases';
2+
import { DialectFormatOptions } from 'src/formatter/ExpressionFormatter';
23
import Formatter from 'src/formatter/Formatter';
34
import Tokenizer from 'src/lexer/Tokenizer';
45
import { functions } from './redshift.functions';
@@ -170,4 +171,8 @@ export default class RedshiftFormatter extends Formatter {
170171
],
171172
});
172173
}
174+
175+
formatOptions(): DialectFormatOptions {
176+
return { alwaysDenseOperators: ['::'] };
177+
}
173178
}

src/languages/transactsql/transactsql.formatter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expandPhrases } from 'src/expandPhrases';
2+
import { DialectFormatOptions } from 'src/formatter/ExpressionFormatter';
23
import Formatter from 'src/formatter/Formatter';
34
import Tokenizer from 'src/lexer/Tokenizer';
45
import { functions } from './transactsql.functions';
@@ -249,4 +250,8 @@ export default class TransactSqlFormatter extends Formatter {
249250
// TODO: Support for money constants
250251
});
251252
}
253+
254+
formatOptions(): DialectFormatOptions {
255+
return { alwaysDenseOperators: ['::'] };
256+
}
252257
}

0 commit comments

Comments
 (0)