Add sqlformat support.

This commit is contained in:
Chiel ten Brinke 2018-08-07 11:39:02 +02:00
parent 3c50ddb506
commit b8173cde86
3 changed files with 14 additions and 2 deletions

View File

@ -238,6 +238,9 @@ Here is a list of formatprograms that are supported by default, and thus will be
* `shfmt` for __Shell__. * `shfmt` for __Shell__.
A shell formatter written in Go supporting POSIX Shell, Bash and mksh that can be installed with `go get -u mvdan.cc/sh/cmd/shfmt`. See https://github.com/mvdan/sh for more info. A shell formatter written in Go supporting POSIX Shell, Bash and mksh that can be installed with `go get -u mvdan.cc/sh/cmd/shfmt`. See https://github.com/mvdan/sh for more info.
* `sqlformat` for __SQL__.
Install `sqlparse` with `pip`.
## Help, the formatter doesn't work as expected! ## Help, the formatter doesn't work as expected!

View File

@ -44,7 +44,7 @@ if !exists('g:formatter_yapf_style')
endif endif
if !exists('g:formatdef_yapf') if !exists('g:formatdef_yapf')
let s:configfile_def = "'yapf -l '.a:firstline.'-'.a:lastline" let s:configfile_def = "'yapf -l '.a:firstline.'-'.a:lastline"
let s:noconfigfile_def = "'yapf --style=\"{based_on_style:'.g:formatter_yapf_style.',indent_width:'.&shiftwidth.(&textwidth ? ',column_limit:'.&textwidth : '').'}\" -l '.a:firstline.'-'.a:lastline" let s:noconfigfile_def = "'yapf --style=\"{based_on_style:'.g:formatter_yapf_style.',indent_width:'.shiftwidth().(&textwidth ? ',column_limit:'.&textwidth : '').'}\" -l '.a:firstline.'-'.a:lastline"
let g:formatdef_yapf = "g:YAPFFormatConfigFileExists() ? (" . s:configfile_def . ") : (" . s:noconfigfile_def . ")" let g:formatdef_yapf = "g:YAPFFormatConfigFileExists() ? (" . s:configfile_def . ") : (" . s:noconfigfile_def . ")"
endif endif
@ -452,7 +452,7 @@ endif
" Fortran " Fortran
if !exists('g:formatdef_fprettify') if !exists('g:formatdef_fprettify')
let g:formatdef_fprettify = '"fprettify --no-report-errors --indent=".&shiftwidth' let g:formatdef_fprettify = '"fprettify --no-report-errors --indent=".shiftwidth()'
endif endif
if !exists('g:formatters_fortran') if !exists('g:formatters_fortran')
@ -476,3 +476,11 @@ endif
if !exists('g:formatters_sh') if !exists('g:formatters_sh')
let g:formatters_sh = ['shfmt'] let g:formatters_sh = ['shfmt']
endif endif
" SQL
if !exists('g:formatdef_sqlformat')
let g:formatdef_sqlformat = '"sqlformat --reindent --indent_width ".shiftwidth()." --keywords upper --identifiers lower -"'
endif
if !exists('g:formatters_sql')
let g:formatters_sql = ['sqlformat']
endif

1
samples/test.sql Normal file
View File

@ -0,0 +1 @@
selECT * FROM foo WHERE id IN (SELECT id FROM bar);