Skip to content

Pass through extra args in cargo dev lint #8793

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

Merged
merged 1 commit into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion clippy_dev/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn exit_if_err(status: io::Result<ExitStatus>) {
}
}

pub fn run(path: &str) {
pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a str>) {
let is_file = match fs::metadata(path) {
Ok(metadata) => metadata.is_file(),
Err(e) => {
Expand All @@ -30,6 +30,7 @@ pub fn run(path: &str) {
.args(["-Z", "no-codegen"])
.args(["--edition", "2021"])
.arg(path)
.args(args)
.status(),
);
} else {
Expand All @@ -42,6 +43,8 @@ pub fn run(path: &str) {
.expect("failed to create tempdir");

let status = Command::new(cargo_clippy_path())
.arg("clippy")
.args(args)
.current_dir(path)
.env("CARGO_TARGET_DIR", target.as_ref())
.status();
Expand Down
15 changes: 14 additions & 1 deletion clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ fn main() {
},
("lint", Some(matches)) => {
let path = matches.value_of("path").unwrap();
lint::run(path);
let args = matches.values_of("args").into_iter().flatten();
lint::run(path, args);
},
("rename_lint", Some(matches)) => {
let old_name = matches.value_of("old_name").unwrap();
Expand Down Expand Up @@ -278,11 +279,23 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
Lint a package directory:
cargo dev lint tests/ui-cargo/wildcard_dependencies/fail
cargo dev lint ~/my-project

Run rustfix:
cargo dev lint ~/my-project -- --fix

Set lint levels:
cargo dev lint file.rs -- -W clippy::pedantic
cargo dev lint ~/my-project -- -- -W clippy::pedantic
"})
.arg(
Arg::with_name("path")
.required(true)
.help("The path to a file or package directory to lint"),
)
.arg(
Arg::with_name("args")
.multiple(true)
.help("Pass extra arguments to cargo/clippy-driver"),
),
)
.subcommand(
Expand Down