Auto merge of #8326 - matthiaskrgr:warn_on_multi_configs, r=xFrednet

warn if we find multiple clippy configs

Fixes #8323

---

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: warn if we find multiple clippy configs
This commit is contained in:
bors 2022-02-06 17:19:11 +00:00
commit 8dc719cb39
9 changed files with 48 additions and 1 deletions

View File

@ -322,6 +322,9 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
let mut current = env::var_os("CLIPPY_CONF_DIR")
.or_else(|| env::var_os("CARGO_MANIFEST_DIR"))
.map_or_else(|| PathBuf::from("."), PathBuf::from);
let mut found_config: Option<PathBuf> = None;
loop {
for config_file_name in &CONFIG_FILE_NAMES {
if let Ok(config_file) = current.join(config_file_name).canonicalize() {
@ -329,11 +332,26 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
Err(e) if e.kind() == io::ErrorKind::NotFound => {},
Err(e) => return Err(e),
Ok(md) if md.is_dir() => {},
Ok(_) => return Ok(Some(config_file)),
Ok(_) => {
// warn if we happen to find two config files #8323
if let Some(ref found_config_) = found_config {
eprintln!(
"Using config file `{}`\nWarning: `{}` will be ignored.",
found_config_.display(),
config_file.display(),
);
} else {
found_config = Some(config_file);
}
},
}
}
}
if found_config.is_some() {
return Ok(found_config);
}
// If the current directory has no parent, we're done searching.
if !current.pop() {
return Ok(None);

View File

@ -0,0 +1,8 @@
[package]
name = "no_warn"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1 @@
avoid-breaking-exported-api = false

View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

View File

@ -0,0 +1 @@
avoid-breaking-exported-api = false

View File

@ -0,0 +1,8 @@
[package]
name = "warn"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1 @@
avoid-breaking-exported-api = false

View File

@ -0,0 +1,5 @@
// ignore-windows
fn main() {
println!("Hello, world!");
}

View File

@ -0,0 +1,2 @@
Using config file `$SRC_DIR/tests/ui-cargo/multiple_config_files/warn/.clippy.toml`
Warning: `$SRC_DIR/tests/ui-cargo/multiple_config_files/warn/clippy.toml` will be ignored.