Add support for .treefmt.toml (#172)

This commit is contained in:
Loïc Reynier 2022-07-04 12:20:01 +02:00 committed by GitHub
parent 676731f566
commit ac9fbe6bf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,8 @@ use std::{collections::BTreeMap, path::Path};
/// Name of the config file
pub const FILENAME: &str = "treefmt.toml";
/// Alternative name of the config file
pub const FILENAMEALT: &str = ".treefmt.toml";
/// treefmt.toml structure
#[derive(Debug, Deserialize)]
@ -55,8 +57,11 @@ pub fn lookup(dir: &Path) -> Option<PathBuf> {
let mut cwd = dir.to_path_buf();
loop {
let config_file = cwd.join(FILENAME);
let config_file_alt = cwd.join(FILENAMEALT);
if config_file.exists() {
return Some(config_file);
} else if config_file_alt.exists() {
return Some(config_file_alt);
}
cwd = match cwd.parent() {
Some(x) => x.to_path_buf(),