Skip to content

Commit

Permalink
Fix config file lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
camsteffen committed May 27, 2021
1 parent 3af9584 commit 6eea598
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
11 changes: 0 additions & 11 deletions clippy_lints/src/lib.rs
Expand Up @@ -405,7 +405,6 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore) {

#[doc(hidden)]
pub fn read_conf(sess: &Session) -> Conf {
use std::path::Path;
let file_name = match utils::conf::lookup_conf_file() {
Ok(Some(path)) => path,
Ok(None) => return Conf::default(),
Expand All @@ -416,16 +415,6 @@ pub fn read_conf(sess: &Session) -> Conf {
},
};

let file_name = if file_name.is_relative() {
sess.local_crate_source_file
.as_deref()
.and_then(Path::parent)
.unwrap_or_else(|| Path::new(""))
.join(file_name)
} else {
file_name
};

let TryConf { conf, errors } = utils::conf::read(&file_name);
// all conf errors are non-fatal, we just use the default conf in case of error
for error in errors {
Expand Down
16 changes: 7 additions & 9 deletions clippy_lints/src/utils/conf.rs
Expand Up @@ -210,15 +210,13 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
.map_or_else(|| PathBuf::from("."), PathBuf::from);
loop {
for config_file_name in &CONFIG_FILE_NAMES {
let config_file = current.join(config_file_name);
match fs::metadata(&config_file) {
// Only return if it's a file to handle the unlikely situation of a directory named
// `clippy.toml`.
Ok(ref md) if !md.is_dir() => return Ok(Some(config_file)),
// Return the error if it's something other than `NotFound`; otherwise we didn't
// find the project file yet, and continue searching.
Err(e) if e.kind() != io::ErrorKind::NotFound => return Err(e),
_ => {},
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)),
}
}
}

Expand Down

0 comments on commit 6eea598

Please sign in to comment.