From 33c2c20e66f694daf899963d778c47f824cda732 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 26 Oct 2017 21:17:47 +0100 Subject: [PATCH] Fix #1051 - Support ash and dash for shellcheck and the sh linter --- ale_linters/sh/shellcheck.vim | 11 ++++++++--- autoload/ale/handlers/sh.vim | 2 +- test/test_shell_detection.vader | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ale_linters/sh/shellcheck.vim b/ale_linters/sh/shellcheck.vim index 68844a0..32b47e2 100644 --- a/ale_linters/sh/shellcheck.vim +++ b/ale_linters/sh/shellcheck.vim @@ -23,15 +23,20 @@ function! ale_linters#sh#shellcheck#GetDialectArgument(buffer) abort let l:shell_type = ale#handlers#sh#GetShellType(a:buffer) if !empty(l:shell_type) + " Use the dash dialect for /bin/ash, etc. + if l:shell_type is# 'ash' + return 'dash' + endif + return l:shell_type endif " If there's no hashbang, try using Vim's buffer variables. - if get(b:, 'is_bash') + if getbufvar(a:buffer, 'is_bash', 0) return 'bash' - elseif get(b:, 'is_sh') + elseif getbufvar(a:buffer, 'is_sh', 0) return 'sh' - elseif get(b:, 'is_kornshell') + elseif getbufvar(a:buffer, 'is_kornshell', 0) return 'ksh' endif diff --git a/autoload/ale/handlers/sh.vim b/autoload/ale/handlers/sh.vim index 894879e..e96dd3c 100644 --- a/autoload/ale/handlers/sh.vim +++ b/autoload/ale/handlers/sh.vim @@ -9,7 +9,7 @@ function! ale#handlers#sh#GetShellType(buffer) abort " Remove options like -e, etc. let l:command = substitute(l:bang_line, ' --\?[a-zA-Z0-9]\+', '', 'g') - for l:possible_shell in ['bash', 'tcsh', 'csh', 'zsh', 'sh'] + for l:possible_shell in ['bash', 'dash', 'ash', 'tcsh', 'csh', 'zsh', 'sh'] if l:command =~# l:possible_shell . '\s*$' return l:possible_shell endif diff --git a/test/test_shell_detection.vader b/test/test_shell_detection.vader index 37cf43c..adb8d70 100644 --- a/test/test_shell_detection.vader +++ b/test/test_shell_detection.vader @@ -81,3 +81,23 @@ Execute(The ksh dialect should be used for shellcheck if b:is_kornshell is 1): let b:is_kornshell = 1 AssertEqual 'ksh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr('')) + +Given(A file with /bin/ash): + #!/bin/ash + +Execute(The ash dialect should be used for the shell and the base function): + AssertEqual 'ash', ale#handlers#sh#GetShellType(bufnr('')) + AssertEqual 'ash', ale_linters#sh#shell#GetExecutable(bufnr('')) + +Execute(dash should be used for shellcheck, which has no ash dialect): + AssertEqual 'dash', ale_linters#sh#shellcheck#GetDialectArgument(bufnr('')) + +Given(A file with /bin/dash): + #!/bin/dash + +Execute(The dash dialect should be used for the shell and the base function): + AssertEqual 'dash', ale#handlers#sh#GetShellType(bufnr('')) + AssertEqual 'dash', ale_linters#sh#shell#GetExecutable(bufnr('')) + +Execute(dash should be used for shellcheck): + AssertEqual 'dash', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))