Skip to content

Commit 8dc719c

Browse files
committed
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
2 parents 093e320 + aae64e9 commit 8dc719c

File tree

9 files changed

+48
-1
lines changed

9 files changed

+48
-1
lines changed

clippy_lints/src/utils/conf.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,36 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
322322
let mut current = env::var_os("CLIPPY_CONF_DIR")
323323
.or_else(|| env::var_os("CARGO_MANIFEST_DIR"))
324324
.map_or_else(|| PathBuf::from("."), PathBuf::from);
325+
326+
let mut found_config: Option<PathBuf> = None;
327+
325328
loop {
326329
for config_file_name in &CONFIG_FILE_NAMES {
327330
if let Ok(config_file) = current.join(config_file_name).canonicalize() {
328331
match fs::metadata(&config_file) {
329332
Err(e) if e.kind() == io::ErrorKind::NotFound => {},
330333
Err(e) => return Err(e),
331334
Ok(md) if md.is_dir() => {},
332-
Ok(_) => return Ok(Some(config_file)),
335+
Ok(_) => {
336+
// warn if we happen to find two config files #8323
337+
if let Some(ref found_config_) = found_config {
338+
eprintln!(
339+
"Using config file `{}`\nWarning: `{}` will be ignored.",
340+
found_config_.display(),
341+
config_file.display(),
342+
);
343+
} else {
344+
found_config = Some(config_file);
345+
}
346+
},
333347
}
334348
}
335349
}
336350

351+
if found_config.is_some() {
352+
return Ok(found_config);
353+
}
354+
337355
// If the current directory has no parent, we're done searching.
338356
if !current.pop() {
339357
return Ok(None);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "no_warn"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
avoid-breaking-exported-api = false
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
avoid-breaking-exported-api = false
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "warn"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
avoid-breaking-exported-api = false
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// ignore-windows
2+
3+
fn main() {
4+
println!("Hello, world!");
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Using config file `$SRC_DIR/tests/ui-cargo/multiple_config_files/warn/.clippy.toml`
2+
Warning: `$SRC_DIR/tests/ui-cargo/multiple_config_files/warn/clippy.toml` will be ignored.

0 commit comments

Comments
 (0)