summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/sqlfluff.vim25
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