Merge pull request #2540 from sijad/pgformatter

add pgformatter fixer
This commit is contained in:
w0rp 2019-05-29 21:26:01 +01:00 committed by GitHub
commit ca0cdd26fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 0 deletions

View File

@ -305,6 +305,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['tex'],
\ 'description' : 'Indent code within environments, commands, after headings and within special code blocks.',
\ },
\ 'pgformatter': {
\ 'function': 'ale#fixers#pgformatter#Fix',
\ 'suggested_filetypes': ['sql'],
\ 'description': 'A PostgreSQL SQL syntax beautifier',
\ },
\}
" Reset the function registry to the default entries.

View File

@ -0,0 +1,12 @@
call ale#Set('sql_pgformatter_executable', 'pg_format')
call ale#Set('sql_pgformatter_options', '')
function! ale#fixers#pgformatter#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'sql_pgformatter_executable')
let l:options = ale#Var(a:buffer, 'sql_pgformatter_options')
return {
\ 'command': ale#Escape(l:executable)
\ . (empty(l:options) ? '' : ' ' . l:options),
\}
endfunction

View File

@ -2,6 +2,24 @@
ALE SQL Integration *ale-sql-options*
===============================================================================
pgformatter *ale-sql-pgformatter*
g:ale_sql_pgformatter_executable *g:ale_sql_pgformatter_executable*
*b:ale_sql_pgformatter_executable*
Type: |String|
Default: `'pg_format'`
This variable sets executable used for pgformatter.
g:ale_sql_pgformatter_options *g:ale_sql_pgformatter_options*
*b:ale_sql_pgformatter_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to the pgformatter fixer.
===============================================================================
sqlfmt *ale-sql-sqlfmt*

View File

@ -415,6 +415,7 @@ Notes:
* `solhint`
* `solium`
* SQL
* `pgformatter`
* `sqlfmt`
* `sqlint`
* Stylus

View File

@ -2236,6 +2236,7 @@ documented in additional help files.
spec....................................|ale-spec-options|
rpmlint...............................|ale-spec-rpmlint|
sql.....................................|ale-sql-options|
pgformatter...........................|ale-sql-pgformatter|
sqlfmt................................|ale-sql-sqlfmt|
stylus..................................|ale-stylus-options|
stylelint.............................|ale-stylus-stylelint|

View File

@ -424,6 +424,7 @@ formatting.
* [solhint](https://github.com/protofire/solhint)
* [solium](https://github.com/duaraghav8/Solium)
* SQL
* [pgformatter](https://github.com/darold/pgFormatter)
* [sqlfmt](https://github.com/jackc/sqlfmt)
* [sqlint](https://github.com/purcell/sqlint)
* Stylus

View File

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