mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-14 15:22:41 +00:00
clippy dev fmt: don't format if we have a local rustc repo enabled as path dependency via cargo dev ra-setup.
rustfmt would try to format the entire rustc repo, probably because it sees it as a local dependency.
This commit is contained in:
parent
404c50f562
commit
91fa25c9de
1 changed files with 20 additions and 1 deletions
|
@ -1,9 +1,9 @@
|
|||
use crate::clippy_project_root;
|
||||
use shell_escape::escape;
|
||||
use std::ffi::OsStr;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::process::{self, Command};
|
||||
use std::{fs, io};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -12,6 +12,7 @@ pub enum CliError {
|
|||
IoError(io::Error),
|
||||
RustfmtNotInstalled,
|
||||
WalkDirError(walkdir::Error),
|
||||
RaSetupActive,
|
||||
}
|
||||
|
||||
impl From<io::Error> for CliError {
|
||||
|
@ -31,12 +32,23 @@ struct FmtContext {
|
|||
verbose: bool,
|
||||
}
|
||||
|
||||
// the "main" function of cargo dev fmt
|
||||
pub fn run(check: bool, verbose: bool) {
|
||||
fn try_run(context: &FmtContext) -> Result<bool, CliError> {
|
||||
let mut success = true;
|
||||
|
||||
let project_root = clippy_project_root();
|
||||
|
||||
// if we added a local rustc repo as path dependency to clippy for rust analyzer, we do NOT want to
|
||||
// format because rustfmt would also format the entire rustc repo as it is a local
|
||||
// dependency
|
||||
if fs::read_to_string(project_root.join("Cargo.toml"))
|
||||
.expect("Failed to read clippy Cargo.toml")
|
||||
.contains(&"[target.'cfg(NOT_A_PLATFORM)'.dependencies]")
|
||||
{
|
||||
return Err(CliError::RaSetupActive);
|
||||
}
|
||||
|
||||
rustfmt_test(context)?;
|
||||
|
||||
success &= cargo_fmt(context, project_root.as_path())?;
|
||||
|
@ -75,6 +87,13 @@ pub fn run(check: bool, verbose: bool) {
|
|||
CliError::WalkDirError(err) => {
|
||||
eprintln!("error: {}", err);
|
||||
},
|
||||
CliError::RaSetupActive => {
|
||||
eprintln!(
|
||||
"error: a local rustc repo is enabled as path dependency via `cargo dev ra-setup`.
|
||||
Not formatting because that would format the local repo as well!
|
||||
Please revert the changes to Cargo.tomls first."
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue