diff options
author | Carl Smedstad <carl.smedstad@protonmail.com> | 2022-11-23 11:58:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-23 19:58:49 +0900 |
commit | 590352304e49874c9598fd49b0ae5ff7ddbc854c (patch) | |
tree | 21723d560ccfd7ce1f11298a5fe393da5eac9766 /autoload | |
parent | 0b25d712b7978c3b6a3bd968645183377d9f1761 (diff) | |
download | ale-590352304e49874c9598fd49b0ae5ff7ddbc854c.zip |
Fix bug in sqlfluff implementation & implement fixer support (#4365)
* Account for no sqlfluff output
Avoid crashes when there isn't any output from sqlfluff.
* Add supplort for sqlfluff as a fixer
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/sqlfluff.vim | 25 |
2 files changed, 30 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 2062f543..b44adb0e 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -386,6 +386,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['sh'], \ 'description': 'Fix sh files with shfmt.', \ }, +\ 'sqlfluff': { +\ 'function': 'ale#fixers#sqlfluff#Fix', +\ 'suggested_filetypes': ['sql'], +\ 'description': 'Fix SQL files with sqlfluff.', +\ }, \ 'sqlfmt': { \ 'function': 'ale#fixers#sqlfmt#Fix', \ 'suggested_filetypes': ['sql'], diff --git a/autoload/ale/fixers/sqlfluff.vim b/autoload/ale/fixers/sqlfluff.vim new file mode 100644 index 00000000..1dc9f5c1 --- /dev/null +++ b/autoload/ale/fixers/sqlfluff.vim @@ -0,0 +1,25 @@ +" Author: Carl Smedstad <carl.smedstad at protonmail dot com> +" Description: Fixing SQL files with sqlfluff + +call ale#Set('sql_sqlfluff_executable', 'sqlfluff') + +function! ale#fixers#sqlfluff#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'sql_sqlfluff_executable') + + let l:cmd = + \ ale#Escape(l:executable) + \ . ' fix --force' + + let l:config_file = ale#path#FindNearestFile(a:buffer, '.sqlfluff') + + if !empty(l:config_file) + let l:cmd .= ' --config ' . ale#Escape(l:config_file) + else + let l:cmd .= ' --dialect ansi' + endif + + return { + \ 'command': l:cmd . ' %t > /dev/null', + \ 'read_temporary_file': 1, + \} +endfunction |