From b031531e79d409af3b143a1f40431cd868cd78fb Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 28 Aug 2017 19:16:23 +0100 Subject: #869 - Detect the shell dialect from the hashbang for shellcheck --- ale_linters/sh/shellcheck.vim | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'ale_linters/sh/shellcheck.vim') 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', { -- cgit v1.2.3