feat: support sqlformat. (#2702)

* feat: support sqlformat.
This commit is contained in:
Cluas 2019-09-13 05:48:27 +08:00 committed by w0rp
parent 3e8c8d3ccb
commit a6c59faa0f
7 changed files with 66 additions and 0 deletions

View File

@ -260,6 +260,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['sql'], \ 'suggested_filetypes': ['sql'],
\ 'description': 'Fix SQL files with sqlfmt.', \ 'description': 'Fix SQL files with sqlfmt.',
\ }, \ },
\ 'sqlformat': {
\ 'function': 'ale#fixers#sqlformat#Fix',
\ 'suggested_filetypes': ['sql'],
\ 'description': 'Fix SQL files with sqlformat.',
\ },
\ 'google_java_format': { \ 'google_java_format': {
\ 'function': 'ale#fixers#google_java_format#Fix', \ 'function': 'ale#fixers#google_java_format#Fix',
\ 'suggested_filetypes': ['java'], \ 'suggested_filetypes': ['java'],

View File

@ -0,0 +1,16 @@
" Author: Cluas <Cluas@live.cn>
" Description: Fixing files with sqlformat.
call ale#Set('sql_sqlformat_executable', 'sqlformat')
call ale#Set('sql_sqlformat_options', '')
function! ale#fixers#sqlformat#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'sql_sqlformat_executable')
let l:options = ale#Var(a:buffer, 'sql_sqlformat_options')
return {
\ 'command': ale#Escape(l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -'
\}
endfunction

View File

@ -39,5 +39,23 @@ g:ale_sql_sqlfmt_options *g:ale_sql_sqlfmt_options*
At this time only the -u flag is available to format with upper-case. At this time only the -u flag is available to format with upper-case.
===============================================================================
sqlformat *ale-sql-sqlformat*
g:ale_sql_sqlformat_executable *g:ale_sql_sqlformat_executable*
*b:ale_sql_sqlformat_executable*
Type: |String|
Default: `'sqlformat'`
This variable sets executable used for sqlformat.
g:ale_sql_sqlformat_options *g:ale_sql_sqlformat_options*
*b:ale_sql_sqlformat_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to the sqlformat fixer.
=============================================================================== ===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -426,6 +426,7 @@ Notes:
* SQL * SQL
* `pgformatter` * `pgformatter`
* `sqlfmt` * `sqlfmt`
* `sqlformat`
* `sqlint` * `sqlint`
* Stylus * Stylus
* `stylelint` * `stylelint`

View File

@ -2377,6 +2377,7 @@ documented in additional help files.
sql.....................................|ale-sql-options| sql.....................................|ale-sql-options|
pgformatter...........................|ale-sql-pgformatter| pgformatter...........................|ale-sql-pgformatter|
sqlfmt................................|ale-sql-sqlfmt| sqlfmt................................|ale-sql-sqlfmt|
sqlformat.............................|ale-sql-sqlformat|
stylus..................................|ale-stylus-options| stylus..................................|ale-stylus-options|
stylelint.............................|ale-stylus-stylelint| stylelint.............................|ale-stylus-stylelint|
sugarss.................................|ale-sugarss-options| sugarss.................................|ale-sugarss-options|

View File

@ -435,6 +435,7 @@ formatting.
* SQL * SQL
* [pgformatter](https://github.com/darold/pgFormatter) * [pgformatter](https://github.com/darold/pgFormatter)
* [sqlfmt](https://github.com/jackc/sqlfmt) * [sqlfmt](https://github.com/jackc/sqlfmt)
* [sqlformat](https://github.com/andialbrecht/sqlparse)
* [sqlint](https://github.com/purcell/sqlint) * [sqlint](https://github.com/purcell/sqlint)
* Stylus * Stylus
* [stylelint](https://github.com/stylelint/stylelint) * [stylelint](https://github.com/stylelint/stylelint)

View File

@ -0,0 +1,24 @@
Before:
Save g:ale_sql_sqlformat_executable
Save g:ale_sql_sqlformat_options
After:
Restore
Execute(The sqlformat callback should return the correct default values):
AssertEqual
\ {
\ 'command': ale#Escape('sqlformat') . ' -'
\ },
\ ale#fixers#sqlformat#Fix(bufnr(''))
Execute(The sqlformat executable and options should be configurable):
let g:ale_sql_sqlformat_executable = '/path/to/sqlformat'
let g:ale_sql_sqlformat_options = '-a'
AssertEqual
\ {
\ 'command': ale#Escape('/path/to/sqlformat')
\ . ' -a -'
\ },
\ ale#fixers#sqlformat#Fix(bufnr(''))