From 4941bd8d0e5d64dea92892fe52c14d856518462c Mon Sep 17 00:00:00 2001 From: John Eikenberry Date: Sun, 25 Feb 2018 11:39:45 +0000 Subject: [PATCH] Fix #1358, fix #1369 - Lint the package on save for go vet instead --- ale_linters/go/govet.vim | 29 +++++++++++++++++-- .../test_govet_command_callback.vader | 16 ++++++++++ test/handler/test_govet_handler.vader | 28 ++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 test/command_callback/test_govet_command_callback.vader create mode 100644 test/handler/test_govet_handler.vader diff --git a/ale_linters/go/govet.vim b/ale_linters/go/govet.vim index f5bb47a3..aae5969d 100644 --- a/ale_linters/go/govet.vim +++ b/ale_linters/go/govet.vim @@ -1,10 +1,35 @@ " Author: neersighted " Description: go vet for Go files +" +" Author: John Eikenberry +" Description: updated to work with go1.10 + +function! ale_linters#go#govet#GetCommand(buffer) abort + return ale#path#BufferCdString(a:buffer) . ' go vet .' +endfunction + +function! ale_linters#go#govet#Handler(buffer, lines) abort + let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?:? ?(.+)$' + let l:output = [] + let l:dir = expand('#' . a:buffer . ':p:h') + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]), + \ 'lnum': l:match[2] + 0, + \ 'col': l:match[3] + 0, + \ 'text': l:match[4], + \ 'type': 'E', + \}) + endfor + return l:output +endfunction call ale#linter#Define('go', { \ 'name': 'go vet', \ 'output_stream': 'stderr', \ 'executable': 'go', -\ 'command': 'go vet %t', -\ 'callback': 'ale#handlers#unix#HandleAsError', +\ 'command_callback': 'ale_linters#go#govet#GetCommand', +\ 'callback': 'ale_linters#go#govet#Handler', +\ 'lint_file': 1, \}) diff --git a/test/command_callback/test_govet_command_callback.vader b/test/command_callback/test_govet_command_callback.vader new file mode 100644 index 00000000..a9b29605 --- /dev/null +++ b/test/command_callback/test_govet_command_callback.vader @@ -0,0 +1,16 @@ +Before: + runtime ale_linters/go/govet.vim + + call ale#test#SetDirectory('/testplugin/test/command_callback') + +After: + Restore + + call ale#linter#Reset() + call ale#test#RestoreDirectory() + +Execute(The default command should be correct): + AssertEqual + \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' + \ . ' go vet .', + \ ale_linters#go#govet#GetCommand(bufnr('')) diff --git a/test/handler/test_govet_handler.vader b/test/handler/test_govet_handler.vader new file mode 100644 index 00000000..b4bfdc93 --- /dev/null +++ b/test/handler/test_govet_handler.vader @@ -0,0 +1,28 @@ +Before: + runtime ale_linters/go/govet.vim + +After: + call ale#linter#Reset() + +Execute(The govet handler should return the correct filenames): + AssertEqual + \ [ + \ { + \ 'lnum': 27, + \ 'col': 0, + \ 'text': 'some error', + \ 'type': 'E', + \ 'filename': ale#path#Simplify(expand('%:p:h') . '/test.go'), + \ }, + \ { + \ 'lnum': 27, + \ 'col': 5, + \ 'text': 'some error with a column', + \ 'type': 'E', + \ 'filename': ale#path#Simplify(expand('%:p:h') . '/other.go'), + \ }, + \ ], + \ ale_linters#go#govet#Handler(bufnr(''), [ + \ 'test.go:27: some error', + \ 'other.go:27:5: some error with a column', + \ ])