about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2019-01-07 20:38:56 +0100
committerMara Bos <m-ou.se@m-ou.se>2019-01-27 13:22:25 +0100
commit24daa174ca9a7bfcaec6189af2830b9449801b63 (patch)
tree21d5c745e45c878560a169c1e4c5f7d7217e76f1 /src
parent203e6d265d88bee97f89bb0529f3a33cb46e0477 (diff)
Look for a global rustfmt.toml.
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.
Diffstat (limited to 'src')
-rw-r--r--src/config/config_type.rs12
-rw-r--r--src/lib.rs1
2 files changed, 12 insertions, 1 deletions
diff --git a/src/config/config_type.rs b/src/config/config_type.rs
index b7c1da36017..665afded9da 100644
--- a/src/config/config_type.rs
+++ b/src/config/config_type.rs
@@ -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)? {
diff --git a/src/lib.rs b/src/lib.rs
index ce28fce3182..a6e531e476b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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)]