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

Rust Clippy command line not handled correctly #4801

Open
mmottl opened this issue Jun 30, 2024 · 1 comment
Open

Rust Clippy command line not handled correctly #4801

mmottl opened this issue Jun 30, 2024 · 1 comment
Labels

Comments

@mmottl
Copy link

mmottl commented Jun 30, 2024

Information

VIM version

VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jun 18 2024 19:01:23)
macOS version - arm64

Operating System:

macOS X Sonoma 14.5

What went wrong

These options previously worked:

let g:ale_rust_cargo_use_clippy = executable('cargo-clippy')
let g:ale_rust_cargo_use_clippy = 1
let g:ale_rust_cargo_clippy_options =
  \ '--tests --all-features --all-targets -- -D warnings'

But not anymore:

(finished - exit code 101) ['/opt/homebrew/bin/zsh', '-c', 'cd ''xxx'' && cargo clippy --frozen --message-format=json -q -- --tests --all-features --all-targets -- -D warnings']

<<<OUTPUT STARTS>>>
error: process didn't exit successfully: `/Users/xxx/.rustup/toolchains/1.79.0-aarch64-apple-darwin/bin/clippy-driver /Users/xxx/.rustup/toolchains/1.79.0-aarch64-apple-darwin/bin/rustc -vV` (exit status: 1)
--- stderr
error: Unrecognized option: 'tests'


<<<OUTPUT ENDS>>>

It seems the extra -- before --tests is causing an issue. Not sure whether the problem is due to Rust version or Ale version changes.

The problem seems to be fixed when I change the following line in file cargo.vim:

            let l:clippy_options = ' -- ' . l:clippy_options

To:

            let l:clippy_options = ' ' . l:clippy_options

Hopefully, this fix will work for others, too.

Reproducing the bug

:ALEInfo

Expand Current Filetype: rust Available Linters: ['analyzer', 'cargo', 'cspell', 'rls', 'rustc'] Linter Aliases: 'analyzer' -> ['rust_analyzer'] Enabled Linters: ['analyzer', 'cargo'] Ignored Linters: [] Suggested Fixers: 'remove_trailing_lines' - Remove all blank lines at the end of a file. 'rustfmt' - Fix Rust files with Rustfmt. 'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.

Linter Variables:
" Press Space to read :help for a setting
let g:ale_rust_analyzer_config = {}
let g:ale_rust_analyzer_executable = 'rust-analyzer'
let g:ale_rust_cargo_avoid_whole_workspace = 1
let g:ale_rust_cargo_check_all_targets = 0
let g:ale_rust_cargo_check_examples = 0
let g:ale_rust_cargo_check_tests = 0
let g:ale_rust_cargo_clippy_options = '--tests --all-features --all-targets -- -D warnings'
let g:ale_rust_cargo_default_feature_behavior = 'default'
let g:ale_rust_cargo_include_features = ''
let g:ale_rust_cargo_target_dir = ''
let g:ale_rust_cargo_use_check = 1
let g:ale_rust_cargo_use_clippy = 1
let g:ale_rust_ignore_error_codes = []
let g:ale_rust_ignore_secondary_spans = 0
let g:ale_rust_rustfmt_options = '+nightly-2024-03-28 --edition 2021'

