diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c6aef22bab..fd75c7d0745 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.0.97 — 2016-10-24 +* For convenience, `cargo clippy` defines a `cargo-clippy` feature. This was + previously added for a short time under the name `clippy` but removed for + compatibility. +* `cargo clippy --help` is more helping (and less helpful :smile:) + ## 0.0.96 — 2016-10-22 * Rustup to *rustc 1.14.0-nightly (f09420685 2016-10-20)* * New lint: [`iter_skip_next`] diff --git a/README.md b/README.md index fee1c5427f2..385a6998238 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,14 @@ You can add options to `allow`/`warn`/`deny`: Note: `deny` produces errors instead of warnings. +For convenience, `cargo clippy` automatically defines a `cargo-clippy` +features. This lets you set lints level and compile with or without clippy +transparently: + +```rust +#[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))] +``` + ## Link with clippy service `clippy-service` is a rust web initiative providing `rust-clippy` as a web service. diff --git a/src/main.rs b/src/main.rs index 594e017fd01..fe1a453ff62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,8 +111,7 @@ impl<'a> CompilerCalls<'a> for ClippyCompilerCalls { use std::path::Path; -const CARGO_CLIPPY_HELP: &str = "\ -Checks a package to catch common mistakes and improve your Rust code. +const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code. Usage: cargo clippy [options] [--] [...] @@ -129,8 +128,13 @@ one of: -W --warn OPT Set lint warnings -A --allow OPT Set lint allowed -D --deny OPT Set lint denied - -F --forbid OPT Set lint forbidden\ -"; + -F --forbid OPT Set lint forbidden + +The feature `cargo-clippy` is automatically defined for convinence. You can use +it to allow or deny lints, eg.: + + #[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))] +"#; pub fn main() { use std::env; @@ -213,13 +217,16 @@ pub fn main() { // this conditional check for the --sysroot flag is there so users can call `cargo-clippy` directly // without having to pass --sysroot or anything - let args: Vec = if env::args().any(|s| s == "--sysroot") { + let mut args: Vec = if env::args().any(|s| s == "--sysroot") { env::args().collect() } else { env::args().chain(Some("--sysroot".to_owned())).chain(Some(sys_root)).collect() }; + // this check ensures that dependencies are built but not linted and the final crate is // linted but not built + args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-clippy""#.to_owned()]); + let mut ccc = ClippyCompilerCalls::new(env::args().any(|s| s == "-Zno-trans")); let (result, _) = rustc_driver::run_compiler(&args, &mut ccc, None, None); @@ -251,6 +258,8 @@ fn process(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32> args.push(String::from("--sysroot")); args.push(sysroot.to_owned()); args.push("-Zno-trans".to_owned()); + args.push("--cfg".to_owned()); + args.push(r#"feature="cargo-clippy""#.to_owned()); let path = std::env::current_exe().expect("current executable path invalid"); let exit_status = std::process::Command::new("cargo")