Closed lloeki closed 3 years ago
Actually came up with this limited workaround:
function! ShellcheckDetect(buffer)
for l:line_num in [1, 2, 3]
let l:line = get(getbufline(a:buffer, l:line_num), 0, '')
if l:line[:11] is# '# shellcheck'
let l:command = l:line
for l:possible_shell in ['bash', 'dash', 'ash', 'tcsh', 'csh', 'zsh', 'ksh', 'sh']
if l:command =~# l:possible_shell . '\s*$'
return l:possible_shell
endif
endfor
endif
endfor
return ''
endfunction
function! ShellcheckSet(buffer)
let l:shell = ShellcheckDetect(a:buffer)
if l:shell == 'bash'
call setbufvar(a:buffer, 'is_bash', 1)
else
call setbufvar(a:buffer, 'is_bash', 0)
endif
endfunction
autocmd FileType sh call ShellcheckSet(bufnr("%"))
@lloeki I have create a PR that adds support to shellcheck shell directives for dialect detection.
Information
VIM version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 11 2020 13:48:59) macOS version Included patches: 1-343
Operating System: macOS 10.15
What went wrong
Opening a shell file with
shellcheck shell=bash
lints withshellcheck -s sh
.Reproducing the bug
=> ALE orders spellcheck to lint as sh
Seems like in
ale_linters#sh#shellcheck#GetDialectArgument(buffer)
there's a vim-level workaround possible by writing my own autocmd to set some buffer variables, but my vimscript-fu is terrible:But from a cursory look I suppose
ale#handlers#sh#GetShellType(buffer)
ought to be modified to look forshellcheck shell={dialect}
in the first few lines (again my vimscript-fu is appalling, otherwise I'd have made a PR 😅).:ALEInfo