about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-01-20 23:00:50 +0100
committerMatthias Krüger <matthias.krueger@famsik.de>2022-01-31 18:36:15 +0100
commit97e5a70f472db51ea319367b5b424a55a77a2187 (patch)
tree1a6cbe1df9ece2eba06b67142f934dd8cf9c381d
parent7bb69c0ae024eef65acb7fd6551fdd99f1563d38 (diff)
downloadrust-97e5a70f472db51ea319367b5b424a55a77a2187.tar.gz
rust-97e5a70f472db51ea319367b5b424a55a77a2187.zip
warn if we find multiple clippy configs
Fixes #8323
-rw-r--r--clippy_lints/src/utils/conf.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs
index c9d99617c1e..36a7e67af6f 100644
--- a/clippy_lints/src/utils/conf.rs
+++ b/clippy_lints/src/utils/conf.rs
@@ -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
+                        if let Some(ref found_config_) = found_config {
+                            eprintln!(
+                                "Warning: found two config files: {} and {}.\nUsing the first one!",
+                                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);