All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: Carl Smedstad <carl.smedstad at protonmail dot com>
2 " Description: sqlfluff for SQL files
4 let g:ale_sql_sqlfluff_executable =
5 \ get(g:, 'ale_sql_sqlfluff_executable', 'sqlfluff')
7 let g:ale_sql_sqlfluff_options =
8 \ get(g:, 'ale_sql_sqlfluff_options', '')
10 function! ale_linters#sql#sqlfluff#Executable(buffer) abort
11 return ale#Var(a:buffer, 'sql_sqlfluff_executable')
14 function! ale_linters#sql#sqlfluff#Command(buffer, version) abort
15 let l:executable = ale_linters#sql#sqlfluff#Executable(a:buffer)
16 let l:options = ale#Var(a:buffer, 'sql_sqlfluff_options')
19 \ ale#Escape(l:executable)
22 let l:config_file = ale#path#FindNearestFile(a:buffer, '.sqlfluff')
24 if !empty(l:config_file)
25 let l:cmd .= ' --config ' . ale#Escape(l:config_file)
27 let l:cmd .= ' --dialect ansi'
38 function! ale_linters#sql#sqlfluff#Handle(buffer, version, lines) abort
40 let l:json_lines = ale#util#FuzzyJSONDecode(a:lines, [])
42 if empty(l:json_lines)
46 let l:json = l:json_lines[0]
48 " if there's no warning, 'result' is `null`.
49 if empty(get(l:json, 'violations'))
53 if ale#semver#GTE(a:version, [3, 0, 0])
54 for l:violation in get(l:json, 'violations', [])
56 \ 'filename': l:json.filepath,
57 \ 'lnum': l:violation.start_line_no,
58 \ 'col': l:violation.start_line_pos,
59 \ 'text': l:violation.description,
60 \ 'code': l:violation.code,
64 if has_key(l:violation, 'end_line_no')
65 let l:err.end_lnum = l:violation.end_line_no
68 if has_key(l:violation, 'end_line_pos')
69 let l:err.end_col = l:violation.end_line_pos
72 call add(l:output, l:err)
75 for l:violation in get(l:json, 'violations', [])
77 \ 'filename': l:json.filepath,
78 \ 'lnum': l:violation.line_no,
79 \ 'col': l:violation.line_pos,
80 \ 'text': l:violation.description,
81 \ 'code': l:violation.code,
90 call ale#linter#Define('sql', {
92 \ 'executable': function('ale_linters#sql#sqlfluff#Executable'),
93 \ 'command': {buffer -> ale#semver#RunWithVersionCheck(
95 \ ale_linters#sql#sqlfluff#Executable(buffer),
97 \ function('ale_linters#sql#sqlfluff#Command'),
99 \ 'callback': {buffer, lines -> ale#semver#RunWithVersionCheck(
101 \ ale_linters#sql#sqlfluff#Executable(buffer),
103 \ {buffer, version -> ale_linters#sql#sqlfluff#Handle(