Skip to content

Commit 653f62c

Browse files
feat: Ability to control newline placement around comma when seperating multiple columns/tables
Add option that can control if the newline is present after the comma or before the comma when listing multiple columns/tables
1 parent 3c96d06 commit 653f62c

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

test/options/commaNewline.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import dedent from 'dedent-js';
2+
3+
import { FormatFn } from '../../src/sqlFormatter.js';
4+
5+
export default function supportsCommaNewline(format: FormatFn) {
6+
it('by default adds newline after comma', () => {
7+
const result = format(`SELECT id, first_name, last_name, email FROM users;`);
8+
expect(result).toBe(
9+
dedent`
10+
SELECT
11+
id,
12+
first_name,
13+
last_name,
14+
email
15+
FROM
16+
users;
17+
`
18+
);
19+
});
20+
21+
it('supports newline before comma', () => {
22+
const result = format(`SELECT id, first_name, last_name, email FROM users;`, {
23+
commaNewline: 'before',
24+
});
25+
expect(result).toBe(
26+
dedent`
27+
SELECT
28+
id
29+
, first_name
30+
, last_name
31+
, email
32+
FROM
33+
users;
34+
`
35+
);
36+
});
37+
}

0 commit comments

Comments
 (0)