diff options
Diffstat (limited to 'ale_linters/sh')
-rw-r--r-- | ale_linters/sh/shell.vim | 14 | ||||
-rw-r--r-- | ale_linters/sh/shellcheck.vim | 30 |
2 files changed, 23 insertions, 21 deletions
diff --git a/ale_linters/sh/shell.vim b/ale_linters/sh/shell.vim index 8f5ca3ae..cf5e4e6c 100644 --- a/ale_linters/sh/shell.vim +++ b/ale_linters/sh/shell.vim @@ -17,18 +17,10 @@ if !exists('g:ale_sh_shell_default_shell') endif function! ale_linters#sh#shell#GetExecutable(buffer) abort - let l:banglines = getbufline(a:buffer, 1) + let l:shell_type = ale#handlers#sh#GetShellType(a:buffer) - " Take the shell executable from the hashbang, if we can. - if len(l:banglines) == 1 && l:banglines[0] =~# '^#!' - " Remove options like -e, etc. - let l:line = substitute(l:banglines[0], '--\?[a-zA-Z0-9]\+', '', 'g') - - for l:possible_shell in ['bash', 'tcsh', 'csh', 'zsh', 'sh'] - if l:line =~# l:possible_shell . '\s*$' - return l:possible_shell - endif - endfor + if !empty(l:shell_type) + return l:shell_type endif return ale#Var(a:buffer, 'sh_shell_default_shell') diff --git a/ale_linters/sh/shellcheck.vim b/ale_linters/sh/shellcheck.vim index 5353683d..3a2d33f2 100644 --- a/ale_linters/sh/shellcheck.vim +++ b/ale_linters/sh/shellcheck.vim @@ -19,25 +19,35 @@ function! ale_linters#sh#shellcheck#GetExecutable(buffer) abort return ale#Var(a:buffer, 'sh_shellcheck_executable') endfunction -function! s:GetDialectArgument() abort - if exists('b:is_bash') && b:is_bash - return '-s bash' - elseif exists('b:is_sh') && b:is_sh - return '-s sh' - elseif exists('b:is_kornshell') && b:is_kornshell - return '-s ksh' +function! ale_linters#sh#shellcheck#GetDialectArgument(buffer) abort + let l:shell_type = ale#handlers#sh#GetShellType(a:buffer) + + if !empty(l:shell_type) + return l:shell_type + endif + + " If there's no hashbang, try using Vim's buffer variables. + if get(b:, 'is_bash') + return 'bash' + elseif get(b:, 'is_sh') + return 'sh' + elseif get(b:, 'is_kornshell') + return 'ksh' endif return '' endfunction function! ale_linters#sh#shellcheck#GetCommand(buffer) abort + let l:options = ale#Var(a:buffer, 'sh_shellcheck_options') let l:exclude_option = ale#Var(a:buffer, 'sh_shellcheck_exclusions') + let l:dialect = ale_linters#sh#shellcheck#GetDialectArgument(a:buffer) return ale_linters#sh#shellcheck#GetExecutable(a:buffer) - \ . ' ' . ale#Var(a:buffer, 'sh_shellcheck_options') - \ . ' ' . (!empty(l:exclude_option) ? '-e ' . l:exclude_option : '') - \ . ' ' . s:GetDialectArgument() . ' -f gcc -' + \ . (!empty(l:options) ? ' ' . l:options : '') + \ . (!empty(l:exclude_option) ? ' -e ' . l:exclude_option : '') + \ . (!empty(l:dialect) ? ' -s ' . l:dialect : '') + \ . ' -f gcc -' endfunction call ale#linter#Define('sh', { |