Skip to content

Commit 43756b6

Browse files
committed
Auto merge of rust-lang#8793 - Alexendoo:dev-lint-extra-args, r=xFrednet
Pass through extra args in `cargo dev lint` changelog: Pass through extra args in `cargo dev lint` Lets you pass some useful flags through, like `-A/W/etc`, `--fix`, `--force-warn`
2 parents 1594e98 + 905a951 commit 43756b6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

clippy_dev/src/lint.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn exit_if_err(status: io::Result<ExitStatus>) {
1313
}
1414
}
1515

16-
pub fn run(path: &str) {
16+
pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a str>) {
1717
let is_file = match fs::metadata(path) {
1818
Ok(metadata) => metadata.is_file(),
1919
Err(e) => {
@@ -30,6 +30,7 @@ pub fn run(path: &str) {
3030
.args(["-Z", "no-codegen"])
3131
.args(["--edition", "2021"])
3232
.arg(path)
33+
.args(args)
3334
.status(),
3435
);
3536
} else {
@@ -42,6 +43,8 @@ pub fn run(path: &str) {
4243
.expect("failed to create tempdir");
4344

4445
let status = Command::new(cargo_clippy_path())
46+
.arg("clippy")
47+
.args(args)
4548
.current_dir(path)
4649
.env("CARGO_TARGET_DIR", target.as_ref())
4750
.status();

clippy_dev/src/main.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ fn main() {
7676
},
7777
("lint", Some(matches)) => {
7878
let path = matches.value_of("path").unwrap();
79-
lint::run(path);
79+
let args = matches.values_of("args").into_iter().flatten();
80+
lint::run(path, args);
8081
},
8182
("rename_lint", Some(matches)) => {
8283
let old_name = matches.value_of("old_name").unwrap();
@@ -278,11 +279,23 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
278279
Lint a package directory:
279280
cargo dev lint tests/ui-cargo/wildcard_dependencies/fail
280281
cargo dev lint ~/my-project
282+
283+
Run rustfix:
284+
cargo dev lint ~/my-project -- --fix
285+
286+
Set lint levels:
287+
cargo dev lint file.rs -- -W clippy::pedantic
288+
cargo dev lint ~/my-project -- -- -W clippy::pedantic
281289
"})
282290
.arg(
283291
Arg::with_name("path")
284292
.required(true)
285293
.help("The path to a file or package directory to lint"),
294+
)
295+
.arg(
296+
Arg::with_name("args")
297+
.multiple(true)
298+
.help("Pass extra arguments to cargo/clippy-driver"),
286299
),
287300
)
288301
.subcommand(

0 commit comments

Comments
 (0)