Skip to content

Commit

Permalink
lint: homogenize vet and errcheck handling
Browse files Browse the repository at this point in the history
* Use go#util#ExecInDir() when running go vet.
* Make the progress message when starting go vet consistent with
  errcheck's similiar progress message.
* Call go#cmd#autowrite() when starting go#lint#Errcheck to either write
  the buffers that have modifications when 'autowrite' or 'autowriteall'
  are set or display a message if neither of those options are set,
  because errcheck only analyzes files on disk.
* chagne the error message that's displayed when the package name cannot
  be determined to avoid implying that the package must be in GOPATH
  when the user is operating in module aware mode.
* Do not echo the start of errcheck progress if g:go_echo_command_info
  is cleared.
* disable g:go_echo_command_info when running tests to avoid screen
  clutter when tests fail.
  • Loading branch information
bhcleek committed Feb 15, 2020
1 parent 13c943a commit 936c7c3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
44 changes: 30 additions & 14 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,29 @@ endfunction
function! go#lint#Vet(bang, ...) abort
call go#cmd#autowrite()

if go#config#EchoCommandInfo()
call go#util#EchoProgress('calling vet...')
endif

let l:cmd = ['go', 'vet']

let buildtags = go#config#BuildTags()
if buildtags isnot ''
let cmd += ['-tags', buildtags]
let l:cmd += ['-tags', buildtags]
endif

if a:0 != 0
call extend(cmd, a:000)
if a:0 == 0
let l:import_path = go#package#ImportPath()
if l:import_path == -1
call go#util#EchoError('could not determine package')
return
endif
let l:cmd = add(l:cmd, l:import_path)
else
let l:cmd = extend(l:cmd, a:000)
endif

let cmd += [go#package#ImportPath()]
if go#config#EchoCommandInfo()
call go#util#EchoProgress('[go vet] analyzing...')
endif

let [l:out, l:err] = go#util#Exec(l:cmd)
let [l:out, l:err] = go#util#ExecInDir(l:cmd)

let l:listtype = go#list#Type("GoVet")
if l:err != 0
Expand Down Expand Up @@ -221,21 +226,32 @@ endfunction
" ErrCheck calls 'errcheck' for the given packages. Any warnings are populated in
" the location list
function! go#lint#Errcheck(bang, ...) abort
call go#cmd#autowrite()

let l:cmd = [go#config#ErrcheckBin(), '-abspath']

let buildtags = go#config#BuildTags()
if buildtags isnot ''
let l:cmd += ['-tags', buildtags]
endif

if a:0 == 0
let l:import_path = go#package#ImportPath()
if l:import_path == -1
call go#util#EchoError('package is not inside GOPATH src')
call go#util#EchoError('could not determine package')
return
endif
let l:args = [l:import_path]
let l:cmd = add(l:cmd, l:import_path)
else
let l:args = a:000
let l:cmd = extend(l:cmd, a:000)
endif

call go#util#EchoProgress('[errcheck] analysing ...')
if go#config#EchoCommandInfo()
call go#util#EchoProgress('[errcheck] analysing...')
endif
redraw

let [l:out, l:err] = go#util#ExecInDir([go#config#ErrcheckBin(), '-abspath'] + l:args)
let [l:out, l:err] = go#util#ExecInDir(l:cmd)

let l:listtype = go#list#Type("GoErrCheck")
if l:err != 0
Expand Down
6 changes: 2 additions & 4 deletions autoload/go/lint_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ func! Test_Vet() abort
let l:tmp = gotest#load_fixture('lint/src/vet/vet.go')

try

let expected = [
\ {'lnum': 7, 'bufnr': bufnr('%'), 'col': 2, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '',
\ {'lnum': 7, 'bufnr': bufnr('%')+2, 'col': 2, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '',
\ 'text': 'Printf format %d has arg str of wrong type string'}
\ ]

Expand Down Expand Up @@ -188,9 +187,8 @@ func! Test_Vet_compilererror() abort
let l:tmp = gotest#load_fixture('lint/src/vet/compilererror/compilererror.go')

try

let expected = [
\ {'lnum': 6, 'bufnr': bufnr('%'), 'col': 22, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': "missing ',' before newline in argument list (and 1 more errors)"}
\ {'lnum': 6, 'bufnr': bufnr('%')+2, 'col': 22, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': "missing ',' before newline in argument list (and 1 more errors)"}
\ ]

let winnr = winnr()
Expand Down
1 change: 1 addition & 0 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ find "$vimgodir" -name '*_test.vim' | while read test_file; do
"$vimgodir/scripts/run-vim" $coverage $vim -e \
+"silent e $test_file" \
+"let g:test_verbose=$verbose" \
+"let g:go_echo_command_info=0" \
-S ./scripts/runtest.vim < /dev/null || (
# If Vim exits with non-0 it's almost certainly a bug in the test runner;
# should very rarely happen in normal usage.
Expand Down

0 comments on commit 936c7c3

Please sign in to comment.