summaryrefslogtreecommitdiff
path: root/ale_linters/sh/shellcheck.vim
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-11-09 23:42:54 +0000
committerw0rp <devw0rp@gmail.com>2017-11-12 10:56:53 +0000
commita8c5e0f4dce14b9dad8e4a238ebc93d8aa6ed28e (patch)
tree54f4aabd2509aec116f3d89953d5e09fdc2c52a4 /ale_linters/sh/shellcheck.vim
parent911b6d8f71213d065bd14548a16ba9140f1790ee (diff)
downloadale-a8c5e0f4dce14b9dad8e4a238ebc93d8aa6ed28e.zip
Simplfy semver handling and share the semver version cache across everything
Diffstat (limited to 'ale_linters/sh/shellcheck.vim')
-rw-r--r--ale_linters/sh/shellcheck.vim31
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)