Skip to content

Commit bde8b4c

Browse files
authored
Fix vimscript lint errors and add CI linter (#181)
* Add Vint config file for vimscript linting * Replace underscore convention with proper script-local scopes * Prefer single quoted strings * Use the full option name * Use robust operators
2 parents 3693ec6 + c212352 commit bde8b4c

File tree

2 files changed

+105
-100
lines changed

2 files changed

+105
-100
lines changed

.vintrc.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cmdargs:
2+
severity: style_problem
3+
color: true
4+
env:
5+
neovim: false

plugin/vimux.vim

Lines changed: 100 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
if exists("g:loaded_vimux") || &cp
1+
if exists('g:loaded_vimux') || &compatible
22
finish
33
endif
44
let g:loaded_vimux = 1
55

6-
function! _VimuxOption(option, default)
6+
function! s:VimuxOption(option, default)
77
if exists(a:option)
88
return eval(a:option)
99
else
1010
return a:default
1111
endif
1212
endfunction
1313

14-
function! _VimuxTmuxCmd()
15-
return _VimuxOption("g:VimuxTmuxCommand", "tmux")
14+
function! s:VimuxTmuxCmd()
15+
return s:VimuxOption('g:VimuxTmuxCommand', 'tmux')
1616
endfunction
1717

18-
if !executable(_VimuxTmuxCmd())
19-
echohl ErrorMsg | echomsg "Failed to find executable "._VimuxTmuxCmd() | echohl None
18+
if !executable(s:VimuxTmuxCmd())
19+
echohl ErrorMsg | echomsg 'Failed to find executable '.s:VimuxTmuxCmd() | echohl None
2020
finish
2121
endif
2222

@@ -35,220 +35,220 @@ command VimuxClearRunnerHistory :call VimuxClearRunnerHistory()
3535
command VimuxTogglePane :call VimuxTogglePane()
3636

3737
function! VimuxRunCommandInDir(command, useFile)
38-
let l:file = ""
38+
let l:file = ''
3939
if a:useFile ==# 1
4040
let l:file = shellescape(expand('%:t'), 1)
4141
endif
42-
call VimuxRunCommand("(cd ".shellescape(expand('%:p:h'), 1)." && ".a:command." ".l:file.")")
42+
call VimuxRunCommand('(cd '.shellescape(expand('%:p:h'), 1).' && '.a:command.' '.l:file.')')
4343
endfunction
4444

4545
function! VimuxRunLastCommand()
46-
if exists("g:VimuxRunnerIndex")
46+
if exists('g:VimuxRunnerIndex')
4747
call VimuxRunCommand(g:VimuxLastCommand)
4848
else
49-
echo "No last vimux command."
49+
echo 'No last vimux command.'
5050
endif
5151
endfunction
5252

5353
function! VimuxRunCommand(command, ...)
54-
if !exists("g:VimuxRunnerIndex") || _VimuxHasRunner(g:VimuxRunnerIndex) == -1
54+
if !exists('g:VimuxRunnerIndex') || s:VimuxHasRunner(g:VimuxRunnerIndex) ==# -1
5555
call VimuxOpenRunner()
5656
endif
5757

5858
let l:autoreturn = 1
59-
if exists("a:1")
59+
if exists('a:1')
6060
let l:autoreturn = a:1
6161
endif
6262

63-
let resetSequence = _VimuxOption("g:VimuxResetSequence", "q C-u")
63+
let resetSequence = s:VimuxOption('g:VimuxResetSequence', 'q C-u')
6464
let g:VimuxLastCommand = a:command
6565

6666
call VimuxSendKeys(resetSequence)
6767
call VimuxSendText(a:command)
6868

69-
if l:autoreturn == 1
70-
call VimuxSendKeys("Enter")
69+
if l:autoreturn ==# 1
70+
call VimuxSendKeys('Enter')
7171
endif
7272
endfunction
7373

7474
function! VimuxSendText(text)
75-
call VimuxSendKeys(shellescape(substitute(a:text, "\n$", " ", "")))
75+
call VimuxSendKeys(shellescape(substitute(a:text, '\n$', ' ', '')))
7676
endfunction
7777

7878
function! VimuxSendKeys(keys)
79-
if exists("g:VimuxRunnerIndex")
80-
call _VimuxTmux("send-keys -t ".g:VimuxRunnerIndex." ".a:keys)
79+
if exists('g:VimuxRunnerIndex')
80+
call s:VimuxTmux('send-keys -t '.g:VimuxRunnerIndex.' '.a:keys)
8181
else
82-
echo "No vimux runner pane/window. Create one with VimuxOpenRunner"
82+
echo 'No vimux runner pane/window. Create one with VimuxOpenRunner'
8383
endif
8484
endfunction
8585

8686
function! VimuxOpenRunner()
87-
let nearestIndex = _VimuxNearestIndex()
87+
let nearestIndex = s:VimuxNearestIndex()
8888

89-
if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1
89+
if s:VimuxOption('g:VimuxUseNearest', 1) ==# 1 && nearestIndex != -1
9090
let g:VimuxRunnerIndex = nearestIndex
9191
else
92-
let extraArguments = _VimuxOption("g:VimuxOpenExtraArgs", "")
93-
if _VimuxRunnerType() == "pane"
94-
let height = _VimuxOption("g:VimuxHeight", 20)
95-
let orientation = _VimuxOption("g:VimuxOrientation", "v")
96-
call _VimuxTmux("split-window -p ".height." -".orientation." ".extraArguments)
97-
elseif _VimuxRunnerType() == "window"
98-
call _VimuxTmux("new-window ".extraArguments)
92+
let extraArguments = s:VimuxOption('g:VimuxOpenExtraArgs', '')
93+
if s:VimuxRunnerType() ==# 'pane'
94+
let height = s:VimuxOption('g:VimuxHeight', 20)
95+
let orientation = s:VimuxOption('g:VimuxOrientation', 'v')
96+
call s:VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments)
97+
elseif s:VimuxRunnerType() ==# 'window'
98+
call s:VimuxTmux('new-window '.extraArguments)
9999
endif
100100

