mirror of https://github.com/dense-analysis/ale
Add support for `cargo clippy` (#2001)
* Add support for `cargo clippy` * Add tests for cargo-clippy support * Add an example to doc for how to configure ale_rust_cargo_use_clippy
This commit is contained in:
parent
3bda132988
commit
f57ad883f2
|
@ -9,6 +9,8 @@ call ale#Set('rust_cargo_check_tests', 0)
|
|||
call ale#Set('rust_cargo_avoid_whole_workspace', 1)
|
||||
call ale#Set('rust_cargo_default_feature_behavior', 'default')
|
||||
call ale#Set('rust_cargo_include_features', '')
|
||||
call ale#Set('rust_cargo_use_clippy', 0)
|
||||
call ale#Set('rust_cargo_clippy_options', '')
|
||||
|
||||
function! ale_linters#rust#cargo#GetCargoExecutable(bufnr) abort
|
||||
if ale#path#FindNearestFile(a:bufnr, 'Cargo.toml') isnot# ''
|
||||
|
@ -70,14 +72,23 @@ function! ale_linters#rust#cargo#GetCommand(buffer, version_output) abort
|
|||
let l:default_feature = ''
|
||||
endif
|
||||
|
||||
let l:subcommand = l:use_check ? 'check' : 'build'
|
||||
let l:clippy_options = ''
|
||||
|
||||
if ale#Var(a:buffer, 'rust_cargo_use_clippy')
|
||||
let l:subcommand = 'clippy'
|
||||
let l:clippy_options = ' ' . ale#Var(a:buffer, 'rust_cargo_clippy_options')
|
||||
endif
|
||||
|
||||
return l:nearest_cargo_prefix . 'cargo '
|
||||
\ . (l:use_check ? 'check' : 'build')
|
||||
\ . l:subcommand
|
||||
\ . (l:use_all_targets ? ' --all-targets' : '')
|
||||
\ . (l:use_examples ? ' --examples' : '')
|
||||
\ . (l:use_tests ? ' --tests' : '')
|
||||
\ . ' --frozen --message-format=json -q'
|
||||
\ . l:default_feature
|
||||
\ . l:include_features
|
||||
\ . l:clippy_options
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('rust', {
|
||||
|
|
|
@ -109,6 +109,7 @@ g:ale_rust_cargo_include_features *g:ale_rust_cargo_include_features*
|
|||
When defined, ALE will set the `--features` option when invoking `cargo` to
|
||||
perform the lint check. See |g:ale_rust_cargo_default_feature_behavior|.
|
||||
|
||||
|
||||
g:ale_rust_cargo_avoid_whole_workspace *g:ale_rust_cargo_avoid_whole_workspace*
|
||||
*b:ale_rust_cargo_avoid_whole_workspace*
|
||||
Type: |Number|
|
||||
|
@ -119,6 +120,36 @@ g:ale_rust_cargo_avoid_whole_workspace *g:ale_rust_cargo_avoid_whole_workspace*
|
|||
in the crate's directory. Otherwise, behave as usual.
|
||||
|
||||
|
||||
g:ale_rust_cargo_use_clippy
|
||||
*g:ale_rust_cargo_use_clippy*
|
||||
*b:ale_rust_cargo_use_clippy*
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
|
||||
When set to 1, `cargo clippy` will be used instead of `cargo check` or
|
||||
`cargo build` as linter.
|
||||
For details of `cargo clippy`, please visit the following link:
|
||||
|
||||
https://github.com/rust-lang-nursery/rust-clippy
|
||||
|
||||
Since `cargo clippy` is optional toolchain, it's safer to check whether
|
||||
`cargo-clippy` is executable as follows:
|
||||
>
|
||||
let g:ale_rust_cargo_use_clippy = executable('cargo-clippy')
|
||||
<
|
||||
|
||||
g:ale_rust_cargo_clippy_options
|
||||
*g:ale_rust_cargo_clippy_options*
|
||||
*b:ale_rust_cargo_clippy_options*
|
||||
|
||||
Type: |String|
|
||||
Default: `''`
|
||||
|
||||
When `cargo clippy` is used, this value will be added to a command line to run
|
||||
it. This variable is useful when you want to add some extra options which
|
||||
only `cargo clippy` supports (e.g. `--deny`).
|
||||
|
||||
|
||||
===============================================================================
|
||||
rls *ale-rust-rls*
|
||||
|
||||
|
|
|
@ -128,3 +128,27 @@ Execute(When a crate belongs to a workspace we chdir into the crate, unless we d
|
|||
\ 'cargo --version',
|
||||
\ 'cargo check --frozen --message-format=json -q',
|
||||
\]
|
||||
|
||||
Execute(When ale_rust_cargo_use_clippy is set, cargo-clippy is used as linter):
|
||||
let b:ale_rust_cargo_use_clippy = 1
|
||||
AssertLinter '', [
|
||||
\ 'cargo --version',
|
||||
\ 'cargo clippy --frozen --message-format=json -q ',
|
||||
\]
|
||||
|
||||
Execute(When ale_rust_cargo_clippy_options is set, cargo-clippy appends it to commandline):
|
||||
let b:ale_rust_cargo_use_clippy = 1
|
||||
let b:ale_rust_cargo_clippy_options = '-- -D warnings'
|
||||
AssertLinter '', [
|
||||
\ 'cargo --version',
|
||||
\ 'cargo clippy --frozen --message-format=json -q -- -D warnings',
|
||||
\]
|
||||
|
||||
Execute(cargo-check does not refer ale_rust_cargo_clippy_options):
|
||||
let b:ale_rust_cargo_use_clippy = 0
|
||||
let b:ale_rust_cargo_use_check = 1
|
||||
let b:ale_rust_cargo_clippy_options = '-- -D warnings'
|
||||
AssertLinter '', [
|
||||
\ 'cargo --version',
|
||||
\ 'cargo check --frozen --message-format=json -q',
|
||||
\]
|
||||
|
|
Loading…
Reference in New Issue