diff options
author | w0rp <w0rp@users.noreply.github.com> | 2019-05-01 22:47:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-01 22:47:08 +0100 |
commit | 4c6f67a3d02d12a7ce2f35cc3cbe2e166ae83b72 (patch) | |
tree | b8479435bd6a6bdd182b79a42d10779b68035bd3 | |
parent | 5d65f9303326a2b6be0f3e0492a04277fb4f7376 (diff) | |
parent | 2303b05baab5b1a54f42d9d1ab2bff05970ebbb2 (diff) | |
download | ale-4c6f67a3d02d12a7ce2f35cc3cbe2e166ae83b72.zip |
Merge pull request #2446 from fnichol/add-var-sh-shellcheck-change-directory
Add g:ale_sh_shellcheck_change_directory
-rw-r--r-- | ale_linters/sh/shellcheck.vim | 6 | ||||
-rw-r--r-- | doc/ale-sh.txt | 12 | ||||
-rw-r--r-- | test/command_callback/test_shellcheck_command_callback.vader | 5 |
3 files changed, 22 insertions, 1 deletions
diff --git a/ale_linters/sh/shellcheck.vim b/ale_linters/sh/shellcheck.vim index 3920cab8..1d8b6096 100644 --- a/ale_linters/sh/shellcheck.vim +++ b/ale_linters/sh/shellcheck.vim @@ -10,6 +10,7 @@ call ale#Set('sh_shellcheck_exclusions', get(g:, 'ale_linters_sh_shellcheck_excl call ale#Set('sh_shellcheck_executable', 'shellcheck') call ale#Set('sh_shellcheck_dialect', 'auto') call ale#Set('sh_shellcheck_options', '') +call ale#Set('sh_shellcheck_change_directory', 1) function! ale_linters#sh#shellcheck#GetDialectArgument(buffer) abort let l:shell_type = ale#handlers#sh#GetShellType(a:buffer) @@ -40,12 +41,15 @@ function! ale_linters#sh#shellcheck#GetCommand(buffer, version) abort let l:exclude_option = ale#Var(a:buffer, 'sh_shellcheck_exclusions') let l:dialect = ale#Var(a:buffer, 'sh_shellcheck_dialect') let l:external_option = ale#semver#GTE(a:version, [0, 4, 0]) ? ' -x' : '' + let l:cd_string = ale#Var(a:buffer, 'sh_shellcheck_change_directory') + \ ? ale#path#BufferCdString(a:buffer) + \ : '' if l:dialect is# 'auto' let l:dialect = ale_linters#sh#shellcheck#GetDialectArgument(a:buffer) endif - return ale#path#BufferCdString(a:buffer) + return l:cd_string \ . '%e' \ . (!empty(l:dialect) ? ' -s ' . l:dialect : '') \ . (!empty(l:options) ? ' ' . l:options : '') diff --git a/doc/ale-sh.txt b/doc/ale-sh.txt index 64f59609..3eac9038 100644 --- a/doc/ale-sh.txt +++ b/doc/ale-sh.txt @@ -62,6 +62,18 @@ g:ale_sh_shellcheck_options *g:ale_sh_shellcheck_options* < +g:ale_sh_shellcheck_change_directory *g:ale_sh_shellcheck_change_directory* + *b:ale_sh_shellcheck_change_directory* + Type: |Number| + Default: `1` + + If set to `1`, ALE will switch to the directory the shell file being + checked with `shellcheck` is in before checking it. This helps `shellcheck` + determine the path to sourced files more easily. This option can be turned + off if you want to control the directory `shellcheck` is executed from + yourself. + + g:ale_sh_shellcheck_dialect *g:ale_sh_shellcheck_dialect* *b:ale_sh_shellcheck_dialect* Type: |String| diff --git a/test/command_callback/test_shellcheck_command_callback.vader b/test/command_callback/test_shellcheck_command_callback.vader index fcdb184a..1d5b056b 100644 --- a/test/command_callback/test_shellcheck_command_callback.vader +++ b/test/command_callback/test_shellcheck_command_callback.vader @@ -14,6 +14,11 @@ After: Execute(The default shellcheck command should be correct): AssertLinter 'shellcheck', b:prefix . ale#Escape('shellcheck') . b:suffix +Execute(The option disabling changing directories should work): + let g:ale_sh_shellcheck_change_directory = 0 + + AssertLinter 'shellcheck', ale#Escape('shellcheck') . b:suffix + Execute(The shellcheck command should accept options): let b:ale_sh_shellcheck_options = '--foobar' |