summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/sqlformat.vim16
-rw-r--r--doc/ale-sql.txt18
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_sqlformat_fixer_callback.vader24
7 files changed, 66 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index d21cb227..ace37207 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -260,6 +260,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['sql'],
\ 'description': 'Fix SQL files with sqlfmt.',
\ },
+\ 'sqlformat': {
+\ 'function': 'ale#fixers#sqlformat#Fix',
+\ 'suggested_filetypes': ['sql'],
+\ 'description': 'Fix SQL files with sqlformat.',
+\ },
\ 'google_java_format': {
\ 'function': 'ale#fixers#google_java_format#Fix',
\ 'suggested_filetypes': ['java'],
diff --git a/autoload/ale/fixers/sqlformat.vim b/autoload/ale/fixers/sqlformat.vim
new file mode 100644
index 00000000..6319c1ac
--- /dev/null
+++ b/autoload/ale/fixers/sqlformat.vim
@@ -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
diff --git a/doc/ale-sql.txt b/doc/ale-sql.txt
index f9bc6ac2..2807271b 100644
--- a/doc/ale-sql.txt
+++ b/doc/ale-sql.txt
@@ -40,4 +40,22 @@ g:ale_sql_sqlfmt_options *g:ale_sql_sqlfmt_options*
===============================================================================
+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:
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 1b1202b9..98c6f354 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -426,6 +426,7 @@ Notes:
* SQL
* `pgformatter`
* `sqlfmt`
+ * `sqlformat`
* `sqlint`
* Stylus
* `stylelint`
diff --git a/doc/ale.txt b/doc/ale.txt
index aa8dbafe..5a123921 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2377,6 +2377,7 @@ documented in additional help files.
sql.....................................|ale-sql-options|
pgformatter...........................|ale-sql-pgformatter|
sqlfmt................................|ale-sql-sqlfmt|
+ sqlformat.............................|ale-sql-sqlformat|
stylus..................................|ale-stylus-options|
stylelint.............................|ale-stylus-stylelint|
sugarss.................................|ale-sugarss-options|
diff --git a/supported-tools.md b/supported-tools.md
index d94da030..96ebaf0f 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -435,6 +435,7 @@ formatting.
* SQL
* [pgformatter](https://github.com/darold/pgFormatter)
* [sqlfmt](https://github.com/jackc/sqlfmt)
+ * [sqlformat](https://github.com/andialbrecht/sqlparse)
* [sqlint](https://github.com/purcell/sqlint)
* Stylus
* [stylelint](https://github.com/stylelint/stylelint)
diff --git a/test/fixers/test_sqlformat_fixer_callback.vader b/test/fixers/test_sqlformat_fixer_callback.vader
new file mode 100644
index 00000000..4bace089
--- /dev/null
+++ b/test/fixers/test_sqlformat_fixer_callback.vader
@@ -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(''))