add pgformatter

This commit is contained in:
Sajjad Hashemian 2019-05-27 09:00:11 +04:30
parent bb08b81bf7
commit 8d8b295ef5
7 changed files with 62 additions and 0 deletions

View file

@ -305,6 +305,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['tex'], \ 'suggested_filetypes': ['tex'],
\ 'description' : 'Indent code within environments, commands, after headings and within special code blocks.', \ '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. " 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* 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* sqlfmt *ale-sql-sqlfmt*

View file

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

View file

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

View file

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