summaryrefslogtreecommitdiff
path: root/ale_linters/sh/shellcheck.vim
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-08-28 19:16:23 +0100
committerw0rp <devw0rp@gmail.com>2017-08-28 19:16:23 +0100
commitb031531e79d409af3b143a1f40431cd868cd78fb (patch)
tree43109aa362992890041ec486fdc2f64bdb14325d /ale_linters/sh/shellcheck.vim
parent73ec83d055a62019c41e699981e841e395219cca (diff)
downloadale-b031531e79d409af3b143a1f40431cd868cd78fb.zip
#869 - Detect the shell dialect from the hashbang for shellcheck
Diffstat (limited to 'ale_linters/sh/shellcheck.vim')
-rw-r--r--ale_linters/sh/shellcheck.vim30
1 files changed, 20 insertions, 10 deletions
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', {