summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/javascript/flow.vim13
-rw-r--r--ale_linters/python/flake8.vim43
-rw-r--r--ale_linters/rust/cargo.vim62
-rw-r--r--ale_linters/sh/shellcheck.vim31
-rw-r--r--ale_linters/vim/vint.vim20
5 files changed, 35 insertions, 134 deletions
diff --git a/ale_linters/javascript/flow.vim b/ale_linters/javascript/flow.vim
index 0dd64535..6d51628b 100644
--- a/ale_linters/javascript/flow.vim
+++ b/ale_linters/javascript/flow.vim
@@ -23,18 +23,15 @@ function! ale_linters#javascript#flow#GetCommand(buffer, version_lines) abort
return ''
endif
- let l:use_respect_pragma = 1
+ let l:executable = ale_linters#javascript#flow#GetExecutable(a:buffer)
+ let l:version = ale#semver#GetVersion(l:executable, a:version_lines)
" If we can parse the version number, then only use --respect-pragma
" if the version is >= 0.36.0, which added the argument.
- for l:match in ale#util#GetMatches(a:version_lines, '\v\d+\.\d+\.\d+$')
- let l:use_respect_pragma = ale#semver#GreaterOrEqual(
- \ ale#semver#Parse(l:match[0]),
- \ [0, 36, 0]
- \)
- endfor
+ let l:use_respect_pragma = empty(l:version)
+ \ || ale#semver#GTE(l:version, [0, 36])
- return ale#Escape(ale_linters#javascript#flow#GetExecutable(a:buffer))
+ return ale#Escape(l:executable)
\ . ' check-contents'
\ . (l:use_respect_pragma ? ' --respect-pragma': '')
\ . ' --json --from ale %s'
diff --git a/ale_linters/python/flake8.vim b/ale_linters/python/flake8.vim
index 8aa4c4df..501db0b1 100644
--- a/ale_linters/python/flake8.vim
+++ b/ale_linters/python/flake8.vim
@@ -10,10 +10,6 @@ let g:ale_python_flake8_options =
\ get(g:, 'ale_python_flake8_options', s:default_options)
let g:ale_python_flake8_use_global = get(g:, 'ale_python_flake8_use_global', 0)
-" A map from Python executable paths to semver strings parsed for those
-" executables, so we don't have to look up the version number constantly.
-let s:version_cache = {}
-
function! s:UsingModule(buffer) abort
return ale#Var(a:buffer, 'python_flake8_options') =~# ' *-m flake8'
endfunction
@@ -26,62 +22,35 @@ function! ale_linters#python#flake8#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'python_flake8_executable')
endfunction
-function! ale_linters#python#flake8#ClearVersionCache() abort
- let s:version_cache = {}
-endfunction
-
function! ale_linters#python#flake8#VersionCheck(buffer) abort
let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer)
" If we have previously stored the version number in a cache, then
" don't look it up again.
- if has_key(s:version_cache, l:executable)
+ if ale#semver#HasVersion(l:executable)
" Returning an empty string skips this command.
return ''
endif
- let l:executable = ale#Escape(ale_linters#python#flake8#GetExecutable(a:buffer))
+ let l:executable = ale#Escape(l:executable)
let l:module_string = s:UsingModule(a:buffer) ? ' -m flake8' : ''
return l:executable . l:module_string . ' --version'
endfunction
-" Get the flake8 version from the output, or the cache.
-function! s:GetVersion(buffer, version_output) abort
- let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer)
- let l:version = []
-
- " Get the version from the cache.
- if has_key(s:version_cache, l:executable)
- return s:version_cache[l:executable]
- endif
-
- if !empty(a:version_output)
- " Parse the version string, and store it in the cache.
- let l:version = ale#semver#Parse(a:version_output[0])
- let s:version_cache[l:executable] = l:version
- endif
-
- return l:version
-endfunction
-
-" flake8 versions 3 and up support the --stdin-display-name argument.
-function! s:SupportsDisplayName(version) abort
- return !empty(a:version) && ale#semver#GreaterOrEqual(a:version, [3, 0, 0])
-endfunction
-
function! ale_linters#python#flake8#GetCommand(buffer, version_output) abort
- let l:version = s:GetVersion(a:buffer, a:version_output)
+ let l:executable = ale_linters#python#flake8#GetExecutable(a:buffer)
+ let l:version = ale#semver#GetVersion(l:executable, a:version_output)
" Only include the --stdin-display-name argument if we can parse the
" flake8 version, and it is recent enough to support it.
- let l:display_name_args = s:SupportsDisplayName(l:version)
+ let l:display_name_args = ale#semver#GTE(l:version, [3, 0, 0])
\ ? ' --stdin-display-name %s'
\ : ''
let l:options = ale#Var(a:buffer, 'python_flake8_options')
- return ale#Escape(ale_linters#python#flake8#GetExecutable(a:buffer))
+ return ale#Escape(l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --format=default'
\ . l:display_name_args . ' -'
diff --git a/ale_linters/rust/cargo.vim b/ale_linters/rust/cargo.vim
index f41cb4b6..ae26fab4 100644
--- a/ale_linters/rust/cargo.vim
+++ b/ale_linters/rust/cargo.vim
@@ -4,8 +4,6 @@
call ale#Set('rust_cargo_use_check', 1)
call ale#Set('rust_cargo_check_all_targets', 1)
-let s:version_cache = {}
-
function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort
if ale#path#FindNearestFile(a:bufnr, 'Cargo.toml') isnot# ''
return 'cargo'
@@ -17,59 +15,23 @@ function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort
endfunction
function! ale_linters#rust#cargo#VersionCheck(buffer) abort
- if has_key(s:version_cache, 'cargo')
- return ''
- endif
-
- return 'cargo --version'
-endfunction
-
-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:CanUseCargoCheck(buffer, version) abort
- " Allow `cargo check` to be disabled.
- if !ale#Var(a:buffer, 'rust_cargo_use_check')
- return 0
- endif
-
- return !empty(a:version)
- \ && ale#semver#GreaterOrEqual(a:version, [0, 17, 0])
-endfunction
-
-function! s:CanUseAllTargets(buffer, version) abort
- if !ale#Var(a:buffer, 'rust_cargo_use_check')
- return 0
- endif
-
- if !ale#Var(a:buffer, 'rust_cargo_check_all_targets')
- return 0
- endif
-
- return !empty(a:version)
- \ && ale#semver#GreaterOrEqual(a:version, [0, 22, 0])
+ return !ale#semver#HasVersion('cargo')
+ \ ? 'cargo --version'
+ \ : ''
endfunction
function! ale_linters#rust#cargo#GetCommand(buffer, version_output) abort
- let l:version = s:GetVersion('cargo', a:version_output)
- let l:command = s:CanUseCargoCheck(a:buffer, l:version)
- \ ? 'check'
- \ : 'build'
- let l:all_targets = s:CanUseAllTargets(a:buffer, l:version)
- \ ? ' --all-targets'
- \ : ''
+ let l:version = ale#semver#GetVersion('cargo', a:version_output)
+
+ let l:use_check = ale#Var(a:buffer, 'rust_cargo_use_check')
+ \ && ale#semver#GTE(l:version, [0, 17, 0])
+ let l:use_all_targets = l:use_check
+ \ && ale#Var(a:buffer, 'rust_cargo_check_all_targets')
+ \ && ale#semver#GTE(l:version, [0, 22, 0])
return 'cargo '
- \ . l:command
- \ . l:all_targets
+ \ . (l:use_check ? 'check' : 'build')
+ \ . (l:use_all_targets ? ' --all-targets' : '')
\ . ' --frozen --message-format=json -q'
endfunction
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)
diff --git a/ale_linters/vim/vint.vim b/ale_linters/vim/vint.vim
index adf2b4ab..dfa00dc0 100644
--- a/ale_linters/vim/vint.vim
+++ b/ale_linters/vim/vint.vim
@@ -6,25 +6,19 @@ let g:ale_vim_vint_show_style_issues =
\ get(g:, 'ale_vim_vint_show_style_issues', 1)
let s:enable_neovim = has('nvim') ? ' --enable-neovim ' : ''
let s:format = '-f "{file_path}:{line_number}:{column_number}: {severity}: {description} (see {reference})"'
-let s:vint_version = []
function! ale_linters#vim#vint#VersionCommand(buffer) abort
- if empty(s:vint_version)
- " Check the Vint version if we haven't checked it already.
- return 'vint --version'
- endif
-
- return ''
+ " Check the Vint version if we haven't checked it already.
+ return !ale#semver#HasVersion('vint')
+ \ ? 'vint --version'
+ \ : ''
endfunction
function! ale_linters#vim#vint#GetCommand(buffer, version_output) abort
- if empty(s:vint_version) && !empty(a:version_output)
- " Parse the version out of the --version output.
- let s:vint_version = ale#semver#Parse(join(a:version_output, "\n"))
- endif
+ let l:version = ale#semver#GetVersion('vint', a:version_output)
- let l:can_use_no_color_flag = empty(s:vint_version)
- \ || ale#semver#GreaterOrEqual(s:vint_version, [0, 3, 7])
+ let l:can_use_no_color_flag = empty(l:version)
+ \ || ale#semver#GTE(l:version, [0, 3, 7])
let l:warning_flag = ale#Var(a:buffer, 'vim_vint_show_style_issues') ? '-s' : '-w'