Properly handle optional end_line_no/end_line_pos in sqlfluff (#4867)

end_line_no/end_line_pos are optional. Example SQL:
`SELECT NULL FROM {{ a_jinja_templated_table }};`

`sqlfluff lint --dialect ansi --format json` gives the following error
among others:
```
{"start_line_no": 1, "start_line_pos": 21, "code": "TMP", "description":
"Undefined jinja template variable: 'a_jinja_templated_table'", "name":
"", "warning": false}
```

As one can see there is no end_line_no/end_line_pos.
This commit is contained in:
Coacher
2024-11-27 16:17:02 +03:00
committed by GitHub
parent 9d30fb2f59
commit 0ef2c455ee
2 changed files with 21 additions and 5 deletions

View File

@@ -52,16 +52,24 @@ function! ale_linters#sql#sqlfluff#Handle(buffer, version, lines) abort
if ale#semver#GTE(a:version, [3, 0, 0])
for l:violation in get(l:json, 'violations', [])
call add(l:output, {
let l:err = {
\ 'filename': l:json.filepath,
\ 'lnum': l:violation.start_line_no,
\ 'end_lnum': l:violation.end_line_no,
\ 'col': l:violation.start_line_pos,
\ 'end_col': l:violation.end_line_pos,
\ 'text': l:violation.description,
\ 'code': l:violation.code,
\ 'type': 'W',
\})
\}
if has_key(l:violation, 'end_line_no')
let l:err.end_lnum = l:violation.end_line_no
endif
if has_key(l:violation, 'end_line_pos')
let l:err.end_col = l:violation.end_line_pos
endif
call add(l:output, l:err)
endfor
else
for l:violation in get(l:json, 'violations', [])