Skip to content

Commit

Permalink
Look for a global rustfmt.toml.
Browse files Browse the repository at this point in the history
If no rustfmt.toml is found in the usual way, the directory 'rustfmt' in
the user's config directory is checked.

 - $XDG_CONFIG_HOME/rustfmt/ (or $HOME/.config/rustfmt/), or
 - $HOME/Library/Preferences/rustfmt/ on Mac, or
 - %AppData%\rustfmt\ on Windows.
  • Loading branch information
m-ou-se committed Jan 27, 2019
1 parent 203e6d2 commit 24daa17
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
56 changes: 56 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ failure = "0.1.3"
bytecount = "0.5"
unicode-width = "0.1.5"
unicode_categories = "0.1.1"
dirs = "1.0.4"

# A noop dependency that changes in the Rust repository, it's a bit of a hack.
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
Expand Down
12 changes: 11 additions & 1 deletion src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,19 @@ macro_rules! create_config {

// If the current directory has no parent, we're done searching.
if !current.pop() {
return Ok(None);
break;
}
}

// If none was found, check in the global configuration directory.
if let Some(mut config_dir) = dirs::config_dir() {
config_dir.push("rustfmt");
if let Some(path) = get_toml_path(&config_dir)? {
return Ok(Some(path));
}
}

return Ok(None);
}

match resolve_project_file(dir)? {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern crate derive_new;
extern crate atty;
extern crate bytecount;
extern crate diff;
extern crate dirs;
extern crate failure;
extern crate itertools;
#[cfg(test)]
Expand Down

0 comments on commit 24daa17

Please sign in to comment.