diff options
author | Finn Steffens <34682885+0xhtml@users.noreply.github.com> | 2023-12-10 12:45:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-10 11:45:01 +0000 |
commit | 9a23ec1f60ec85f6afb70870a1978141b321fb3c (patch) | |
tree | 5da9624f31fbe6d2fd1fec039046c73f74fbcb60 /ale_linters/python | |
parent | ecc796b3d798f86a619469559977a76b439f7333 (diff) | |
download | ale-9a23ec1f60ec85f6afb70870a1978141b321fb3c.zip |
Ruff use json-lines output format (#4656)
* Ruff use json-lines output format
* Fix Ruff: add -q to prevent non json output
Using the json-lines output format allows for setting of the end_line,
end_col and code field of the handle output.
Additionally, the first letter of the code is used to determine the type
field.
Co-authored-by: w0rp <w0rp@users.noreply.github.com>
Diffstat (limited to 'ale_linters/python')
-rw-r--r-- | ale_linters/python/ruff.vim | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/ale_linters/python/ruff.vim b/ale_linters/python/ruff.vim index 617ef5b7..c4f8ad1b 100644 --- a/ale_linters/python/ruff.vim +++ b/ale_linters/python/ruff.vim @@ -47,22 +47,25 @@ function! ale_linters#python#ruff#GetCommand(buffer, version) abort " NOTE: ruff version `0.0.69` supports liniting input from stdin " NOTE: ruff version `0.1.0` deprecates `--format text` - return ale#Escape(l:executable) . l:exec_args + return ale#Escape(l:executable) . l:exec_args . ' -q' \ . ale#Pad(ale#Var(a:buffer, 'python_ruff_options')) - \ . (ale#semver#GTE(a:version, [0, 1, 0]) ? ' --output-format text' : ' --format text') + \ . (ale#semver#GTE(a:version, [0, 1, 0]) ? ' --output-format json-lines' : ' --format json-lines') \ . (ale#semver#GTE(a:version, [0, 0, 69]) ? ' --stdin-filename %s -' : ' %s') endfunction function! ale_linters#python#ruff#Handle(buffer, lines) abort - "Example: path/to/file.py:10:5: E999 SyntaxError: unexpected indent - let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+)?:? (.+)$' let l:output = [] - for l:match in ale#util#GetMatches(a:lines, l:pattern) + for l:line in a:lines + let l:item = json_decode(l:line) call add(l:output, { - \ 'lnum': l:match[1] + 0, - \ 'col': l:match[2] + 0, - \ 'text': l:match[3], + \ 'lnum': l:item.location.row, + \ 'col': l:item.location.column, + \ 'end_lnum': l:item.end_location.row, + \ 'end_col': l:item.end_location.column - 1, + \ 'code': l:item.code, + \ 'text': l:item.message, + \ 'type': l:item.code =~? '\vE\d+' ? 'E' : 'W', \}) endfor |