Skip to content

Commit cb7641b

Browse files
authored
[FEA] Add newline and indentation for too long lines (#148)
* [long-lines] add reformatting of too long lines in SELECT * [long-lines] add toml as dependency and update package version * [long-lines] improve reformatting of in lines * [long-lines] remove dependency on toml and add additional argument max-line-length to CLI
1 parent fe10bf1 commit cb7641b

16 files changed

Lines changed: 1232 additions & 130 deletions

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,24 @@ Format your SQL files via the command line
2323

2424
You can also format all your SQL-files via
2525

26-
`sql-formatter *.sql` in Unix
26+
`sql-formatter *.sql`
2727

28-
or via
28+
To format all your SQL files recursively use
2929

30-
`sql-formatter "*.sql"` in Windows
30+
`sql-formatter -r "*.sql"`
3131

32-
To format all your SQL files recursively use
32+
### Controlling maximum length line via truncation
33+
34+
The `sql_formatter` will try to truncate too long lines in the `SELECT` clause for either
35+
36+
* Function with many arguments
37+
* `in` with many elements
38+
39+
The default maximum line length is 82 after line stripping.
3340

34-
`sql-formatter --recursive "*.sql"` in Unix and Windows
41+
You can control the maximum length line using e.g.
42+
43+
`sql-formatter sql_file.sql --max-line-length=50`
3544

3645
### Usage with `pre-commit`
3746

@@ -48,9 +57,23 @@ repos:
4857
language: system
4958
entry: sql-formatter
5059
files: \.sql$
60+
```
5161
62+
or
63+
64+
```yaml
65+
repos:
66+
- repo: local
67+
hooks:
68+
- id: sql_formatter
69+
name: SQL formatter
70+
language: system
71+
entry: sql-formatter --max-line-length=50
72+
files: \.sql$
5273
```
5374
75+
for a custom maximum line length truncation of e.g. 50
76+
5477
### Usage in Python
5578
5679
To exemplify the formatting let's say you have a SQL query like this

0 commit comments

Comments
 (0)