diff options
| author | bors <bors@rust-lang.org> | 2021-11-07 06:06:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-11-07 06:06:26 +0000 |
| commit | 07f4f7c2dd07fce07b0d6d3c95eb01ed80b47638 (patch) | |
| tree | f5e11dda2cd1f046d1bc7cd8102d44e8d8da6d53 | |
| parent | e3d1e60ed961c581092af4daa0442fc43b9c6068 (diff) | |
| parent | b5bae091849dc02b7aded5026cf1e2b5497db318 (diff) | |
| download | rust-07f4f7c2dd07fce07b0d6d3c95eb01ed80b47638.tar.gz rust-07f4f7c2dd07fce07b0d6d3c95eb01ed80b47638.zip | |
Auto merge of #7917 - Alexendoo:cargo-dev-lint, r=giraffate
Add `cargo dev lint` to manually run clippy on a file I found the manual run command really useful, this makes it a bit easier to type Not sure if this belongs in the changelog or not changelog: Add `cargo dev lint` to manually run clippy on a file
| -rw-r--r-- | clippy_dev/src/lib.rs | 1 | ||||
| -rw-r--r-- | clippy_dev/src/lint.rs | 20 | ||||
| -rw-r--r-- | clippy_dev/src/main.rs | 15 | ||||
| -rw-r--r-- | doc/adding_lints.md | 2 |
4 files changed, 36 insertions, 2 deletions
diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 5538f62c8e7..59fde447547 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -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; diff --git a/clippy_dev/src/lint.rs b/clippy_dev/src/lint.rs new file mode 100644 index 00000000000..dfd16f71054 --- /dev/null +++ b/clippy_dev/src/lint.rs @@ -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)); +} diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index b5c04efce3b..30a241c8ba1 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -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(); @@ -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); + }, _ => {}, } } @@ -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() } diff --git a/doc/adding_lints.md b/doc/adding_lints.md index ae2444f0171..26d06d334cd 100644 --- a/doc/adding_lints.md +++ b/doc/adding_lints.md @@ -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 |
