Skip to content
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

Add cargo dev lint to manually run clippy on a file #7917

Merged
merged 1 commit into from
Nov 7, 2021
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
1 change: 1 addition & 0 deletions clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::path::PathBuf;

pub mod bless;
pub mod fmt;
pub mod lint;
pub mod new_lint;
pub mod serve;
pub mod setup;
Expand Down
20 changes: 20 additions & 0 deletions clippy_dev/src/lint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::process::{self, Command};

pub fn run(filename: &str) {
let code = Command::new("cargo")
.args(["run", "--bin", "clippy-driver", "--"])
.args(["-L", "./target/debug"])
.args(["-Z", "no-codegen"])
.args(["--edition", "2021"])
.arg(filename)
.env("__CLIPPY_INTERNAL_TESTS", "true")
.status()
.expect("failed to run cargo")
.code();

if code.is_none() {
eprintln!("Killed by signal");
}

process::exit(code.unwrap_or(1));
}
15 changes: 14 additions & 1 deletion clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![warn(rust_2018_idioms, unused_lifetimes)]

use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
use clippy_dev::{bless, fmt, new_lint, serve, setup, update_lints};
use clippy_dev::{bless, fmt, lint, new_lint, serve, setup, update_lints};
fn main() {
let matches = get_clap_config();

Expand Down Expand Up @@ -55,6 +55,10 @@ fn main() {
let lint = matches.value_of("lint");
serve::run(port, lint);
},
("lint", Some(matches)) => {
let filename = matches.value_of("filename").unwrap();
lint::run(filename);
},
_ => {},
}
}
Expand Down Expand Up @@ -219,5 +223,14 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
)
.arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
)
.subcommand(
SubCommand::with_name("lint")
.about("Manually run clippy on a file")
.arg(
Arg::with_name("filename")
.required(true)
.help("The path to a file to lint"),
),
)
.get_matches()
}
2 changes: 1 addition & 1 deletion doc/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Manually testing against an example file can be useful if you have added some
your local modifications, run

```
env __CLIPPY_INTERNAL_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug input.rs
cargo dev lint input.rs
```

from the working copy root. With tests in place, let's have a look at
Expand Down