diff --git a/docs/reference.md b/docs/reference.md index 16b0c19..3054ba8 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -8,7 +8,7 @@ Configuration is read from the following (in precedence order) - Command line arguments - File specified via `--config PATH` -- Search parents of specified file / directory for `typos.toml` +- Search parents of specified file / directory for one of `typos.toml`, `_typos.toml`, or `.typos.toml` ### Config Fields diff --git a/src/config.rs b/src/config.rs index 60c3671..7462126 100644 --- a/src/config.rs +++ b/src/config.rs @@ -131,7 +131,7 @@ impl Config { } pub fn derive(cwd: &std::path::Path) -> Result { - if let Some(path) = find_project_file(cwd.to_owned(), "typos.toml") { + if let Some(path) = find_project_file(cwd, &["typos.toml", "_typos.toml", ".typos.toml"]) { Self::from_file(&path) } else { Ok(Default::default()) @@ -435,18 +435,17 @@ impl FileSource for FileConfig { } } -fn find_project_file(dir: std::path::PathBuf, name: &str) -> Option { - let mut file_path = dir; - file_path.push(name); - while !file_path.exists() { - file_path.pop(); // filename - let hit_bottom = !file_path.pop(); - if hit_bottom { - return None; +fn find_project_file(dir: &std::path::Path, names: &[&str]) -> Option { + for ancestor in dir.ancestors() { + let mut file_path = ancestor.join("placeholder"); + for name in names { + file_path.set_file_name(name); + if file_path.exists() { + return Some(file_path); + } } - file_path.push(name); } - Some(file_path) + None } #[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize)]