Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Rust cargo linter to better integrate with Clippy #2618

Merged
merged 2 commits into from
Jul 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions ale_linters/rust/cargo.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ endfunction
function! ale_linters#rust#cargo#GetCommand(buffer, version) abort
let l:use_check = ale#Var(a:buffer, 'rust_cargo_use_check')
\ && ale#semver#GTE(a:version, [0, 17, 0])
let l:use_all_targets = l:use_check
\ && ale#Var(a:buffer, 'rust_cargo_check_all_targets')
let l:use_all_targets = ale#Var(a:buffer, 'rust_cargo_check_all_targets')
\ && ale#semver#GTE(a:version, [0, 22, 0])
let l:use_examples = l:use_check
\ && ale#Var(a:buffer, 'rust_cargo_check_examples')
let l:use_examples = ale#Var(a:buffer, 'rust_cargo_check_examples')
\ && ale#semver#GTE(a:version, [0, 22, 0])
let l:use_tests = l:use_check
\ && ale#Var(a:buffer, 'rust_cargo_check_tests')
let l:use_tests = ale#Var(a:buffer, 'rust_cargo_check_tests')
\ && ale#semver#GTE(a:version, [0, 22, 0])

let l:include_features = ale#Var(a:buffer, 'rust_cargo_include_features')
Expand Down Expand Up @@ -69,7 +66,15 @@ function! ale_linters#rust#cargo#GetCommand(buffer, version) abort

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')
let l:clippy_options = ale#Var(a:buffer, 'rust_cargo_clippy_options')

if l:clippy_options =~# '^-- '
let l:clippy_options = join(split(l:clippy_options, '-- '))
endif

if l:clippy_options isnot# ''
let l:clippy_options = ' -- ' . l:clippy_options
endif
endif

return l:nearest_cargo_prefix . 'cargo '
Expand Down
39 changes: 38 additions & 1 deletion test/command_callback/test_cargo_command_callbacks.vader
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,60 @@ Execute(When a crate belongs to a workspace we chdir into the crate, unless we d

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', [
\ ale#Escape('cargo') . ' --version',
\ 'cargo clippy --frozen --message-format=json -q ',
\ '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', [
\ ale#Escape('cargo') . ' --version',
\ 'cargo clippy --frozen --message-format=json -q -- -D warnings',
\]

Execute(Clippy options work without prepending --):
let b:ale_rust_cargo_use_clippy = 1
let b:ale_rust_cargo_clippy_options = '-D warnings'

AssertLinter 'cargo', [
\ ale#Escape('cargo') . ' --version',
\ 'cargo clippy --frozen --message-format=json -q -- -D warnings',
\]

Execute(Build supports all cargo flags):
let g:ale_rust_cargo_use_check = 0
let g:ale_rust_cargo_check_all_targets = 1
let g:ale_rust_cargo_check_tests = 1
let g:ale_rust_cargo_check_examples = 1
let b:ale_rust_cargo_default_feature_behavior = 'all'

AssertLinter 'cargo', [
\ ale#Escape('cargo') . ' --version',
\ 'cargo build --all-targets --examples --tests --frozen --message-format=json -q --all-features',
\]

Execute(Clippy supports all cargo flags):
let b:ale_rust_cargo_use_clippy = 1
let g:ale_rust_cargo_check_all_targets = 1
let g:ale_rust_cargo_check_tests = 1
let g:ale_rust_cargo_check_examples = 1
let b:ale_rust_cargo_default_feature_behavior = 'all'
let b:ale_rust_cargo_clippy_options = '-D warnings'

AssertLinter 'cargo', [
\ ale#Escape('cargo') . ' --version',
\ 'cargo clippy --all-targets --examples --tests --frozen --message-format=json -q --all-features -- -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', [
\ ale#Escape('cargo') . ' --version',
\ 'cargo check --frozen --message-format=json -q',
Expand Down