Skip to content

Commit 2d2f5b3

Browse files
authored
Merge pull request #2334 from bhcleek/redo-2316
lint the correct package when :GoLint is called without arguments
2 parents 8033862 + a0b9285 commit 2d2f5b3

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

autoload/go/lint.vim

+3-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ function! go#lint#Gometa(bang, autosave, ...) abort
101101
endif
102102
endfunction
103103

104-
" Golint calls 'golint'.
104+
" Golint calls 'golint' on the current directory. Any warnings are populated in
105+
" the location list
105106
function! go#lint#Golint(bang, ...) abort
106107
if a:0 == 0
107-
let [l:out, l:err] = go#util#ExecInDir([go#config#GolintBin(), '.'])
108+
let [l:out, l:err] = go#util#Exec([go#config#GolintBin(), expand('%:p:h')])
108109
else
109110
let [l:out, l:err] = go#util#Exec([go#config#GolintBin()] + a:000)
110111
endif

autoload/go/lint_test.vim

+64-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func! Test_GometaGolangciLint() abort
1111
endfunc
1212

1313
func! s:gometa(metalinter) abort
14-
let $GOPATH = fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint'
14+
let RestoreGOPATH = go#util#SetEnv('GOPATH', fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint')
1515
silent exe 'e ' . $GOPATH . '/src/lint/lint.go'
1616

1717
try
@@ -36,6 +36,7 @@ func! s:gometa(metalinter) abort
3636

3737
call gotest#assert_quickfix(actual, expected)
3838
finally
39+
call call(RestoreGOPATH, [])
3940
unlet g:go_metalinter_enabled
4041
endtry
4142
endfunc
@@ -49,7 +50,7 @@ func! Test_GometaWithDisabledGolangciLint() abort
4950
endfunc
5051

5152
func! s:gometawithdisabled(metalinter) abort
52-
let $GOPATH = fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint'
53+
let RestoreGOPATH = go#util#SetEnv('GOPATH', fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint')
5354
silent exe 'e ' . $GOPATH . '/src/lint/lint.go'
5455

5556
try
@@ -74,6 +75,7 @@ func! s:gometawithdisabled(metalinter) abort
7475

7576
call gotest#assert_quickfix(actual, expected)
7677
finally
78+
call call(RestoreGOPATH, [])
7779
unlet g:go_metalinter_disabled
7880
endtry
7981
endfunc
@@ -87,7 +89,7 @@ func! Test_GometaAutoSaveGolangciLint() abort
8789
endfunc
8890

8991
func! s:gometaautosave(metalinter) abort
90-
let $GOPATH = fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint'
92+
let RestoreGOPATH = go#util#SetEnv('GOPATH', fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint')
9193
silent exe 'e ' . $GOPATH . '/src/lint/lint.go'
9294

9395
try
@@ -114,12 +116,13 @@ func! s:gometaautosave(metalinter) abort
114116

115117
call gotest#assert_quickfix(actual, expected)
116118
finally
119+
call call(RestoreGOPATH, [])
117120
unlet g:go_metalinter_autosave_enabled
118121
endtry
119122
endfunc
120123

121124
func! Test_Vet() abort
122-
let $GOPATH = fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint'
125+
let RestoreGOPATH = go#util#SetEnv('GOPATH', fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint')
123126
silent exe 'e ' . $GOPATH . '/src/vet/vet.go'
124127
compiler go
125128

@@ -142,6 +145,63 @@ func! Test_Vet() abort
142145
let actual = getqflist()
143146
endwhile
144147

148+
call gotest#assert_quickfix(actual, expected)
149+
call call(RestoreGOPATH, [])
150+
endfunc
151+
152+
func! Test_Lint_GOPATH() abort
153+
let RestoreGOPATH = go#util#SetEnv('GOPATH', fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint')
154+
155+
silent exe 'e ' . $GOPATH . '/src/lint/lint.go'
156+
compiler go
157+
158+
let expected = [
159+
\ {'lnum': 5, 'bufnr': bufnr('%'), 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exported function MissingDoc should have comment or be unexported'},
160+
\ {'lnum': 5, 'bufnr': 6, 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exported function AlsoMissingDoc should have comment or be unexported'}
161+
\ ]
162+
163+
let winnr = winnr()
164+
165+
" clear the location lists
166+
call setqflist([], 'r')
167+
168+
call go#lint#Golint(1)
169+
170+
let actual = getqflist()
171+
let start = reltime()
172+
while len(actual) == 0 && reltimefloat(reltime(start)) < 10
173+
sleep 100m
174+
let actual = getqflist()
175+
endwhile
176+
177+
call gotest#assert_quickfix(actual, expected)
178+
179+
call call(RestoreGOPATH, [])
180+
endfunc
181+
182+
func! Test_Lint_NullModule() abort
183+
silent exe 'e ' . fnameescape(fnamemodify(getcwd(), ':p')) . 'test-fixtures/lint/src/lint/lint.go'
184+
compiler go
185+
186+
let expected = [
187+
\ {'lnum': 5, 'bufnr': bufnr('%'), 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exported function MissingDoc should have comment or be unexported'},
188+
\ {'lnum': 5, 'bufnr': 6, 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exported function AlsoMissingDoc should have comment or be unexported'}
189+
\ ]
190+
191+
let winnr = winnr()
192+
193+
" clear the location lists
194+
call setqflist([], 'r')
195+
196+
call go#lint#Golint(1)
197+
198+
let actual = getqflist()
199+
let start = reltime()
200+
while len(actual) == 0 && reltimefloat(reltime(start)) < 10
201+
sleep 100m
202+
let actual = getqflist()
203+
endwhile
204+
145205
call gotest#assert_quickfix(actual, expected)
146206
endfunc
147207

0 commit comments

Comments
 (0)