Skip to content

Commit

Permalink
lint: add g:go_metalinter_path setting
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih committed Sep 30, 2015
1 parent f2f4660 commit d7d0dc7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
35 changes: 21 additions & 14 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ if !exists("g:go_metalinter_enabled")
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
endif

if !exists("g:go_metalinter_path")
let g:go_metalinter_path = "./..."
endif

if !exists("g:go_golint_bin")
let g:go_golint_bin = "golint"
endif
Expand All @@ -14,36 +18,42 @@ if !exists("g:go_errcheck_bin")
let g:go_errcheck_bin = "errcheck"
endif

function! go#lint#Gometa(...) abort
" change GOPATH too, so the underlying tools in gometalinter can pick up
" the correct GOPATH
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()

function! go#lint#Gometa(path_to_lint) abort
let meta_command = "gometalinter --disable-all"
if empty(g:go_metalinter_command)
let bin_path = go#path#CheckBinPath("gometalinter")
if empty(bin_path)
return
endif

if empty(g:go_metalinter_enabled)
echohl Error | echomsg "vim-go: please enable linters with the setting g:go_metalinter_enabled" | echohl None
return
endif

for linter in g:go_metalinter_enabled
let meta_command .= " --enable=".linter
endfor

" TODO(arslan): maybe this should be passed via argument?
" for now we search for all underlying files
let meta_command .= " ./..."

" by default we search for all underlying files
let path = g:go_metalinter_path
if !empty(a:path_to_lint)
let path = a:path_to_lint
endif

let meta_command .= path

This comment has been minimized.

Copy link
@yulrizka

yulrizka Oct 2, 2015

@fatih should this be

let meta_command .= " " . path

else it would be --enable=errcheck./...

This comment has been minimized.

Copy link
@fatih

fatih Oct 2, 2015

Author Owner

Great catch, can you open an issue please? I'll fix it asap, Or just send a PR.

else
" the user wants something else, let us use it.
let meta_command = g:go_metalinter_command
endif

" debug
" comment out the following two lines for debugging
" echo meta_command
" return

let out = system(meta_command)
let out = go#tool#ExecuteInDir(meta_command)

if v:shell_error == 0
redraw | echo
call setqflist([])
Expand All @@ -63,9 +73,6 @@ function! go#lint#Gometa(...) abort

let &errorformat = old_errorformat
endif

" restore GOPATH again
let $GOPATH = old_gopath
endfunction

" Golint calls 'golint' on the current directory. Any warnings are populated in
Expand Down
20 changes: 15 additions & 5 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,15 @@ COMMANDS *go-commands*
scope.

*:GoMetaLinter*
:GoMetaLinter
:GoMetaLinter [path]

Calls the underlying `gometalinter` tool and displays all warnings and
errors in a quickfix window. By default the following linters are
enabled: "'vet', 'golint', 'errcheck'". This can be changed with the
|g:go_metalinter_enabled| variable. To override the command completely
use the variable |g:go_metalinter_command|
errors in a quickfix window. By default it lints the files for the path
`./...` . This can be changed with the 'path' argument temoporary or with the
|g:go_metalinter_path| variable permanently. By default the following
linters are enabled: "'vet', 'golint', 'errcheck'". This can be changed
with the |g:go_metalinter_enabled| variable. To override the command
completely use the variable |g:go_metalinter_command|


===============================================================================
Expand Down Expand Up @@ -846,6 +848,14 @@ over of how `gometalinter` should be executed. By default it's empty.
>
let g:go_metalinter_command = ""
<
*'g:go_metalinter_path'*

Defines the default path to be linted for the |GoMetaLinter| command. By
default it's set to `./...`, which recursively lints all files underd the
current directory.
>
let g:go_metalinter_path = "./..."
<

===============================================================================
TROUBLESHOOTING *go-troubleshooting*
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/go/commands.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ command! -nargs=1 -bang -complete=customlist,go#package#Complete GoImport call g
command! -nargs=* -bang -complete=customlist,go#package#Complete GoImportAs call go#import#SwitchImport(1, <f-args>, '<bang>')

" -- linters
command! -nargs=* GoMetaLinter call go#lint#Gometa()
command! -nargs=* GoMetaLinter call go#lint#Gometa('')
command! -nargs=* GoLint call go#lint#Golint(<f-args>)
command! -nargs=* -bang GoVet call go#lint#Vet(<bang>0, <f-args>)
command! -nargs=* -complete=customlist,go#package#Complete GoErrCheck call go#lint#Errcheck(<f-args>)
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/go/mappings.vim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ nnoremap <silent> <Plug>(go-doc-vertical) :<C-u>call go#doc#Open("vnew", "vsplit
nnoremap <silent> <Plug>(go-doc-split) :<C-u>call go#doc#Open("new", "split")<CR>
nnoremap <silent> <Plug>(go-doc-browser) :<C-u>call go#doc#OpenBrowser()<CR>
nnoremap <silent> <Plug>(go-metalinter) :<C-u>call go#lint#Gometa()<CR>
nnoremap <silent> <Plug>(go-metalinter) :<C-u>call go#lint#Gometa('')<CR>
nnoremap <silent> <Plug>(go-vet) :<C-u>call go#lint#Vet(!g:go_jump_to_error)<CR>

0 comments on commit d7d0dc7

Please sign in to comment.