mirror of https://github.com/dense-analysis/ale
Move the test for buffer-local variables
The "ale#handlers#sh#GetShellType()" function currently falls back to the file type without checking for buffer-local variables first. This causes the function to return "sh" even when a script is known by Vim to be a script of a more specific type (e.g., "bash"). The "ale#handlers#shellcheck#GetDialectArgument()" function then erroneously uses this type even though a more fitting type should be used instead. Files without a "#!" line will be of type "sh" even though they may have a ".bash" suffix. This commit fixes the problem by checking for buffer-local shell type variables (set by Vim) before falling back to the file type.
This commit is contained in:
parent
73632312c2
commit
31b7a2de41
|
@ -11,6 +11,17 @@ function! ale#handlers#sh#GetShellType(buffer) abort
|
||||||
let l:command = substitute(l:shebang, ' --\?[a-zA-Z0-9]\+', '', 'g')
|
let l:command = substitute(l:shebang, ' --\?[a-zA-Z0-9]\+', '', 'g')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" With no shebang line, attempt to use Vim's buffer-local variables.
|
||||||
|
if l:command is# ''
|
||||||
|
if getbufvar(a:buffer, 'is_bash', 0)
|
||||||
|
let l:command = 'bash'
|
||||||
|
elseif getbufvar(a:buffer, 'is_sh', 0)
|
||||||
|
let l:command = 'sh'
|
||||||
|
elseif getbufvar(a:buffer, 'is_kornshell', 0)
|
||||||
|
let l:command = 'ksh'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
" If we couldn't find a shebang, try the filetype
|
" If we couldn't find a shebang, try the filetype
|
||||||
if l:command is# ''
|
if l:command is# ''
|
||||||
let l:command = &filetype
|
let l:command = &filetype
|
||||||
|
|
|
@ -13,15 +13,6 @@ function! ale#handlers#shellcheck#GetDialectArgument(buffer) abort
|
||||||
return l:shell_type
|
return l:shell_type
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If there's no hashbang, try using Vim's buffer variables.
|
|
||||||
if getbufvar(a:buffer, 'is_bash', 0)
|
|
||||||
return 'bash'
|
|
||||||
elseif getbufvar(a:buffer, 'is_sh', 0)
|
|
||||||
return 'sh'
|
|
||||||
elseif getbufvar(a:buffer, 'is_kornshell', 0)
|
|
||||||
return 'ksh'
|
|
||||||
endif
|
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue