Skip to content

Commit

Permalink
[FEA] Add newline and indentation for too long lines (#148)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
PabloRMira authored Mar 20, 2021
1 parent fe10bf1 commit cb7641b
Show file tree
Hide file tree
Showing 16 changed files with 1,232 additions and 130 deletions.
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,24 @@ Format your SQL files via the command line

You can also format all your SQL-files via

`sql-formatter *.sql` in Unix
`sql-formatter *.sql`

or via
To format all your SQL files recursively use

`sql-formatter "*.sql"` in Windows
`sql-formatter -r "*.sql"`

To format all your SQL files recursively use
### Controlling maximum length line via truncation

The `sql_formatter` will try to truncate too long lines in the `SELECT` clause for either

* Function with many arguments
* `in` with many elements

The default maximum line length is 82 after line stripping.

`sql-formatter --recursive "*.sql"` in Unix and Windows
You can control the maximum length line using e.g.

`sql-formatter sql_file.sql --max-line-length=50`

### Usage with `pre-commit`

Expand All @@ -48,9 +57,23 @@ repos:
language: system
entry: sql-formatter
files: \.sql$
```
or
```yaml
repos:
- repo: local
hooks:
- id: sql_formatter
name: SQL formatter
language: system
entry: sql-formatter --max-line-length=50
files: \.sql$
```
for a custom maximum line length truncation of e.g. 50
### Usage in Python
To exemplify the formatting let's say you have a SQL query like this
Expand Down
Loading

0 comments on commit cb7641b

Please sign in to comment.