mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-18 19:43:43 +00:00
Make --fix imply --no-deps
This commit is contained in:
parent
7eda421e96
commit
a83eb7ca99
32
src/main.rs
32
src/main.rs
@ -62,7 +62,7 @@ struct ClippyCmd {
|
|||||||
unstable_options: bool,
|
unstable_options: bool,
|
||||||
cargo_subcommand: &'static str,
|
cargo_subcommand: &'static str,
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
clippy_args: String,
|
clippy_args: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClippyCmd {
|
impl ClippyCmd {
|
||||||
@ -99,7 +99,10 @@ impl ClippyCmd {
|
|||||||
args.insert(0, "+nightly".to_string());
|
args.insert(0, "+nightly".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
let clippy_args: String = old_args.map(|arg| format!("{}__CLIPPY_HACKERY__", arg)).collect();
|
let mut clippy_args: Vec<String> = old_args.collect();
|
||||||
|
if cargo_subcommand == "fix" && !clippy_args.iter().any(|arg| arg == "--no-deps") {
|
||||||
|
clippy_args.push("--no-deps".into());
|
||||||
|
}
|
||||||
|
|
||||||
ClippyCmd {
|
ClippyCmd {
|
||||||
unstable_options,
|
unstable_options,
|
||||||
@ -147,10 +150,15 @@ impl ClippyCmd {
|
|||||||
|
|
||||||
fn into_std_cmd(self) -> Command {
|
fn into_std_cmd(self) -> Command {
|
||||||
let mut cmd = Command::new("cargo");
|
let mut cmd = Command::new("cargo");
|
||||||
|
let clippy_args: String = self
|
||||||
|
.clippy_args
|
||||||
|
.iter()
|
||||||
|
.map(|arg| format!("{}__CLIPPY_HACKERY__", arg))
|
||||||
|
.collect();
|
||||||
|
|
||||||
cmd.env(self.path_env(), Self::path())
|
cmd.env(self.path_env(), Self::path())
|
||||||
.envs(ClippyCmd::target_dir())
|
.envs(ClippyCmd::target_dir())
|
||||||
.env("CLIPPY_ARGS", self.clippy_args)
|
.env("CLIPPY_ARGS", clippy_args)
|
||||||
.arg(self.cargo_subcommand)
|
.arg(self.cargo_subcommand)
|
||||||
.args(&self.args);
|
.args(&self.args);
|
||||||
|
|
||||||
@ -201,6 +209,24 @@ mod tests {
|
|||||||
assert!(cmd.args.iter().any(|arg| arg.ends_with("unstable-options")));
|
assert!(cmd.args.iter().any(|arg| arg.ends_with("unstable-options")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fix_implies_no_deps() {
|
||||||
|
let args = "cargo clippy --fix -Zunstable-options"
|
||||||
|
.split_whitespace()
|
||||||
|
.map(ToString::to_string);
|
||||||
|
let cmd = ClippyCmd::new(args);
|
||||||
|
assert!(cmd.clippy_args.iter().any(|arg| arg == "--no-deps"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_deps_not_duplicated_with_fix() {
|
||||||
|
let args = "cargo clippy --fix -Zunstable-options -- --no-deps"
|
||||||
|
.split_whitespace()
|
||||||
|
.map(ToString::to_string);
|
||||||
|
let cmd = ClippyCmd::new(args);
|
||||||
|
assert_eq!(cmd.clippy_args.iter().filter(|arg| *arg == "--no-deps").count(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check() {
|
fn check() {
|
||||||
let args = "cargo clippy".split_whitespace().map(ToString::to_string);
|
let args = "cargo clippy".split_whitespace().map(ToString::to_string);
|
||||||
|
Loading…
Reference in New Issue
Block a user