summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/rust/cargo.vim13
-rw-r--r--doc/ale-rust.txt31
-rw-r--r--test/command_callback/test_cargo_command_callbacks.vader24
3 files changed, 67 insertions, 1 deletions
diff --git a/ale_linters/rust/cargo.vim b/ale_linters/rust/cargo.vim
index 5aefe72c..cf6187f8 100644
--- a/ale_linters/rust/cargo.vim
+++ b/ale_linters/rust/cargo.vim
@@ -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', {
diff --git a/doc/ale-rust.txt b/doc/ale-rust.txt
index 13e5f6f0..ce5634ae 100644
--- a/doc/ale-rust.txt
+++ b/doc/ale-rust.txt
@@ -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*
diff --git a/test/command_callback/test_cargo_command_callbacks.vader b/test/command_callback/test_cargo_command_callbacks.vader
index ac8846b0..f0afbc91 100644
--- a/test/command_callback/test_cargo_command_callbacks.vader
+++ b/test/command_callback/test_cargo_command_callbacks.vader
@@ -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',
+ \]