Skip to content

Commit e7c5e81

Browse files
committed
Vint-related fixes
1 parent 633b02c commit e7c5e81

File tree

9 files changed

+66
-30
lines changed

9 files changed

+66
-30
lines changed

.vintrc.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmdargs:
2+
# Checking more strictly
3+
severity: style_problem
4+
5+
policies:
6+
# Disable a violation
7+
ProhibitUnnecessaryDoubleQuote:
8+
enabled: false
9+
ProhibitImplicitScopeVariable:
10+
enabled: false

autoload/rust.vim

+9-9
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function! s:Run(dict, rustc_args, args)
8484

8585
let pwd = a:dict.istemp ? a:dict.tmpdir : ''
8686
let output = s:system(pwd, shellescape(rustc) . " " . join(map(rustc_args, 'shellescape(v:val)')))
87-
if output != ''
87+
if output !=# ''
8888
echohl WarningMsg
8989
echo output
9090
echohl None
@@ -151,7 +151,7 @@ function! s:Expand(dict, pretty, args)
151151
endfunction
152152

153153
function! rust#CompleteExpand(lead, line, pos)
154-
if a:line[: a:pos-1] =~ '^RustExpand!\s*\S*$'
154+
if a:line[: a:pos-1] =~# '^RustExpand!\s*\S*$'
155155
" first argument and it has a !
156156
let list = ["normal", "expanded", "typed", "expanded,identified", "flowgraph=", "everybody_loops"]
157157
if !empty(a:lead)
@@ -180,7 +180,7 @@ function! s:Emit(dict, type, args)
180180
let args = [relpath, '--emit', a:type, '-o', output_path] + a:args
181181
let pwd = a:dict.istemp ? a:dict.tmpdir : ''
182182
let output = s:system(pwd, shellescape(rustc) . " " . join(map(args, 'shellescape(v:val)')))
183-
if output != ''
183+
if output !=# ''
184184
echohl WarningMsg
185185
echo output
186186
echohl None
@@ -190,10 +190,10 @@ function! s:Emit(dict, type, args)
190190
exe 'silent keepalt read' fnameescape(output_path)
191191
1
192192
d
193-
if a:type == "llvm-ir"
193+
if a:type ==# "llvm-ir"
194194
setl filetype=llvm
195195
let extension = 'll'
196-
elseif a:type == "asm"
196+
elseif a:type ==# "asm"
197197
setl filetype=asm
198198
let extension = 's'
199199
endif
@@ -259,8 +259,8 @@ function! s:WithPath(func, ...)
259259
let dict.tmpdir_relpath = filename
260260
let dict.path = dict.tmpdir.'/'.filename
261261

262-
let saved.mod = &mod
263-
set nomod
262+
let saved.mod = &modified
263+
set nomodified
264264

265265
silent exe 'keepalt write! ' . fnameescape(dict.path)
266266
if pathisempty
@@ -341,7 +341,7 @@ function! s:ShellTokenize(text)
341341
endif
342342
let l:state = 3
343343
elseif l:state == 5 " single-quoted
344-
if l:c == "'"
344+
if l:c ==# "'"
345345
let l:state = 1
346346
else
347347
let l:current .= l:c
@@ -359,7 +359,7 @@ function! s:RmDir(path)
359359
if empty(a:path)
360360
echoerr 'Attempted to delete empty path'
361361
return 0
362-
elseif a:path == '/' || a:path == $HOME
362+
elseif a:path ==# '/' || a:path ==# $HOME
363363
echoerr 'Attempted to delete protected path: ' . a:path
364364
return 0
365365
endif

compiler/cargo.vim

+4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ endif
1010
runtime compiler/rustc.vim
1111
let current_compiler = "cargo"
1212

13+
" vint: -ProhibitAbbreviationOption
1314
let s:save_cpo = &cpo
1415
set cpo&vim
16+
" vint: +ProhibitAbbreviationOption
1517

