Fix golangci-lint fixer with version 2 (#4960)
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--lua-only) (push) Has been cancelled
CI / test_ale (--neovim-07-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled

This commit is contained in:
Horacio Sanson
2025-05-17 20:28:17 +09:00
committed by GitHub
parent 7cdaaa645d
commit 5098dfd27e
3 changed files with 115 additions and 43 deletions

View File

@@ -1,32 +1,48 @@
" Author: Ian Stapleton Cordasco <graffatcolmingov@gmail.com>
" Description: Run golangci-lint with the --fix flag to autofix some issues
call ale#Set('go_golangci_lint_options', '')
call ale#Set('go_golangci_lint_executable', 'golangci-lint')
call ale#Set('go_golangci_lint_package', 1)
call ale#Set('go_golangci_formatter_options', '')
call ale#Set('go_golangci_formatter_executable', 'golangci-lint')
function! ale#fixers#golangci_lint#GetCommand(buffer) abort
function! ale#fixers#golangci_lint#GetExecutable(buffer) abort
let l:executable = ale#Var(a:buffer, 'go_golangci_formatter_executable')
return l:executable
endfunction
function! ale#fixers#golangci_lint#GetCommand(buffer, version) abort
let l:filename = expand('#' . a:buffer . ':t')
let l:executable = ale#Var(a:buffer, 'go_golangci_lint_executable')
let l:options = ale#Var(a:buffer, 'go_golangci_lint_options') . ' --fix'
let l:package_mode = ale#Var(a:buffer, 'go_golangci_lint_package')
let l:executable = ale#fixers#golangci_lint#GetExecutable(a:buffer)
let l:options = ale#Var(a:buffer, 'go_golangci_formatter_options')
let l:env = ale#go#EnvString(a:buffer)
if l:package_mode
if ale#semver#GTE(a:version, [2, 0, 0])
return l:env . ale#Escape(l:executable)
\ . ' run '
\ . l:options
\ . ' fmt --stdin '
\ . l:options
else
return l:env . ale#Escape(l:executable)
\ . ' run --fix '
\ . l:options
\ . ' '
\ . ale#Escape(l:filename)
endif
endfunction
return l:env . ale#Escape(l:executable)
\ . ' run '
\ . l:options
\ . ' ' . ale#Escape(l:filename)
function! ale#fixers#golangci_lint#GetCommandForVersion(buffer, version) abort
return {
\ 'command': ale#fixers#golangci_lint#GetCommand(a:buffer, a:version)
\}
endfunction
function! ale#fixers#golangci_lint#Fix(buffer) abort
return {
\ 'command': ale#fixers#golangci_lint#GetCommand(a:buffer),
\}
let l:executable = ale#fixers#golangci_lint#GetExecutable(a:buffer)
let l:command = ale#fixers#golangci_lint#GetExecutable(a:buffer) . ale#Pad('--version')
return ale#semver#RunWithVersionCheck(
\ a:buffer,
\ l:executable,
\ l:command,
\ function('ale#fixers#golangci_lint#GetCommandForVersion'),
\)
endfunction