mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 21:24:33 +08:00
Add support for sqlfluff 3.0.0 (#4743)
As stated in the changelog: "the original fields of line_pos and line_no have been renamed to start_line_pos and start_line_no, to distinguish them from the new fields starting end_*"
This commit is contained in:
@@ -11,7 +11,7 @@ function! ale_linters#sql#sqlfluff#Executable(buffer) abort
|
|||||||
return ale#Var(a:buffer, 'sql_sqlfluff_executable')
|
return ale#Var(a:buffer, 'sql_sqlfluff_executable')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#sql#sqlfluff#Command(buffer) abort
|
function! ale_linters#sql#sqlfluff#Command(buffer, version) abort
|
||||||
let l:executable = ale_linters#sql#sqlfluff#Executable(a:buffer)
|
let l:executable = ale_linters#sql#sqlfluff#Executable(a:buffer)
|
||||||
let l:options = ale#Var(a:buffer, 'sql_sqlfluff_options')
|
let l:options = ale#Var(a:buffer, 'sql_sqlfluff_options')
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ function! ale_linters#sql#sqlfluff#Command(buffer) abort
|
|||||||
return l:cmd
|
return l:cmd
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#sql#sqlfluff#Handle(buffer, lines) abort
|
function! ale_linters#sql#sqlfluff#Handle(buffer, version, lines) abort
|
||||||
let l:output = []
|
let l:output = []
|
||||||
let l:json_lines = ale#util#FuzzyJSONDecode(a:lines, [])
|
let l:json_lines = ale#util#FuzzyJSONDecode(a:lines, [])
|
||||||
|
|
||||||
@@ -50,16 +50,31 @@ function! ale_linters#sql#sqlfluff#Handle(buffer, lines) abort
|
|||||||
return l:output
|
return l:output
|
||||||
endif
|
endif
|
||||||
|
|
||||||
for l:violation in get(l:json, 'violations', [])
|
if ale#semver#GTE(a:version, [3, 0, 0])
|
||||||
call add(l:output, {
|
for l:violation in get(l:json, 'violations', [])
|
||||||
\ 'filename': l:json.filepath,
|
call add(l:output, {
|
||||||
\ 'lnum': l:violation.line_no,
|
\ 'filename': l:json.filepath,
|
||||||
\ 'col': l:violation.line_pos,
|
\ 'lnum': l:violation.start_line_no,
|
||||||
\ 'text': l:violation.description,
|
\ 'end_lnum': l:violation.end_line_no,
|
||||||
\ 'code': l:violation.code,
|
\ 'col': l:violation.start_line_pos,
|
||||||
\ 'type': 'W',
|
\ 'end_col': l:violation.end_line_pos,
|
||||||
\})
|
\ 'text': l:violation.description,
|
||||||
endfor
|
\ 'code': l:violation.code,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\})
|
||||||
|
endfor
|
||||||
|
else
|
||||||
|
for l:violation in get(l:json, 'violations', [])
|
||||||
|
call add(l:output, {
|
||||||
|
\ 'filename': l:json.filepath,
|
||||||
|
\ 'lnum': l:violation.line_no,
|
||||||
|
\ 'col': l:violation.line_pos,
|
||||||
|
\ 'text': l:violation.description,
|
||||||
|
\ 'code': l:violation.code,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\})
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
|
||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
@@ -67,6 +82,19 @@ endfunction
|
|||||||
call ale#linter#Define('sql', {
|
call ale#linter#Define('sql', {
|
||||||
\ 'name': 'sqlfluff',
|
\ 'name': 'sqlfluff',
|
||||||
\ 'executable': function('ale_linters#sql#sqlfluff#Executable'),
|
\ 'executable': function('ale_linters#sql#sqlfluff#Executable'),
|
||||||
\ 'command': function('ale_linters#sql#sqlfluff#Command'),
|
\ 'command': {buffer -> ale#semver#RunWithVersionCheck(
|
||||||
\ 'callback': 'ale_linters#sql#sqlfluff#Handle',
|
\ buffer,
|
||||||
|
\ ale_linters#sql#sqlfluff#Executable(buffer),
|
||||||
|
\ '%e --version',
|
||||||
|
\ function('ale_linters#sql#sqlfluff#Command'),
|
||||||
|
\ )},
|
||||||
|
\ 'callback': {buffer, lines -> ale#semver#RunWithVersionCheck(
|
||||||
|
\ buffer,
|
||||||
|
\ ale_linters#sql#sqlfluff#Executable(buffer),
|
||||||
|
\ '%e --version',
|
||||||
|
\ {buffer, version -> ale_linters#sql#sqlfluff#Handle(
|
||||||
|
\ buffer,
|
||||||
|
\ l:version,
|
||||||
|
\ lines)},
|
||||||
|
\ )},
|
||||||
\})
|
\})
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Before:
|
|||||||
After:
|
After:
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
|
||||||
Execute(The sqlfluff handler should handle basic warnings):
|
Execute(The sqlfluff handler should handle basic warnings with version older than 3.0.0):
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [
|
\ [
|
||||||
\ {
|
\ {
|
||||||
@@ -32,6 +32,44 @@ Execute(The sqlfluff handler should handle basic warnings):
|
|||||||
\ 'text': 'Files must end with a single trailing newline.',
|
\ 'text': 'Files must end with a single trailing newline.',
|
||||||
\ },
|
\ },
|
||||||
\ ],
|
\ ],
|
||||||
\ ale_linters#sql#sqlfluff#Handle(1, [
|
\ ale_linters#sql#sqlfluff#Handle(bufnr(''), [2, 3, 5], [
|
||||||
\ '[{"filepath": "schema.sql", "violations": [{"line_no": 1, "line_pos": 8, "code": "L010", "description": "Keywords must be consistently upper case."}, {"line_no": 13, "line_pos": 2, "code": "L003", "description": "Expected 1 indentation, found 0 [compared to line 12]"}, {"line_no": 16, "line_pos": 1, "code": "L009", "description": "Files must end with a single trailing newline."}]}]',
|
\ '[{"filepath": "schema.sql", "violations": [{"line_no": 1, "line_pos": 8, "code": "L010", "description": "Keywords must be consistently upper case."}, {"line_no": 13, "line_pos": 2, "code": "L003", "description": "Expected 1 indentation, found 0 [compared to line 12]"}, {"line_no": 16, "line_pos": 1, "code": "L009", "description": "Files must end with a single trailing newline."}]}]',
|
||||||
\ ])
|
\ ])
|
||||||
|
|
||||||
|
Execute(The sqlfluff handler should handle basic warnings with version newer than 3.0.0):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'filename': 'schema.sql',
|
||||||
|
\ 'lnum': 1,
|
||||||
|
\ 'end_lnum': 1,
|
||||||
|
\ 'col': 8,
|
||||||
|
\ 'end_col': 12,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'code': 'L010',
|
||||||
|
\ 'text': 'Keywords must be consistently upper case.',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'filename': 'schema.sql',
|
||||||
|
\ 'lnum': 13,
|
||||||
|
\ 'end_lnum': 13,
|
||||||
|
\ 'col': 2,
|
||||||
|
\ 'end_col': 20,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'code': 'L003',
|
||||||
|
\ 'text': 'Expected 1 indentation, found 0 [compared to line 12]',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'filename': 'schema.sql',
|
||||||
|
\ 'lnum': 16,
|
||||||
|
\ 'end_lnum': 16,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'end_col': 5,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'code': 'L009',
|
||||||
|
\ 'text': 'Files must end with a single trailing newline.',
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ ale_linters#sql#sqlfluff#Handle(bufnr(''), [3, 0, 0], [
|
||||||
|
\ '[{"filepath": "schema.sql", "violations": [{"start_line_no": 1, "end_line_no":1, "start_line_pos": 8, "end_line_pos":12, "code": "L010", "description": "Keywords must be consistently upper case."}, {"start_line_no": 13, "end_line_no":13, "start_line_pos": 2, "end_line_pos":20, "code": "L003", "description": "Expected 1 indentation, found 0 [compared to line 12]"}, {"start_line_no": 16, "end_line_no":16, "start_line_pos": 1, "end_line_pos":5, "code": "L009", "description": "Files must end with a single trailing newline."}]}]',
|
||||||
|
\ ])
|
||||||
|
|||||||
Reference in New Issue
Block a user