101-
let g:VimuxRunnerIndex = _VimuxTmuxIndex()
102-
call _VimuxSetRunnerName()
103-
call _VimuxTmux("last-"._VimuxRunnerType())
101+
let g:VimuxRunnerIndex = s:VimuxTmuxIndex()
102+
call s:VimuxSetRunnerName()
103+
call s:VimuxTmux('last-'.s:VimuxRunnerType())
104104
endif
105105
endfunction
106106

107107
function! VimuxCloseRunner()
108-
if exists("g:VimuxRunnerIndex")
109-
call _VimuxTmux("kill-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex)
108+
if exists('g:VimuxRunnerIndex')
109+
call s:VimuxTmux('kill-'.s:VimuxRunnerType().' -t '.g:VimuxRunnerIndex)
110110
unlet g:VimuxRunnerIndex
111111
endif
112112
endfunction
113113

114114
function! VimuxTogglePane()
115-
if exists("g:VimuxRunnerIndex")
116-
if _VimuxRunnerType() == "window"
117-
call _VimuxTmux("join-pane -d -s ".g:VimuxRunnerIndex." -p "._VimuxOption("g:VimuxHeight", 20))
118-
let g:VimuxRunnerType = "pane"
119-
elseif _VimuxRunnerType() == "pane"
120-
let g:VimuxRunnerIndex=substitute(_VimuxTmux("break-pane -d -t ".g:VimuxRunnerIndex." -P -F '#{window_id}'"), "\n", "", "")
121-
let g:VimuxRunnerType = "window"
115+
if exists('g:VimuxRunnerIndex')
116+
if s:VimuxRunnerType() ==# 'window'
117+
call s:VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.s:VimuxOption('g:VimuxHeight', 20))
118+
let g:VimuxRunnerType = 'pane'
119+
elseif s:VimuxRunnerType() ==# 'pane'
120+
let g:VimuxRunnerIndex=substitute(s:VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '')
121+
let g:VimuxRunnerType = 'window'
122122
endif
123123
endif
124124
endfunction
125125

