diff options
| author | Philipp Krones <hello@philkrones.com> | 2022-07-18 09:39:37 +0200 |
|---|---|---|
| committer | Philipp Krones <hello@philkrones.com> | 2022-07-18 09:39:37 +0200 |
| commit | 7d4daaa8fa71337fc78b1b7799d048d51a3b3fcd (patch) | |
| tree | bff228b4e1035020349d3d974500c5137b72161e /clippy_dev/src | |
| parent | f88a1399bb89f9c4f95fb4a1e6d9b5ab05f35201 (diff) | |
| download | rust-7d4daaa8fa71337fc78b1b7799d048d51a3b3fcd.tar.gz rust-7d4daaa8fa71337fc78b1b7799d048d51a3b3fcd.zip | |
Merge commit 'fdb84cbfd25908df5683f8f62388f663d9260e39' into clippyup
Diffstat (limited to 'clippy_dev/src')
| -rw-r--r-- | clippy_dev/src/dogfood.rs | 33 | ||||
| -rw-r--r-- | clippy_dev/src/lib.rs | 1 | ||||
| -rw-r--r-- | clippy_dev/src/main.rs | 20 | ||||
| -rw-r--r-- | clippy_dev/src/update_lints.rs | 2 |
4 files changed, 54 insertions, 2 deletions
diff --git a/clippy_dev/src/dogfood.rs b/clippy_dev/src/dogfood.rs new file mode 100644 index 00000000000..b69e9f649ec --- /dev/null +++ b/clippy_dev/src/dogfood.rs @@ -0,0 +1,33 @@ +use crate::clippy_project_root; +use std::process::Command; + +/// # Panics +/// +/// Panics if unable to run the dogfood test +pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) { + let mut cmd = Command::new("cargo"); + + cmd.current_dir(clippy_project_root()) + .args(["test", "--test", "dogfood"]) + .args(["--features", "internal"]) + .args(["--", "dogfood_clippy"]); + + let mut dogfood_args = Vec::new(); + if fix { + dogfood_args.push("--fix"); + } + + if allow_dirty { + dogfood_args.push("--allow-dirty"); + } + + if allow_staged { + dogfood_args.push("--allow-staged"); + } + + cmd.env("__CLIPPY_DOGFOOD_ARGS", dogfood_args.join(" ")); + + let output = cmd.output().expect("failed to run command"); + + println!("{}", String::from_utf8_lossy(&output.stdout)); +} diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index fe69284ab10..8536e242992 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -11,6 +11,7 @@ extern crate rustc_lexer; use std::path::PathBuf; pub mod bless; +pub mod dogfood; pub mod fmt; pub mod lint; pub mod new_lint; diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 243a901503f..a29ba2d0c85 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::{Arg, ArgAction, ArgMatches, Command, PossibleValue}; -use clippy_dev::{bless, fmt, lint, new_lint, serve, setup, update_lints}; +use clippy_dev::{bless, dogfood, fmt, lint, new_lint, serve, setup, update_lints}; use indoc::indoc; fn main() { @@ -13,6 +13,13 @@ fn main() { Some(("bless", matches)) => { bless::bless(matches.contains_id("ignore-timestamp")); }, + Some(("dogfood", matches)) => { + dogfood::dogfood( + matches.contains_id("fix"), + matches.contains_id("allow-dirty"), + matches.contains_id("allow-staged"), + ); + }, Some(("fmt", matches)) => { fmt::run(matches.contains_id("check"), matches.contains_id("verbose")); }, @@ -104,6 +111,17 @@ fn get_clap_config() -> ArgMatches { .long("ignore-timestamp") .help("Include files updated before clippy was built"), ), + Command::new("dogfood").about("Runs the dogfood test").args([ + Arg::new("fix").long("fix").help("Apply the suggestions when possible"), + Arg::new("allow-dirty") + .long("allow-dirty") + .help("Fix code even if the working directory has changes") + .requires("fix"), + Arg::new("allow-staged") + .long("allow-staged") + .help("Fix code even if the working directory has staged changes") + .requires("fix"), + ]), Command::new("fmt") .about("Run rustfmt on all projects and tests") .args([ diff --git a/clippy_dev/src/update_lints.rs b/clippy_dev/src/update_lints.rs index 2e0659f42d7..c089f4d8ce4 100644 --- a/clippy_dev/src/update_lints.rs +++ b/clippy_dev/src/update_lints.rs @@ -553,7 +553,7 @@ fn replace_ident_like(contents: &str, replacements: &[(&str, &str)]) -> Option<S pos = m.end(); } result.push_str(&contents[pos..]); - edited.then(|| result) + edited.then_some(result) } fn round_to_fifty(count: usize) -> usize { |
