Skip to content

Commit

Permalink
warn if we find multiple clippy configs
Browse files Browse the repository at this point in the history
Fixes #8323
  • Loading branch information
matthiaskrgr committed Jan 31, 2022
1 parent 7bb69c0 commit 97e5a70
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion clippy_lints/src/utils/conf.rs
Expand Up @@ -322,18 +322,36 @@ 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() {
match fs::metadata(&config_file) {
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);
Expand Down

0 comments on commit 97e5a70

Please sign in to comment.