From 6c22936303a3236b471baee81c83683de4c25f47 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Mon, 2 Nov 2020 10:46:28 -0500 Subject: [PATCH 1/3] Remove a noise comment --- autoload/ale/handlers/sh.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/ale/handlers/sh.vim b/autoload/ale/handlers/sh.vim index 1e50cb8958..20ed5cb8e7 100644 --- a/autoload/ale/handlers/sh.vim +++ b/autoload/ale/handlers/sh.vim @@ -1,6 +1,5 @@ " Author: w0rp -" Get the shell type for a buffer, based on the hashbang line. function! ale#handlers#sh#GetShellType(buffer) abort let l:bang_line = get(getbufline(a:buffer, 1), 0, '') From 73632312c2519d7925dc57e5abcd0eacc5f1e55f Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Mon, 2 Nov 2020 10:46:56 -0500 Subject: [PATCH 2/3] Use the proper term for the "#!" line --- autoload/ale/handlers/sh.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/autoload/ale/handlers/sh.vim b/autoload/ale/handlers/sh.vim index 20ed5cb8e7..f99c3dbd98 100644 --- a/autoload/ale/handlers/sh.vim +++ b/autoload/ale/handlers/sh.vim @@ -1,17 +1,17 @@ " Author: w0rp function! ale#handlers#sh#GetShellType(buffer) abort - let l:bang_line = get(getbufline(a:buffer, 1), 0, '') + let l:shebang = get(getbufline(a:buffer, 1), 0, '') let l:command = '' - " Take the shell executable from the hashbang, if we can. - if l:bang_line[:1] is# '#!' + " Take the shell executable from the shebang, if we can. + if l:shebang[:1] is# '#!' " Remove options like -e, etc. - let l:command = substitute(l:bang_line, ' --\?[a-zA-Z0-9]\+', '', 'g') + let l:command = substitute(l:shebang, ' --\?[a-zA-Z0-9]\+', '', 'g') endif - " If we couldn't find a hashbang, try the filetype + " If we couldn't find a shebang, try the filetype if l:command is# '' let l:command = &filetype endif From 31b7a2de41d7bfccfd80a563bf3920258230cdc3 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Mon, 2 Nov 2020 10:50:14 -0500 Subject: [PATCH 3/3] 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. --- autoload/ale/handlers/sh.vim | 11 +++++++++++ autoload/ale/handlers/shellcheck.vim | 9 --------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/autoload/ale/handlers/sh.vim b/autoload/ale/handlers/sh.vim index f99c3dbd98..6ed9fea37d 100644 --- a/autoload/ale/handlers/sh.vim +++ b/autoload/ale/handlers/sh.vim @@ -11,6 +11,17 @@ function! ale#handlers#sh#GetShellType(buffer) abort let l:command = substitute(l:shebang, ' --\?[a-zA-Z0-9]\+', '', 'g') 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 l:command is# '' let l:command = &filetype diff --git a/autoload/ale/handlers/shellcheck.vim b/autoload/ale/handlers/shellcheck.vim index b16280f0f4..351d6d3fd3 100644 --- a/autoload/ale/handlers/shellcheck.vim +++ b/autoload/ale/handlers/shellcheck.vim @@ -13,15 +13,6 @@ function! ale#handlers#shellcheck#GetDialectArgument(buffer) abort return l:shell_type 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 '' endfunction