mirror of
https://github.com/dense-analysis/ale
synced 2024-12-25 15:42:26 +00:00
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
This commit is contained in:
parent
0b25d712b7
commit
590352304e
@ -37,7 +37,13 @@ endfunction
|
||||
|
||||
function! ale_linters#sql#sqlfluff#Handle(buffer, lines) abort
|
||||
let l:output = []
|
||||
let l:json = ale#util#FuzzyJSONDecode(a:lines, {})[0]
|
||||
let l:json_lines = ale#util#FuzzyJSONDecode(a:lines, [])
|
||||
|
||||
if empty(l:json_lines)
|
||||
return l:output
|
||||
endif
|
||||
|
||||
let l:json = l:json_lines[0]
|
||||
|
||||
" if there's no warning, 'result' is `null`.
|
||||
if empty(get(l:json, 'violations'))
|
||||
|
@ -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'],
|
||||
|
25
autoload/ale/fixers/sqlfluff.vim
Normal file
25
autoload/ale/fixers/sqlfluff.vim
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user