mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-09 19:21:33 +08:00
Simplfy semver handling and share the semver version cache across everything
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user