126126
function! VimuxZoomRunner()
127-
if exists("g:VimuxRunnerIndex")
128-
if _VimuxRunnerType() == "pane"
129-
call _VimuxTmux("resize-pane -Z -t ".g:VimuxRunnerIndex)
130-
elseif _VimuxRunnerType() == "window"
131-
call _VimuxTmux("select-window -t ".g:VimuxRunnerIndex)
127+
if exists('g:VimuxRunnerIndex')
128+
if s:VimuxRunnerType() ==# 'pane'
129+
call s:VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex)
130+
elseif s:VimuxRunnerType() ==# 'window'
131+
call s:VimuxTmux('select-window -t '.g:VimuxRunnerIndex)
132132
endif
133133
endif
134134
endfunction
135135

136136
function! VimuxInspectRunner()
137-
call _VimuxTmux("select-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex)
138-
call _VimuxTmux("copy-mode")
137+
call s:VimuxTmux('select-'.s:VimuxRunnerType().' -t '.g:VimuxRunnerIndex)
138+
call s:VimuxTmux('copy-mode')
139139
endfunction
140140

141141
function! VimuxScrollUpInspect()
142142
call VimuxInspectRunner()
143-
call _VimuxTmux("last-"._VimuxRunnerType())
144-
call VimuxSendKeys("C-u")
143+
call s:VimuxTmux('last-'.s:VimuxRunnerType())
144+
call VimuxSendKeys('C-u')
145145
endfunction
146146

147147
function! VimuxScrollDownInspect()
148148
call VimuxInspectRunner()
149-
call _VimuxTmux("last-"._VimuxRunnerType())
150-
call VimuxSendKeys("C-d")
149+
call s:VimuxTmux('last-'.s:VimuxRunnerType())
150+
call VimuxSendKeys('C-d')
151151
endfunction
152152

153153
function! VimuxInterruptRunner()
154-
call VimuxSendKeys("^c")
154+
call VimuxSendKeys('^c')
155155
endfunction
156156

157157
function! VimuxClearTerminalScreen()
158-
if exists("g:VimuxRunnerIndex")
159-
call VimuxSendKeys("C-l")
158+
if exists('g:VimuxRunnerIndex')
159+
call VimuxSendKeys('C-l')
160160
endif
161161
endfunction
162162

163163
function! VimuxClearRunnerHistory()
164-
if exists("g:VimuxRunnerIndex")
165-
call _VimuxTmux("clear-history -t ".g:VimuxRunnerIndex)
164+
if exists('g:VimuxRunnerIndex')
165+
call s:VimuxTmux('clear-history -t '.g:VimuxRunnerIndex)
166166
endif
167167
endfunction
168168

169169
function! VimuxPromptCommand(...)
170-
let command = a:0 == 1 ? a:1 : ""
171-
let l:command = input(_VimuxOption("g:VimuxPromptString", "Command? "), command, 'shellcmd')
170+
let command = a:0 ==# 1 ? a:1 : ''
171+
let l:command = input(s:VimuxOption('g:VimuxPromptString', 'Command? '), command, 'shellcmd')
172172
call VimuxRunCommand(l:command)
173173
endfunction
174174

175-
function! _VimuxTmux(arguments)
176-
if _VimuxOption("g:VimuxDebug", 0) != 0
177-
echom _VimuxTmuxCmd()." ".a:arguments
175+
function! s:VimuxTmux(arguments)
176+
if s:VimuxOption('g:VimuxDebug', 0) != 0
177+
echom s:VimuxTmuxCmd().' '.a:arguments
178178
endif
179-
return system(_VimuxTmuxCmd()." ".a:arguments)
179+
return system(s:VimuxTmuxCmd().' '.a:arguments)
180180
endfunction
181181

182-
function! _VimuxTmuxSession()
183-
return _VimuxTmuxProperty("#S")
182+
function! s:VimuxTmuxSession()
183+
return s:VimuxTmuxProperty('#S')
184184
endfunction
185185

186-
function! _VimuxTmuxIndex()
187-
if _VimuxRunnerType() == "pane"
188-
return _VimuxTmuxPaneId()
186+
function! s:VimuxTmuxIndex()
187+
if s:VimuxRunnerType() ==# 'pane'
188+
return s:VimuxTmuxPaneId()
189189
else
190-
return _VimuxTmuxWindowId()
190+
return s:VimuxTmuxWindowId()
191191
end
192192
endfunction
193193

194-
function! _VimuxTmuxPaneId()
195-
return _VimuxTmuxProperty("#{pane_id}")
194+
function! s:VimuxTmuxPaneId()
195+
return s:VimuxTmuxProperty('#{pane_id}')
196196
endfunction
197197

198-
function! _VimuxTmuxWindowId()
199-
return _VimuxTmuxProperty("#{window_id}")
198+
function! s:VimuxTmuxWindowId()
199+
return s:VimuxTmuxProperty('#{window_id}')
200200
endfunction
201201

202-
function! _VimuxNearestIndex()
203-
let t = _VimuxRunnerType()
204-
let filter = _VimuxGetTargetFilter()
205-
let views = split(_VimuxTmux("list-".t."s -F '#{".t."_active}:#{".t."_id}'".filter), "\n")
202+
function! s:VimuxNearestIndex()
203+
let t = s:VimuxRunnerType()
204+
let filter = s:VimuxGetTargetFilter()
205+
let views = split(s:VimuxTmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n')
206206

207207
for view in views
208-
if match(view, "1:") == -1
209-
return split(view, ":")[1]
208+
if match(view, '1:') ==# -1
209+
return split(view, ':')[1]
210210
endif
211211
endfor
212212

213213
return -1
214214
endfunction
215215

216-
function! _VimuxGetTargetFilter()
217-
let targetName = _VimuxOption("g:VimuxRunnerName", "")
218-
if targetName == ""
219-
return ""
216+
function! s:VimuxGetTargetFilter()
217+
let targetName = s:VimuxOption('g:VimuxRunnerName', '')
218+
if targetName ==# ''
219+
return ''
220220
endif
221-
let t = _VimuxRunnerType()
222-
if t == "window"
221+
let t = s:VimuxRunnerType()
222+
if t ==# 'window'
223223
return " -f '#{==:#{window_name},".targetName."}'"
224-
elseif t == "pane"
224+
elseif t ==# 'pane'
225225
return " -f '#{==:#{pane_title},".targetName."}'"
226226
endif
227227
endfunction
228228

229-
function! _VimuxSetRunnerName()
230-
let targetName = _VimuxOption("g:VimuxRunnerName", "")
231-
if targetName == ""
229+
function! s:VimuxSetRunnerName()
230+
let targetName = s:VimuxOption('g:VimuxRunnerName', '')
231+
if targetName ==# ''
232232
return
233233
endif
234-
let t = _VimuxRunnerType()
235-
if t == "window"
236-
call _VimuxTmux("rename-window ".targetName)
237-
elseif t == "pane"
238-
call _VimuxTmux("select-pane -T ".targetName)
234+
let t = s:VimuxRunnerType()
235+
if t ==# 'window'
236+
call s:VimuxTmux('rename-window '.targetName)
237+
elseif t ==# 'pane'
238+
call s:VimuxTmux('select-pane -T '.targetName)
239239
endif
240240
endfunction
241241

242242

243-
function! _VimuxRunnerType()
244-
return _VimuxOption("g:VimuxRunnerType", "pane")
243+
function! s:VimuxRunnerType()
244+
return s:VimuxOption('g:VimuxRunnerType', 'pane')
245245
endfunction
246246

247-
function! _VimuxTmuxProperty(property)
248-
return substitute(_VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
247+
function! s:VimuxTmuxProperty(property)
248+
return substitute(s:VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
249249
endfunction
250250

251-
function! _VimuxHasRunner(index)
252-
let t = _VimuxRunnerType()
253-
return match(_VimuxTmux("list-".t."s -F '#{".t."_id}'"), a:index)
251+
function! s:VimuxHasRunner(index)
252+
let t = s:VimuxRunnerType()
253+
return match(s:VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index)
254254
endfunction

0 commit comments

Comments
 (0)