Skip to content

Commit ebbc5b3

Browse files
authored
Add some VimScript lint tools (#1558)
* Add some VimScript lint tools https://github.com/syngan/vim-vimlint https://github.com/Kuniwak/vint * Remove trailing newlines * Add augroup to all autocmds * Fix undefined variables `l:tmpname` is never defined. * Explicitly define global variables with g: * Disable some vint errors * Change has() syntax to what vimlint wants * Disable warning for unused variables Too much effort to fix and vimlint can't deal with closures... * Install vint in Dockerfile * Add 2>&1
1 parent a81c1bd commit ebbc5b3

19 files changed

+103
-41
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
language: go
2+
notifications:
3+
email: false
24
matrix:
35
include:
46
- env: SCRIPT=test VIM_VERSION=vim-7.4
@@ -7,5 +9,6 @@ matrix:
79
- env: SCRIPT=lint VIM_VERSION=vim-8.0
810
install:
911
- ./scripts/install-vim $VIM_VERSION
12+
- pip install --user vim-vint
1013
script:
1114
- ./scripts/$SCRIPT $VIM_VERSION

.vintrc.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
policies:
2+
ProhibitUnnecessaryDoubleQuote:
3+
enabled: false
4+
ProhibitEqualTildeOperator:
5+
enabled: false
6+
ProhibitNoAbortFunction:
7+
enabled: false

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM golang:1.9.1
22

33
RUN apt-get update -y && \
4-
apt-get install -y build-essential curl git libncurses5-dev && \
4+
apt-get install -y build-essential curl git libncurses5-dev python3-pip && \
55
apt-get clean && \
66
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
77

@@ -14,5 +14,6 @@ WORKDIR /vim-go
1414
RUN scripts/install-vim vim-7.4
1515
RUN scripts/install-vim vim-8.0
1616
RUN scripts/install-vim nvim
17+
RUN pip3 install vim-vint
1718

1819
ENTRYPOINT ["make"]

autoload/ctrlp/decls.vim

-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ function! ctrlp#decls#enter() abort
9393
return
9494
endif
9595

96-
if exists("l:tmpname")
97-
call delete(l:tmpname)
98-
endif
99-
10096
let result = eval(out)
10197
if type(result) != 4 || !has_key(result, 'decls')
10298
return

autoload/fzf/decls.vim

-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ function! s:source(mode,...) abort
9090
return
9191
endif
9292

93-
if exists("l:tmpname")
94-
call delete(l:tmpname)
95-
endif
96-
9793
let result = eval(out)
9894
if type(result) != 4 || !has_key(result, 'decls')
9995
return ret_decls

autoload/go/cmd.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function! go#cmd#Build(bang, ...) abort
1414
" placeholder with the current folder (indicated with '.'). We also pass -i
1515
" that tries to install the dependencies, this has the side effect that it
1616
" caches the build results, so every other build is faster.
17-
let args =
17+
let args =
1818
\ ["build"] +
1919
\ map(copy(a:000), "expand(v:val)") +
2020
\ ["-i", ".", "errors"]

autoload/go/coverage.vim

+7-4
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ function! go#coverage#Clear() abort
9595
if exists("s:toggle") | let s:toggle = 0 | endif
9696

9797
" remove the autocmd we defined
98-
if exists("#BufWinLeave#<buffer>")
99-
autocmd! BufWinLeave <buffer>
100-
endif
98+
augroup vim-go-coverage
99+
autocmd!
100+
augroup end
101101
endfunction
102102

103103
" Browser creates a new cover profile with 'go test -coverprofile' and opens
@@ -258,7 +258,10 @@ function! go#coverage#overlay(file) abort
258258
endfor
259259

260260
" clear the matches if we leave the buffer
261-
autocmd BufWinLeave <buffer> call go#coverage#Clear()
261+
augroup vim-go-coverage
262+
autocmd!
263+
autocmd BufWinLeave <buffer> call go#coverage#Clear()
264+
augroup end
262265

263266
for m in matches
264267
call matchaddpos(m.group, m.pos)

autoload/go/fmt.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function! go#fmt#update_file(source, target)
131131

132132
" the title information was introduced with 7.4-2200
133133
" https://github.com/vim/vim/commit/d823fa910cca43fec3c31c030ee908a14c272640
134-
if has('patch-7.4-2200')
134+
if has('patch-7.4.2200')
135135
" clean up previous list
136136
if l:listtype == "quickfix"
137137
let l:list_title = getqflist({'title': 1})

autoload/go/guru.vim

+7-4
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,10 @@ function! s:same_ids_highlight(exit_val, output) abort
529529
if get(g:, "go_auto_sameids", 0)
530530
" re-apply SameIds at the current cursor position at the time the buffer
531531
" is redisplayed: e.g. :edit, :GoRename, etc.
532-
autocmd BufWinEnter <buffer> nested call go#guru#SameIds()
532+
augroup vim-go-sameids
533+
autocmd!
534+
autocmd BufWinEnter <buffer> nested call go#guru#SameIds()
535+
augroup end
533536
endif
534537
endfunction
535538

@@ -551,9 +554,9 @@ function! go#guru#ClearSameIds() abort
551554
endif
552555

553556
" remove the autocmds we defined
554-
if exists("#BufWinEnter#<buffer>")
555-
autocmd! BufWinEnter <buffer>
556-
endif
557+
augroup vim-go-sameids
558+
autocmd!
559+
augroup end
557560

558561
return 0
559562
endfunction

autoload/go/list.vim

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ if !exists("g:go_list_type_commands")
77
endif
88

99
" Window opens the list with the given height up to 10 lines maximum.
10-
" Otherwise g:go_loclist_height is used.
10+
" Otherwise g:go_loclist_height is used.
1111
"
12-
" If no or zero height is given it closes the window by default.
12+
" If no or zero height is given it closes the window by default.
1313
" To prevent this, set g:go_list_autoclose = 0
1414
function! go#list#Window(listtype, ...) abort
1515
" we don't use lwindow to close the location list as we need also the

autoload/go/tags.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func s:write_out(out) abort
100100
call go#list#Window(l:listtype, len(result['errors']))
101101

102102
"prevent jumping to quickfix list
103-
exe l:winnr . "wincmd w"
103+
exe l:winnr . "wincmd w"
104104
endif
105105
endfunc
106106

autoload/go/test.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ endfunction
226226

227227
" show_errors parses the given list of lines of a 'go test' output and returns
228228
" a quickfix compatible list of errors. It's intended to be used only for go
229-
" test output.
229+
" test output.
230230
function! s:show_errors(args, exit_val, messages) abort
231231
let l:listtype = go#list#Type("GoTest")
232232

autoload/gotest.vim

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ fun! gotest#assert_buffer(skipHeader, want) abort
6767
for l:lnum in range(0, len(l:buffer) - 1)
6868
" Bit rudimentary, but works reasonably well.
6969
if match(l:buffer[l:lnum], '^\v(func|var|const|import \(|\))') > -1
70-
let l:buffer = l:buffer[l:lnum:]
70+
" vint bug: https://github.com/Kuniwak/vint/issues/179
71+
" vint: -ProhibitUsingUndeclaredVariable
72+
let l:buffer = l:buffer[l:lnum:len(l:buffer)]
7173
break
7274
endif
7375
endfor

compiler/go.vim

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"
55
" compiler/go.vim: Vim compiler file for Go.
66

7-
if exists("current_compiler")
7+
if exists("g:current_compiler")
88
finish
99
endif
10-
let current_compiler = "go"
10+
let g:current_compiler = "go"
1111

1212
if exists(":CompilerSet") != 2
1313
command -nargs=* CompilerSet setlocal <args>

ftdetect/gofiletype.vim

+10-7
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ function! s:gofiletype_post()
1818
let &g:fileencodings = s:current_fileencodings
1919
endfunction
2020

21-
au BufNewFile *.go setfiletype go | setlocal fileencoding=utf-8 fileformat=unix
22-
au BufRead *.go call s:gofiletype_pre("go")
23-
au BufReadPost *.go call s:gofiletype_post()
21+
augroup vim-go-filetype
22+
autocmd!
23+
au BufNewFile *.go setfiletype go | setlocal fileencoding=utf-8 fileformat=unix
24+
au BufRead *.go call s:gofiletype_pre("go")
25+
au BufReadPost *.go call s:gofiletype_post()
2426

25-
au BufNewFile *.s setfiletype asm | setlocal fileencoding=utf-8 fileformat=unix
26-
au BufRead *.s call s:gofiletype_pre("asm")
27-
au BufReadPost *.s call s:gofiletype_post()
27+
au BufNewFile *.s setfiletype asm | setlocal fileencoding=utf-8 fileformat=unix
28+
au BufRead *.s call s:gofiletype_pre("asm")
29+
au BufReadPost *.s call s:gofiletype_post()
2830

29-
au BufRead,BufNewFile *.tmpl set filetype=gohtmltmpl
31+
au BufRead,BufNewFile *.tmpl set filetype=gohtmltmpl
32+
augroup end
3033

3134
" vim: sw=2 ts=2 et

scripts/install-vim

+9-3
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,19 @@ else
9090
fi
9191

9292
# Make sure all Go tools and other dependencies are installed.
93+
echo "Installing Go binaries"
9394
export GOPATH=$installdir
9495
export PATH=${GOPATH}/bin:$PATH
9596
"$vimgodir/scripts/run-vim" $vim +':silent :GoUpdateBinaries' +':qa'
9697

97-
[ -d "$installdir/share/vim/vimgo/pack/vim-go/start/vim-vimhelplint" ] || \
98-
git clone --depth 1 --quiet https://github.com/machakann/vim-vimhelplint \
99-
"$installdir/share/vim/vimgo/pack/vim-go/start/vim-vimhelplint"
98+
echo "Installing lint tools"
99+
(
100+
mkdir -p "$installdir/share/vim/vimgo/pack/vim-go/start/"
101+
cd "$installdir/share/vim/vimgo/pack/vim-go/start/"
102+
[ -d "vim-vimhelplint" ] || git clone --depth 1 --quiet https://github.com/machakann/vim-vimhelplint
103+
[ -d "vim-vimlparser" ] || git clone --depth 1 --quiet https://github.com/ynkdir/vim-vimlparser
104+
[ -d "vim-vimlint" ] || git clone --depth 1 --quiet https://github.com/syngan/vim-vimlint
105+
)
100106

101107
# Don't really need source after successful install.
102108
rm -rf "$srcdir"

scripts/lint

+43-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,45 @@ if [ ! -f "$vimdir/bin/vim" ]; then
2525
exit 1
2626
fi
2727

28+
### Run vint
29+
############
30+
failed=0
31+
printf "Running vint ... "
32+
if [ -x "$(command -v vint)" ]; then
33+
lint=$(vint "$vimgodir" 2>&1 ||:)
34+
if [ -n "$lint" ]; then
35+
echo "FAILED"
36+
echo "$lint"
37+
echo
38+
failed=6
39+
else
40+
echo "PASSED"
41+
fi
42+
else
43+
echo "SKIPPED"
44+
echo "'vint' binary not found; use 'pip install vim-vint' to install it."
45+
fi
46+
47+
### Run vim-vimlint
48+
###################
49+
printf "Running vim-vimlint ... "
50+
lint=$(sh "$vimdir/share/vim/vimgo/pack/vim-go/start/vim-vimlint/bin/vimlint.sh" \
51+
-p "$vimdir/share/vim/vimgo/pack/vim-go/start/vim-vimlparser" \
52+
-l "$vimdir/share/vim/vimgo/pack/vim-go/start/vim-vimlint" \
53+
-u \
54+
-c func_abort=1 \
55+
-e EVL110=1 -e EVL103=1 -e EVL104=1 -e EVL102=1 \
56+
"$vimgodir" \
57+
2>&1 ||:)
58+
if [ -n "$lint" ]; then
59+
echo "FAILED"
60+
echo "$lint"
61+
echo
62+
failed=6
63+
else
64+
echo "PASSED"
65+
fi
66+
2867
### Run vimhelplint.
2968
####################
3069
printf "Running vimhelplint ... "
@@ -37,12 +76,13 @@ lint=$($vimdir/bin/vim -esNR \
3776
+"e $vimgodir/doc/vim-go.txt" \
3877
+'verbose VimhelpLintEcho' \
3978
+q \
40-
2>&1)
79+
2>&1 ||:)
4180
if [ "$lint" ]; then
4281
echo "FAILED"
4382
echo "$lint"
44-
exit 6
83+
failed=6
4584
else
4685
echo "PASSED"
47-
exit 0
4886
fi
87+
88+
exit "$failed"

scripts/runtest.vim

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
" Make sure some options are set to sane defaults and output all messages in
22
" English.
3+
4+
" vint: -ProhibitSetNoCompatible
35
set nocompatible nomore shellslash encoding=utf-8 shortmess+=WIF
46
lang mess C
57

syntax/gohtmltmpl.vim

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ if exists("b:current_syntax")
22
finish
33
endif
44

5-
if !exists("main_syntax")
6-
let main_syntax = 'html'
5+
if !exists("g:main_syntax")
6+
let g:main_syntax = 'html'
77
endif
88

99
runtime! syntax/gotexttmpl.vim

0 commit comments

Comments
 (0)