From f68629a5097122c65eea0d5239555f5396ff0863 Mon Sep 17 00:00:00 2001 From: Nadir Fejzic Date: Sun, 25 Jul 2021 14:41:35 +0200 Subject: [PATCH 1/3] Explain flags missing in cargo check in --help This commit closes #7389. As stated in the issue, `cargo clippy --help` provides explanation for some flags and states that the rest are same as in `cargo check --help`, even though some clippy specific flags exist. This commit extends the `cargo clippy --help` with two additional flags, - `cargo clippy --fix` - `cargo clippy --no-deps` If there are more flags which are not present in `cargo check --help` please bring these to my attention, I will include these aswell. For now, I noticed only the two flags mentioned above. --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index 6bd4123ddeb4..f79e70abc03b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,8 @@ Usage: cargo clippy [options] [--] [...] Common options: + --fix Automatically apply lint suggestions + --no-deps Run Clippy only on the given crate -h, --help Print this message -V, --version Print version info and exit From 0e5802ef5de2ea13811be3febab3ca005eb6404f Mon Sep 17 00:00:00 2001 From: Nadir Fejzic Date: Mon, 26 Jul 2021 16:14:29 +0200 Subject: [PATCH 2/3] Include more information in --help `--no-deps` filled in with a little more information. Explain that `--fix` implies `--no-deps`. Explain that `--no-deps` is used with `cargo clippy --`, including one example. --- src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index f79e70abc03b..8685c08cefed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,11 +14,13 @@ Usage: cargo clippy [options] [--] [...] Common options: - --fix Automatically apply lint suggestions - --no-deps Run Clippy only on the given crate + --no-deps Run Clippy only on the given crate, without linting the dependencies + --fix Automatically apply lint suggestions. This flag implies `--no-deps` -h, --help Print this message -V, --version Print version info and exit +Note: --no-deps flag is used with `cargo clippy --`. Example: `cargo clippy -- --no-deps` + Other options are the same as `cargo check`. To allow or deny a lint from the command line you can use `cargo clippy --` From f7af8bf2c1c361d7889f0edf398753bea97b8caa Mon Sep 17 00:00:00 2001 From: Nadir Fejzic Date: Tue, 27 Jul 2021 11:13:42 +0200 Subject: [PATCH 3/3] Handle `--no-deps` flag same as `--fix` flag. As proposed in the pull request thread, there is some inconsistency in handling the `--no-deps` flag which requires `--` before it, and `--fix` flag which does not. In this commit the `--no-deps` flag does not need the `--` anymore. However, it can still be used that way: `cargo clipyy -- --no-deps`. --- src/main.rs | 9 ++++++--- tests/dogfood.rs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8685c08cefed..7589f42a7b4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,8 +19,6 @@ Common options: -h, --help Print this message -V, --version Print version info and exit -Note: --no-deps flag is used with `cargo clippy --`. Example: `cargo clippy -- --no-deps` - Other options are the same as `cargo check`. To allow or deny a lint from the command line you can use `cargo clippy --` @@ -75,6 +73,7 @@ impl ClippyCmd { { let mut cargo_subcommand = "check"; let mut args = vec![]; + let mut clippy_args: Vec = vec![]; for arg in old_args.by_ref() { match arg.as_str() { @@ -82,6 +81,10 @@ impl ClippyCmd { cargo_subcommand = "fix"; continue; }, + "--no-deps" => { + clippy_args.push("--no-deps".into()); + continue; + }, "--" => break, _ => {}, } @@ -89,7 +92,7 @@ impl ClippyCmd { args.push(arg); } - let mut clippy_args: Vec = old_args.collect(); + clippy_args.append(&mut (old_args.collect())); if cargo_subcommand == "fix" && !clippy_args.iter().any(|arg| arg == "--no-deps") { clippy_args.push("--no-deps".into()); } diff --git a/tests/dogfood.rs b/tests/dogfood.rs index 7de130c7dbef..a996f9df144e 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -76,8 +76,8 @@ fn test_no_deps_ignores_path_deps_in_workspaces() { .env("CARGO_INCREMENTAL", "0") .arg("clippy") .args(&["-p", "subcrate"]) - .arg("--") .arg("--no-deps") + .arg("--") .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir .args(&["--cfg", r#"feature="primary_package_test""#]) .output()