Global Variables:
" Press Space to read :help for a setting
let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_disable_lsp = 'auto'
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_fixers = {'vim': ['trim_whitespace', 'remove_trailing_lines'], 'sh': ['shfmt', 'trim_whitespace', 'remove_trailing_lines'], 'cpp': ['clang-format', 'trim_whitespace', 'remove_trailing_lines'], 'go': ['gofmt', 'trim_whitespace', 'remove_trailing_lines'], 'markdown': ['prettier', 'trim_whitespace', 'remove_trailing_lines'], 'bash': ['shfmt', 'trim_whitespace', 'remove_trailing_lines'], 'yaml': ['prettier', 'trim_whitespace', 'remove_trailing_lines'], 'ocaml': ['ocamlformat', 'trim_whitespace', 'remove_trailing_lines'], 'python': ['ruff_format', 'trim_whitespace', 'remove_trailing_lines'], 'bzl': ['buildifier', 'trim_whitespace', 'remove_trailing_lines'], 'c': ['clang-format', 'trim_whitespace', 'remove_trailing_lines'], 'proto': ['buf-format', 'protolint', 'trim_whitespace', 'remove_trailing_lines'], 'xml': ['xmllint', 'trim_whitespace', 'remove_trailing_lines'], 'toml': ['trim_whitespace', 'remove_trailing_lines'], 'rust': ['rustfmt', 'trim_whitespace', 'remove_trailing_lines'], 'zsh': ['shfmt', 'trim_whitespace', 'remove_trailing_lines'], 'json': ['prettier', 'trim_whitespace', 'remove_trailing_lines'], 'sql': ['sqlfluff', 'trim_whitespace', 'remove_trailing_lines'], 'java': ['google_java_format', 'trim_whitespace', 'remove_trailing_lines']}
let g:ale_history_enabled = 1
let g:ale_info_default_mode = 'preview'
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {'sh': ['bashate', 'language_server', 'shell', 'shellcheck'], 'cpp': ['cc', 'clangtidy', 'cppcheck', 'cpplint'], 'go': ['gofmt', 'golangci-lint', 'revive', 'staticcheck'], 'markdown': ['markdownlint', 'proselint', 'vale', 'writegood'], 'yaml': ['yamllint', 'yaml-language-server', 'circleci', 'spectral'], 'ocaml': ['merlin'], 'python': ['ruff', 'flake8', 'pylint', 'pyright', 'bandit'], 'c': ['cc', 'clangtidy', 'cppcheck', 'cpplint'], 'proto': ['buf_lint', 'protolint'], 'xml': ['xmllint'], 'rust': ['analyzer', 'cargo'], 'json': ['jsonlint', 'spectral'], 'java': ['javalsp', 'checkstyle', 'pmd'], 'sql': ['sqlfluff'], 'ansible': ['ansible_lint', 'language_server']}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '✘'
let g:ale_sign_info = 'ⓘ'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '✘'
let g:ale_sign_style_warning = '⚠'
let g:ale_sign_warning = '⚠'
let g:ale_sign_highlight_linenrs = 0
let g:ale_type_map = {}
let g:ale_use_neovim_diagnostics_api = 0
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 'all'
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1

Command History:

(executable check - success) rust-analyzer
(executable check - success) cargo
(finished - exit code 0) ['/opt/homebrew/bin/zsh', '-c', 'cd ''xxx'' && ''cargo'' --version']

<<>>
cargo 1.79.0 (ffa9cf99a 2024-06-03)
<<>>

(finished - exit code 101) ['/opt/homebrew/bin/zsh', '-c', 'cd ''xxx'' && cargo clippy --frozen --message-format=json -q -- --tests --all-features --all-targets -- -D warnings']

<<>>
error: process didn't exit successfully: /Users/xxx/.rustup/toolchains/1.79.0-aarch64-apple-darwin/bin/clippy-driver /Users/xxx/.rustup/toolchains/1.79.0-aarch64-apple-darwin/bin/rustc -vV (exit status: 1)
--- stderr
error: Unrecognized option: 'tests'

<<>>

@mmottl mmottl added the bug label Jun 30, 2024
@nospam2998
Copy link
Contributor

It appears these two dashes were explicitly added in commit e52388b, in order to make it possible to provide clippy options. While those dashes are indeed needed prior to selectors for specifying what to deny, warn and allow, it seems like a valid use case to also wish to provide cargo options of which the clippy options obviously are a substring.

In other words, it is working as designed and documented. Whether or not it is working as desired is up for debate. With the variable being named ale_rust_cargo_clippy_options, both the expectations of whether it represents cargo options or clippy options are quite reasonable.

I believe that g:ale_rust_cargo_default_feature_behavior=all and g:ale_rust_cargo_check_all_targets=1 would cover your specific use case, but there might be other reasons for wishing to provide other flags.

How would an improvement look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants