mirror of
https://github.com/dense-analysis/ale
synced 2025-04-11 03:51:38 +00:00
parent
0ef2c455ee
commit
65b49c1b81
@ -327,6 +327,11 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['go'],
|
\ 'suggested_filetypes': ['go'],
|
||||||
\ 'description': 'Fix Go files imports with goimports.',
|
\ 'description': 'Fix Go files imports with goimports.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'golangci_lint': {
|
||||||
|
\ 'function': 'ale#fixers#golangci_lint#Fix',
|
||||||
|
\ 'suggested_filetypes': ['go'],
|
||||||
|
\ 'description': 'Fix Go files with golangci-lint.',
|
||||||
|
\ },
|
||||||
\ 'golines': {
|
\ 'golines': {
|
||||||
\ 'function': 'ale#fixers#golines#Fix',
|
\ 'function': 'ale#fixers#golines#Fix',
|
||||||
\ 'suggested_filetypes': ['go'],
|
\ 'suggested_filetypes': ['go'],
|
||||||
|
32
autoload/ale/fixers/golangci_lint.vim
Normal file
32
autoload/ale/fixers/golangci_lint.vim
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
" 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)
|
||||||
|
|
||||||
|
function! ale#fixers#golangci_lint#GetCommand(buffer) 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:env = ale#go#EnvString(a:buffer)
|
||||||
|
|
||||||
|
|
||||||
|
if l:package_mode
|
||||||
|
return l:env . ale#Escape(l:executable)
|
||||||
|
\ . ' run '
|
||||||
|
\ . l:options
|
||||||
|
endif
|
||||||
|
|
||||||
|
return l:env . ale#Escape(l:executable)
|
||||||
|
\ . ' run '
|
||||||
|
\ . l:options
|
||||||
|
\ . ' ' . ale#Escape(l:filename)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale#fixers#golangci_lint#Fix(buffer) abort
|
||||||
|
return {
|
||||||
|
\ 'command': ale#fixers#golangci_lint#GetCommand(a:buffer),
|
||||||
|
\}
|
||||||
|
endfunction
|
48
test/fixers/test_golangci_lint_fixer_callback.vader
Normal file
48
test/fixers/test_golangci_lint_fixer_callback.vader
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_go_go111module
|
||||||
|
Save g:ale_go_golangci_lint_executable
|
||||||
|
Save g:ale_go_golangci_lint_options
|
||||||
|
Save g:ale_go_golangci_lint_package
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don't match it.
|
||||||
|
let g:ale_go_golangci_lint_executable = 'xxxinvalid'
|
||||||
|
let g:ale_go_golangci_lint_options = ''
|
||||||
|
|
||||||
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||||
|
call ale#test#SetFilename('../test-files/go/testfile.go')
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
unlet! b:ale_go_go111module
|
||||||
|
|
||||||
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
|
Execute(The golangci-lint callback should return the correct default values):
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid') . ' run --fix',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#golangci_lint#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The golangci-lint callback should include custom golangci-lint options):
|
||||||
|
let g:ale_go_golangci_lint_options = "--new --config /dev/null"
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid')
|
||||||
|
\ . ' run ' . g:ale_go_golangci_lint_options . ' --fix',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#golangci_lint#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The golangci-lint callback should support per-file mode):
|
||||||
|
let g:ale_go_golangci_lint_package = 0
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid')
|
||||||
|
\ . ' run '
|
||||||
|
\ . g:ale_go_golangci_lint_options
|
||||||
|
\ . ' --fix ' . ale#Escape('testfile.go'),
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#golangci_lint#Fix(bufnr(''))
|
Loading…
Reference in New Issue
Block a user