Skip to content

Commit 07f4f7c

Browse files
committed
Auto merge of rust-lang#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
2 parents e3d1e60 + b5bae09 commit 07f4f7c

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

clippy_dev/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::path::PathBuf;
77

88
pub mod bless;
99
pub mod fmt;
10+
pub mod lint;
1011
pub mod new_lint;
1112
pub mod serve;
1213
pub mod setup;

clippy_dev/src/lint.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::process::{self, Command};
2+
3+
pub fn run(filename: &str) {
4+
let code = Command::new("cargo")
5+
.args(["run", "--bin", "clippy-driver", "--"])
6+
.args(["-L", "./target/debug"])
7+
.args(["-Z", "no-codegen"])
8+
.args(["--edition", "2021"])
9+
.arg(filename)
10+
.env("__CLIPPY_INTERNAL_TESTS", "true")
11+
.status()
12+
.expect("failed to run cargo")
13+
.code();
14+
15+
if code.is_none() {
16+
eprintln!("Killed by signal");
17+
}
18+
19+
process::exit(code.unwrap_or(1));
20+
}

clippy_dev/src/main.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![warn(rust_2018_idioms, unused_lifetimes)]
44

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

@@ -55,6 +55,10 @@ fn main() {
5555
let lint = matches.value_of("lint");
5656
serve::run(port, lint);
5757
},
58+
("lint", Some(matches)) => {
59+
let filename = matches.value_of("filename").unwrap();
60+
lint::run(filename);
61+
},
5862
_ => {},
5963
}
6064
}
@@ -219,5 +223,14 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
219223
)
220224
.arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
221225
)
226+
.subcommand(
227+
SubCommand::with_name("lint")
228+
.about("Manually run clippy on a file")
229+
.arg(
230+
Arg::with_name("filename")
231+
.required(true)
232+
.help("The path to a file to lint"),
233+
),
234+
)
222235
.get_matches()
223236
}

doc/adding_lints.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Manually testing against an example file can be useful if you have added some
157157
your local modifications, run
158158

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

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

0 commit comments

Comments
 (0)