Skip to content

Commit a32f714

Browse files
authored
Merge pull request #2727 from bhcleek/lint/homogenize
lint: homogenize code quality tool calls
2 parents f17b742 + 7d21c2e commit a32f714

File tree

3 files changed

+110
-32
lines changed

3 files changed

+110
-32
lines changed

autoload/go/lint.vim

+107-28
Original file line numberDiff line numberDiff line change
@@ -146,56 +146,97 @@ endfunction
146146
" Golint calls 'golint' on the current directory. Any warnings are populated in
147147
" the location list
148148
function! go#lint#Golint(bang, ...) abort
149+
call go#cmd#autowrite()
150+
151+
let l:type = 'golint'
152+
let l:status = {
153+
\ 'desc': 'current status',
154+
\ 'type': l:type,
155+
\ 'state': "started",
156+
\ }
157+
if go#config#EchoCommandInfo()
158+
call go#util#EchoProgress(printf('[%s] analyzing...', l:type))
159+
endif
160+
call go#statusline#Update(expand('%:p:h'), l:status)
161+
149162
if a:0 == 0
150163
let [l:out, l:err] = go#util#Exec([go#config#GolintBin(), expand('%:p:h')])
151164
else
152165
let [l:out, l:err] = go#util#Exec([go#config#GolintBin()] + a:000)
153166
endif
154167

155-
if empty(l:out)
156-
call go#util#EchoSuccess('[lint] PASS')
157-
return
158-
endif
168+
let l:status.state = 'success'
169+
let l:state = 'PASS'
170+
if !empty(l:out)
171+
let l:status.state = 'failed'
172+
let l:state = 'FAIL'
159173

160-
let l:winid = win_getid(winnr())
161-
let l:listtype = go#list#Type("GoLint")
162-
call go#list#Parse(l:listtype, l:out, "GoLint")
163-
let l:errors = go#list#Get(l:listtype)
164-
call go#list#Window(l:listtype, len(l:errors))
174+
let l:winid = win_getid(winnr())
175+
let l:listtype = go#list#Type("GoLint")
176+
call go#list#Parse(l:listtype, l:out, "GoLint")
177+
let l:errors = go#list#Get(l:listtype)
178+
call go#list#Window(l:listtype, len(l:errors))
165179

166-
if a:bang
167-
call win_gotoid(l:winid)
180+
if a:bang
181+
call win_gotoid(l:winid)
182+
else
183+
call go#list#JumpToFirst(l:listtype)
184+
endif
185+
if go#config#EchoCommandInfo()
186+
call go#util#EchoError(printf('[%s] %s', l:type, l:state))
187+
endif
168188
else
169-
call go#list#JumpToFirst(l:listtype)
189+
if go#config#EchoCommandInfo()
190+
call go#util#EchoSuccess(printf('[%s] %s', l:type, l:state))
191+
endif
170192
endif
193+
call go#statusline#Update(expand('%:p:h'), l:status)
171194
endfunction
172195

173196
" Vet calls 'go vet' on the current directory. Any warnings are populated in
174197
" the location list
175198
function! go#lint#Vet(bang, ...) abort
176199
call go#cmd#autowrite()
177200

178-
if go#config#EchoCommandInfo()
179-
call go#util#EchoProgress('calling vet...')
180-
endif
181-
182201
let l:cmd = ['go', 'vet']
183202

184203
let buildtags = go#config#BuildTags()
185204
if buildtags isnot ''
186-
let cmd += ['-tags', buildtags]
205+
let l:cmd += ['-tags', buildtags]
206+
endif
207+
208+
if a:0 == 0
209+
let l:import_path = go#package#ImportPath()
210+
if l:import_path == -1
211+
call go#util#EchoError('could not determine package')
212+
return
213+
endif
214+
let l:cmd = add(l:cmd, l:import_path)
215+
else
216+
let l:cmd = extend(l:cmd, a:000)
187217
endif
188218

189-
if a:0 != 0
190-
call extend(cmd, a:000)
219+
let l:type = 'go vet'
220+
if go#config#EchoCommandInfo()
221+
call go#util#EchoProgress(printf('[%s] analyzing...', l:type))
191222
endif
223+
let l:status = {
224+
\ 'desc': 'current status',
225+
\ 'type': l:type,
226+
\ 'state': "started",
227+
\ }
228+
call go#statusline#Update(expand('%:p:h'), l:status)
192229

