-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature request: flag for non-zero exit status if warnings are present #1209
Comments
The return code is handled by rustc itself. However in a script, it would be much easier to use JSON output: % rustc a.rs
warning: unused variable: `a`, #[warn(unused_variables)] on by default
--> a.rs:2:9
|
2 | let a = 42;
| ^
% rustc --error-format json a.rs
{"message":"unused variable: `a`, #[warn(unused_variables)] on by default","code":null,"level":"warning","spans":[{"file_name":"a.rs","byte_start":20,"byte_end":21,"line_start":2,"line_end":2,"column_start":9,"column_end":10,"is_primary":true,"text":[{"text":" let a = 42;","highlight_start":9,"highlight_end":10}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[],"rendered":null} (you get one line per error/warning, which is a json object describing the error) |
@mcarton: that does not clearly separate between messages generated by Clippy and other messages. For instance, the compiler aborting due to previous Clippy-induced errors is considered an error in itself. Moreover, Cargo writes these machine readable JSON messages on standard error instead of standard output, resulting in unparseable about (a mixture of exclusively human and machine readable output). |
You can pass |
@oli-obk: Does that work if you set the lint level to |
@sanmai-NL yes |
@oli-obk:
#![feature(stmt_expr_attributes)]
#![warn(bad_style)]
#![warn(future_incompatible)]
#![warn(unused)]
#![warn(warnings)]
#![allow(missing_docs)]
#![cfg_attr(feature = "cargo-clippy", warn(clippy))]
#![cfg_attr(feature = "cargo-clippy", warn(clippy_pedantic))]
#![cfg_attr(feature = "cargo-clippy", allow(missing_docs_in_private_items))]
// ... cargo +nightly clippy --frozen --all-features --package something -- -Dwarnings
echo $?
|
It works fine on my machine :/
It was in a lib project without workspaces though. |
@oli-obk: what can we do here? Can you or someone else who wishes to confirm take some more time to test with a virtual workspace? If this snag is resolved then this GitHub issue could, as far as I am concerned, be closed. So it seems worthwhile to test and even add a test case if there turns out to be a bug. |
@sanmai-NL If you give me a repro example (upload your example to github?) I can investigate further |
@oli-obk I had the same problem as @sanmai-NL , the output said |
I ran into this as well. FROM rust:1.26
RUN USER='root' cargo init --vcs=none --name=foo \
&& echo 'fn unused() {}' >> src/main.rs \
&& rustup --version \
&& rustup toolchain install nightly \
&& cargo +nightly install clippy \
&& cargo --version && cargo +nightly clippy --version \
&& cargo +nightly clippy -- -D warnings Which when built with
|
Fixed in #2863 Now we just need a regression test. Probably just adding something to travis is enough. |
I don't think forbidding warnings is enough. For example, when I have two packages in workspace, Moreover this is awkward to use in CI in non-blocking mode. I'd like to know number of hard errors and number of warnings. Hard errors should block CI, but not the warnings. |
I'm on macOS 10.15.6 x86 and clippy will not exit with non-zero status.
I'm trying to make my local dev tools work the same as the project's continuous integration scripts on GitHub. I tried configuring CLion 2020.2.4 with a single run configuration that runs both I would really appreciate advice on setting this up. |
Strangely, the problem just went away:
And the Perhaps clippy is caching some results on disk and returning 0 in some strange edge case? |
Maybe we can try |
Indeed this seems to be due to some persistent state (setting
|
@oli-obk the problem is that if i run with the option |
You're in luck: rust-lang/rust#87337 just got merged and should be in stable in 7 or 8 weeks, then this should just work exactly as you expect |
Note that rust-lang/rust#87337 only avoids failing fast within the crate; if you have multiple crates in a workspace, cargo will still stop after the first one with a denied warning. |
@jyn514 i see...., may i know what is the motivation of this design? I feel either make it configurable that totally not failing fast, or something like only after encountered certain number of denies then fail is better? Instead of like currently fail at 1st, then push then fail at another, so on and on, a bit annoying |
@lnshi "it's hard" and no one has done the work to implement it. |
Why is this issue still open? Seems pretty fixed to me |
This still doesn't work between crates in a workspace, only within individual crates. Doing it for the whole workspace requires cargo support: rust-lang/rust#82761 (comment) |
Here are two more reasons why a separate flag would be an improvement over
An option that changed the exit status behavior only would not have these disadvantages. |
Tracking #1209 (comment) in #12623 For the cargo feature that will be rust-lang/cargo#8424 |
Hello, awesome tool and using it has been helping me learn Rust!
I've been trying to automate executing clippy from some scripts I run across a number of crates I'm maintaining at the moment, and it's tricky to check if there was any warnings from clippy from a Bash script.
I'd love if there was a flag I could set to trigger non-zero exit statuses for any warnings so I can use clippy meaningfully from my scripts. Apologies if something like this already exists and I've just missed it, running
clippy --help
doesn't appear to show anything relevant though.The text was updated successfully, but these errors were encountered: