Fix 4913 - use JSON output for golangci-lint instead of regexps. (#4917)
Some checks are pending
CI / build_image (push) Waiting to run
CI / test_ale (--linters-only) (push) Blocked by required conditions
CI / test_ale (--neovim-06-only) (push) Blocked by required conditions
CI / test_ale (--neovim-08-only) (push) Blocked by required conditions
CI / test_ale (--vim-80-only) (push) Blocked by required conditions
CI / test_ale (--vim-90-only) (push) Blocked by required conditions

* Fix 4913 - use JSON output for golangci-lint instead of regexps.

* Check for empty array
This commit is contained in:
Horacio Sanson
2025-03-07 22:02:49 +09:00
committed by GitHub
parent e319d48941
commit 7882fb9811
3 changed files with 113 additions and 63 deletions

View File

@@ -15,39 +15,41 @@ function! ale_linters#go#golangci_lint#GetCommand(buffer) abort
return ale#go#EnvString(a:buffer)
\ . '%e run '
\ . l:options
\ . ' --out-format=json'
\ . ' --show-stats=0'
endif
return ale#go#EnvString(a:buffer)
\ . '%e run '
\ . ale#Escape(l:filename)
\ . ' ' . l:options
endfunction
function! ale_linters#go#golangci_lint#GetMatches(lines) abort
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?:?:?:?\s\*?(.+)\s+\((.+)\)$'
return ale#util#GetMatches(a:lines, l:pattern)
\ . ' --out-format=json'
\ . ' --show-stats=0'
endfunction
function! ale_linters#go#golangci_lint#Handler(buffer, lines) abort
let l:dir = expand('#' . a:buffer . ':p:h')
let l:output = []
for l:match in ale_linters#go#golangci_lint#GetMatches(a:lines)
if l:match[5] is# 'typecheck'
let l:matches = ale#util#FuzzyJSONDecode(a:lines, [])
if empty(l:matches)
return []
endif
for l:match in l:matches['Issues']
if l:match['FromLinter'] is# 'typecheck'
let l:msg_type = 'E'
else
let l:msg_type = 'W'
endif
" l:match[1] will already be an absolute path, output from
" golangci_lint
call add(l:output, {
\ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]),
\ 'lnum': l:match[2] + 0,
\ 'col': l:match[3] + 0,
\ 'filename': ale#path#GetAbsPath(l:dir, l:match['Pos']['Filename']),
\ 'lnum': l:match['Pos']['Line'] + 0,
\ 'col': l:match['Pos']['Column'] + 0,
\ 'type': l:msg_type,
\ 'text': l:match[4] . ' (' . l:match[5] . ')',
\ 'text': match['FromLinter'] . ' - ' . l:match['Text'],
\})
endfor