diff options
author | w0rp <devw0rp@gmail.com> | 2017-11-09 23:42:54 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-11-09 23:42:54 +0000 |
commit | d425b8a18ab3c8155fdc7376192434f8878e954f (patch) | |
tree | 8a702b7b398fe43e9b8b3a05e3011b3ca530fd83 /ale_linters/sh | |
parent | c1fa88e78ccfeb98a688a209cd9f67da1bf076aa (diff) | |
download | ale-d425b8a18ab3c8155fdc7376192434f8878e954f.zip |
Simplfy semver handling and share the semver version cache across everything
Diffstat (limited to 'ale_linters/sh')
-rw-r--r-- | ale_linters/sh/shellcheck.vim | 31 |
1 files changed, 5 insertions, 26 deletions
diff --git a/ale_linters/sh/shellcheck.vim b/ale_linters/sh/shellcheck.vim index 1f6bdf81..e79b3b88 100644 --- a/ale_linters/sh/shellcheck.vim +++ b/ale_linters/sh/shellcheck.vim @@ -15,8 +15,6 @@ let g:ale_sh_shellcheck_executable = let g:ale_sh_shellcheck_options = \ get(g:, 'ale_sh_shellcheck_options', '') -let s:version_cache = {} - function! ale_linters#sh#shellcheck#GetExecutable(buffer) abort return ale#Var(a:buffer, 'sh_shellcheck_executable') endfunction @@ -49,38 +47,19 @@ function! ale_linters#sh#shellcheck#VersionCheck(buffer) abort let l:executable = ale_linters#sh#shellcheck#GetExecutable(a:buffer) " Don't check the version again if we've already cached it. - if has_key(s:version_cache, l:executable) - return '' - endif - - return ale#Escape(l:executable) . ' --version' -endfunction - -" Get the shellcheck version from the cache, or parse it and cache it. -function! s:GetVersion(executable, output) abort - let l:version = get(s:version_cache, a:executable, []) - - for l:match in ale#util#GetMatches(a:output, '\v\d+\.\d+\.\d+') - let l:version = ale#semver#Parse(l:match[0]) - let s:version_cache[a:executable] = l:version - endfor - - return l:version -endfunction - -function! s:CanUseExternalOption(version) abort - return !empty(a:version) - \ && ale#semver#GreaterOrEqual(a:version, [0, 4, 0]) + return !ale#semver#HasVersion(l:executable) + \ ? ale#Escape(l:executable) . ' --version' + \ : '' endfunction function! ale_linters#sh#shellcheck#GetCommand(buffer, version_output) abort let l:executable = ale_linters#sh#shellcheck#GetExecutable(a:buffer) - let l:version = s:GetVersion(l:executable, a:version_output) + let l:version = ale#semver#GetVersion(l:executable, a:version_output) 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) - let l:external_option = s:CanUseExternalOption(l:version) ? ' -x' : '' + let l:external_option = ale#semver#GTE(l:version, [0, 4, 0]) ? ' -x' : '' return ale#path#BufferCdString(a:buffer) \ . ale#Escape(l:executable) |