Skip to content

Commit 635a4cd

Browse files
committed
Also look in home directory for global config.
1 parent 13db34f commit 635a4cd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Configurations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Configuring Rustfmt
22

3-
Rustfmt is designed to be very configurable. You can create a TOML file called `rustfmt.toml` or `.rustfmt.toml`, place it in the project or any other parent directory and it will apply the options in that file. If none of these directories contain such a file, your [global config directory](https://docs.rs/dirs/1.0.4/dirs/fn.config_dir.html) is checked for a folder called `rustfmt`, which may contain a `rustfmt.toml` (e.g. `~/.config/rustfmt/rustfmt.toml`).
3+
Rustfmt is designed to be very configurable. You can create a TOML file called `rustfmt.toml` or `.rustfmt.toml`, place it in the project or any other parent directory and it will apply the options in that file. If none of these directories contain such a file, both your home directory and a directory called `rustfmt` in your [global config directory](https://docs.rs/dirs/1.0.4/dirs/fn.config_dir.html) (e.g. `.config/rustfmt/`) are checked as well.
44

55
A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:
66

src/config/config_type.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,14 @@ macro_rules! create_config {
349349
}
350350
}
351351

352-
// If none was found, check in the global configuration directory.
352+
// If nothing was found, check in the home directory.
353+
if let Some(home_dir) = dirs::home_dir() {
354+
if let Some(path) = get_toml_path(&home_dir)? {
355+
return Ok(Some(path));
356+
}
357+
}
358+
359+
// If none was found ther either, check in the user's configuration directory.
353360
if let Some(mut config_dir) = dirs::config_dir() {
354361
config_dir.push("rustfmt");
355362
if let Some(path) = get_toml_path(&config_dir)? {

0 commit comments

Comments
 (0)