1618
if exists(':CompilerSet') != 2
1719
command -nargs=* CompilerSet setlocal <args>
@@ -39,7 +41,9 @@ CompilerSet errorformat+=
3941
\%-Gnote:\ Run\ with\ \`RUST_BACKTRACE=%.%#,
4042
\%.%#panicked\ at\ \\'%m\\'\\,\ %f:%l:%c
4143

44+
" vint: -ProhibitAbbreviationOption
4245
let &cpo = s:save_cpo
4346
unlet s:save_cpo
47+
" vint: +ProhibitAbbreviationOption
4448

4549
" vim: set et sw=4 sts=4 ts=8:

compiler/rustc.vim

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ if exists("current_compiler")
99
endif
1010
let current_compiler = "rustc"
1111

12-
let s:cpo_save = &cpo
12+
" vint: -ProhibitAbbreviationOption
13+
let s:save_cpo = &cpo
1314
set cpo&vim
15+
" vint: +ProhibitAbbreviationOption
1416

1517
if exists(":CompilerSet") != 2
1618
command -nargs=* CompilerSet setlocal <args>
@@ -43,7 +45,9 @@ CompilerSet errorformat+=
4345
\%-G%*[\ ]^%*[~],
4446
\%-G%*[\ ]...
4547

46-
let &cpo = s:cpo_save
47-
unlet s:cpo_save
48+
" vint: -ProhibitAbbreviationOption
49+
let &cpo = s:save_cpo
50+
unlet s:save_cpo
51+
" vint: +ProhibitAbbreviationOption
4852

4953
" vim: set et sw=4 sts=4 ts=8:

ftdetect/rust.vim

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
au BufRead,BufNewFile *.rs set filetype=rust
2-
au BufRead,BufNewFile Cargo.toml if &filetype == "" | set filetype=cfg | endif
1+
" vint: -ProhibitAutocmdWithNoGroup
2+
3+
autocmd BufRead,BufNewFile *.rs set filetype=rust
4+
autocmd BufRead,BufNewFile Cargo.toml if &filetype == "" | set filetype=cfg | endif
35

46
" vim: set et sw=4 sts=4 ts=8:

ftplugin/rust.vim

+4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ if exists("b:did_ftplugin")
1010
endif
1111
let b:did_ftplugin = 1
1212

13+
" vint: -ProhibitAbbreviationOption
1314
let s:save_cpo = &cpo
1415
set cpo&vim
16+
" vint: +ProhibitAbbreviationOption
1517

1618
augroup rust.vim
1719
autocmd!
@@ -205,7 +207,9 @@ set matchpairs+=<:>
205207
" For matchit.vim (rustArrow stops `Fn() -> X` messing things up)
206208
let b:match_skip = 's:comment\|string\|rustArrow'
207209

210+
" vint: -ProhibitAbbreviationOption
208211
let &cpo = s:save_cpo
209212
unlet s:save_cpo
213+
" vint: +ProhibitAbbreviationOption
210214

211215
" vim: set et sw=4 sts=4 ts=8:

ftplugin/rust/tagbar.vim

+4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ if !exists(':Tagbar')
55
finish
66
endif
77

8+
" vint: -ProhibitAbbreviationOption
89
let s:save_cpo = &cpo
910
set cpo&vim
11+
" vint: +ProhibitAbbreviationOption
1012

1113
let g:tagbar_type_rust = {
1214
\ 'ctagstype' : 'rust',
@@ -27,8 +29,10 @@ if !get(g:, 'rust_use_custom_ctags_defs', 0)
2729
let g:tagbar_type_rust.deffile = expand('<sfile>:p:h:h:h') . '/ctags/rust.ctags'
2830
endif
2931

32+
" vint: -ProhibitAbbreviationOption
3033
let &cpo = s:save_cpo
3134
unlet s:save_cpo
35+
" vint: +ProhibitAbbreviationOption
3236

3337

3438
" vim: set et sw=4 sts=4 ts=8:

indent/rust.vim

+20-16
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ if exists("*GetRustIndent")
2929
finish
3030
endif
3131

32+
" vint: -ProhibitAbbreviationOption
3233
let s:save_cpo = &cpo
3334
set cpo&vim
35+
" vint: +ProhibitAbbreviationOption
3436

3537
" Come here when loading the script the first time.
3638

@@ -44,12 +46,12 @@ function! s:get_line_trimmed(lnum)
4446
" If the last character in the line is a comment, do a binary search for
4547
" the start of the comment. synID() is slow, a linear search would take
4648
" too long on a long line.
47-
if synIDattr(synID(a:lnum, line_len, 1), "name") =~ 'Comment\|Todo'
49+
if synIDattr(synID(a:lnum, line_len, 1), "name") =~? 'Comment\|Todo'
4850
let min = 1
4951
let max = line_len
5052
while min < max
5153
let col = (min + max) / 2
52-
if synIDattr(synID(a:lnum, col, 1), "name") =~ 'Comment\|Todo'
54+
if synIDattr(synID(a:lnum, col, 1), "name") =~? 'Comment\|Todo'
5355
let max = col
5456
else
5557
let min = col + 1
@@ -69,7 +71,7 @@ function! s:is_string_comment(lnum, col)
6971
if has('syntax_items')
7072
for id in synstack(a:lnum, a:col)
7173
let synname = synIDattr(id, "name")
72-
if synname == "rustString" || synname =~ "^rustComment"
74+
if synname ==# "rustString" || synname =~# "^rustComment"
7375
return 1
7476
endif
7577
endfor
@@ -88,13 +90,13 @@ function GetRustIndent(lnum)
8890

8991
if has('syntax_items')
9092
let synname = synIDattr(synID(a:lnum, 1, 1), "name")
91-
if synname == "rustString"
93+
if synname ==# "rustString"
9294
" If the start of the line is in a string, don't change the indent
9395
return -1
94-
elseif synname =~ '\(Comment\|Todo\)'
95-
\ && line !~ '^\s*/\*' " not /* opening line
96-
if synname =~ "CommentML" " multi-line
97-
if line !~ '^\s*\*' && getline(a:lnum - 1) =~ '^\s*/\*'
96+
elseif synname =~? '\(Comment\|Todo\)'
97+
\ && line !~# '^\s*/\*' " not /* opening line
98+
if synname =~? "CommentML" " multi-line
99+
if line !~# '^\s*\*' && getline(a:lnum - 1) =~# '^\s*/\*'
98100
" This is (hopefully) the line after a /*, and it has no
99101
" leader, so the correct indentation is that of the
100102
" previous line.
@@ -121,22 +123,22 @@ function GetRustIndent(lnum)
121123
" Search backwards for the previous non-empty line.
122124
let prevlinenum = prevnonblank(a:lnum - 1)
123125
let prevline = s:get_line_trimmed(prevlinenum)
124-
while prevlinenum > 1 && prevline !~ '[^[:blank:]]'
126+
while prevlinenum > 1 && prevline !~# '[^[:blank:]]'
125127
let prevlinenum = prevnonblank(prevlinenum - 1)
126128
let prevline = s:get_line_trimmed(prevlinenum)
127129
endwhile
128130

129131
" Handle where clauses nicely: subsequent values should line up nicely.
130-
if prevline[len(prevline) - 1] == ","
132+
if prevline[len(prevline) - 1] ==# ","
131133
\ && prevline =~# '^\s*where\s'
132134
return indent(prevlinenum) + 6
133135
endif
134136

135-
if prevline[len(prevline) - 1] == ","
136-
\ && s:get_line_trimmed(a:lnum) !~ '^\s*[\[\]{}]'
137-
\ && prevline !~ '^\s*fn\s'
138-
\ && prevline !~ '([^()]\+,$'
139-
\ && s:get_line_trimmed(a:lnum) !~ '^\s*\S\+\s*=>'
137+
if prevline[len(prevline) - 1] ==# ","
138+
\ && s:get_line_trimmed(a:lnum) !~# '^\s*[\[\]{}]'
139+
\ && prevline !~# '^\s*fn\s'
140+
\ && prevline !~# '([^()]\+,$'
141+
\ && s:get_line_trimmed(a:lnum) !~# '^\s*\S\+\s*=>'
140142
" Oh ho! The previous line ended in a comma! I bet cindent will try to
141143
" take this too far... For now, let's normally use the previous line's
142144
" indent.
@@ -195,7 +197,7 @@ function GetRustIndent(lnum)
195197
else
196198
" At the module scope, inside square brackets only
197199
"if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum
198-
if line =~ "^\\s*]"
200+
if line =~# "^\\s*]"
199201
" It's the closing line, dedent it
200202
return 0
201203
else
@@ -209,7 +211,9 @@ function GetRustIndent(lnum)
209211
return cindent(a:lnum)
210212
endfunction
211213

214+
" vint: -ProhibitAbbreviationOption
212215
let &cpo = s:save_cpo
213216
unlet s:save_cpo
217+
" vint: +ProhibitAbbreviationOption
214218

215219
" vim: set et sw=4 sts=4 ts=8:

syntax_checkers/rust/rustc.vim

+4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ if exists("g:loaded_syntastic_rust_rustc_checker")
1010
endif
1111
let g:loaded_syntastic_rust_rustc_checker = 1
1212

13+
" vint: -ProhibitAbbreviationOption
1314
let s:save_cpo = &cpo
1415
set cpo&vim
16+
" vint: +ProhibitAbbreviationOption
1517

1618
function! SyntaxCheckers_rust_rustc_GetLocList() dict
1719
let makeprg = self.makeprgBuild({})
@@ -44,7 +46,9 @@ call g:SyntasticRegistry.CreateAndRegisterChecker({
4446
\ 'filetype': 'rust',
4547
\ 'name': 'rustc'})
4648

49+
" vint: -ProhibitAbbreviationOption
4750
let &cpo = s:save_cpo
4851
unlet s:save_cpo
52+
" vint: +ProhibitAbbreviationOption
4953

5054
" vim: set et sw=4 sts=4 ts=8:

0 commit comments

Comments
 (0)