193-
let cmd += [go#package#ImportPath()]
230+
let [l:out, l:err] = go#util#ExecInDir(l:cmd)
194231

195-
let [l:out, l:err] = go#util#Exec(l:cmd)
232+
let l:status.state = 'success'
233+
let l:state = 'PASS'
196234

197235
let l:listtype = go#list#Type("GoVet")
198236
if l:err != 0
237+
let l:status.state = 'failed'
238+
let l:state = 'FAIL'
239+
199240
let l:winid = win_getid(winnr())
200241
let l:errorformat = "%-Gexit status %\\d%\\+," . &errorformat
201242
call go#list#ParseFormat(l:listtype, l:errorformat, out, "GoVet")
@@ -212,33 +253,65 @@ function! go#lint#Vet(bang, ...) abort
212253
else
213254
call win_gotoid(l:winid)
214255
endif
256+
257+
if go#config#EchoCommandInfo()
258+
call go#util#EchoError(printf('[%s] %s', l:type, l:state))
259+
endif
215260
else
216261
call go#list#Clean(l:listtype)
217-
call go#util#EchoSuccess('[vet] PASS')
262+
if go#config#EchoCommandInfo()
263+
call go#util#EchoSuccess(printf('[%s] %s', l:type, l:state))
264+
endif
218265
endif
266+
call go#statusline#Update(expand('%:p:h'), l:status)
219267
endfunction
220268

221269
" ErrCheck calls 'errcheck' for the given packages. Any warnings are populated in
222270
" the location list
223271
function! go#lint#Errcheck(bang, ...) abort
272+
call go#cmd#autowrite()
273+
274+
let l:cmd = [go#config#ErrcheckBin(), '-abspath']
275+
276+
let buildtags = go#config#BuildTags()
277+
if buildtags isnot ''
278+
let l:cmd += ['-tags', buildtags]
279+
endif
280+
224281
if a:0 == 0
225282
let l:import_path = go#package#ImportPath()
226283
if l:import_path == -1
227-
call go#util#EchoError('package is not inside GOPATH src')
284+
call go#util#EchoError('could not determine package')
228285
return
229286
endif
230-
let l:args = [l:import_path]
287+
let l:cmd = add(l:cmd, l:import_path)
231288
else
232-
let l:args = a:000
289+
let l:cmd = extend(l:cmd, a:000)
233290
endif
234291

235-
call go#util#EchoProgress('[errcheck] analysing ...')
292+
let l:type = 'errcheck'
293+
if go#config#EchoCommandInfo()
294+
call go#util#EchoProgress(printf('[%s] analyzing...', l:type))
295+
endif
296+
let l:status = {
297+
\ 'desc': 'current status',
298+
\ 'type': l:type,
299+
\ 'state': "started",
300+
\ }
236301
redraw
237302

238-
let [l:out, l:err] = go#util#ExecInDir([go#config#ErrcheckBin(), '-abspath'] + l:args)
303+
call go#statusline#Update(expand('%:p:h'), l:status)
304+
305+
let [l:out, l:err] = go#util#ExecInDir(l:cmd)
306+
307+
let l:status.state = 'success'
308+
let l:state = 'PASS'
239309

240310
let l:listtype = go#list#Type("GoErrCheck")
241311
if l:err != 0
312+
let l:status.state = 'failed'
313+
let l:state = 'FAIL'
314+
242315
let l:winid = win_getid(winnr())
243316

244317
if l:err == 1
@@ -262,10 +335,16 @@ function! go#lint#Errcheck(bang, ...) abort
262335
call win_gotoid(l:winid)
263336
endif
264337
endif
338+
if go#config#EchoCommandInfo()
339+
call go#util#EchoError(printf('[%s] %s', l:type, l:state))
340+
endif
265341
else
266342
call go#list#Clean(l:listtype)
267-
call go#util#EchoSuccess('[errcheck] PASS')
343+
if go#config#EchoCommandInfo()
344+
call go#util#EchoSuccess(printf('[%s] %s', l:type, l:state))
345+
endif
268346
endif
347+
call go#statusline#Update(expand('%:p:h'), l:status)
269348
endfunction
270349

271350
function! go#lint#ToggleMetaLinterAutoSave() abort

autoload/go/lint_test.vim

+2-4
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ func! Test_Vet() abort
158158
let l:tmp = gotest#load_fixture('lint/src/vet/vet.go')
159159

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

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

190189
try
191-
192190
let expected = [
193-
\ {'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)"}
191+
\ {'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)"}
194192
\ ]
195193

196194
let winnr = winnr()

scripts/test

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ find "$vimgodir" -name '*_test.vim' | while read test_file; do
6969
"$vimgodir/scripts/run-vim" $coverage $vim -e \
7070
+"silent e $test_file" \
7171
+"let g:test_verbose=$verbose" \
72+
+"let g:go_echo_command_info=0" \
7273
-S ./scripts/runtest.vim < /dev/null || (
7374
# If Vim exits with non-0 it's almost certainly a bug in the test runner;
7475
# should very rarely happen in normal usage.

0 commit comments

Comments
 (0)