Multiple config file names feature (#1101)
* Add multiple configuration file names feature * Add '.rustfmt.toml' in README file * Clean up configuration file code * Make config file names constant * Use only one blank line
This commit is contained in:
parent
e76cb6a907
commit
6380937b59
12
README.md
12
README.md
|
@ -124,9 +124,10 @@ notes above on running rustfmt.
|
|||
## Configuring Rustfmt
|
||||
|
||||
Rustfmt is designed to be very configurable. You can create a TOML file called
|
||||
rustfmt.toml, place it in the project directory and it will apply the options
|
||||
in that file. See `rustfmt --config-help` for the options which are available,
|
||||
or if you prefer to see source code, [src/config.rs](src/config.rs).
|
||||
`rustfmt.toml` or `.rustfmt.toml`, place it in the project or any other parent
|
||||
directory and it will apply the options in that file. See `rustfmt
|
||||
--config-help` for the options which are available, or if you prefer to see
|
||||
source code, [src/config.rs](src/config.rs).
|
||||
|
||||
By default, Rustfmt uses a style which (mostly) conforms to the
|
||||
[Rust style guidelines](https://github.com/rust-lang/rust/tree/master/src/doc/style).
|
||||
|
@ -148,8 +149,9 @@ options covering different styles. File an issue, or even better, submit a PR.
|
|||
#[rustfmt_skip] // requires nightly and #![feature(custom_attribute)] in crate root
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)] // works in stable
|
||||
```
|
||||
* When you run rustfmt, place a file named rustfmt.toml in target file
|
||||
directory or its parents to override the default settings of rustfmt.
|
||||
* When you run rustfmt, place a file named `rustfmt.toml` or `.rustfmt.toml` in
|
||||
target file directory or its parents to override the default settings of
|
||||
rustfmt.
|
||||
* After successful compilation, a `rustfmt` executable can be found in the
|
||||
target directory.
|
||||
* If you're having issues compiling Rustfmt (or compile errors when trying to
|
||||
|
|
|
@ -109,20 +109,24 @@ fn lookup_project_file(dir: &Path) -> FmtResult<Option<PathBuf>> {
|
|||
|
||||
current = try!(fs::canonicalize(current));
|
||||
|
||||
const CONFIG_FILE_NAMES: [&'static str; 2] = [".rustfmt.toml", "rustfmt.toml"];
|
||||
|
||||
loop {
|
||||
let config_file = current.join("rustfmt.toml");
|
||||
match fs::metadata(&config_file) {
|
||||
// Only return if it's a file to handle the unlikely situation of a directory named
|
||||
// `rustfmt.toml`.
|
||||
Ok(ref md) if md.is_file() => return Ok(Some(config_file)),
|
||||
// Return the error if it's something other than `NotFound`; otherwise we didn't find
|
||||
// the project file yet, and continue searching.
|
||||
Err(e) => {
|
||||
if e.kind() != ErrorKind::NotFound {
|
||||
return Err(FmtError::from(e));
|
||||
for config_file_name in &CONFIG_FILE_NAMES {
|
||||
let config_file = current.join(config_file_name);
|
||||
match fs::metadata(&config_file) {
|
||||
// Only return if it's a file to handle the unlikely situation of a directory named
|
||||
// `rustfmt.toml`.
|
||||
Ok(ref md) if md.is_file() => return Ok(Some(config_file)),
|
||||
// Return the error if it's something other than `NotFound`; otherwise we didn't
|
||||
// find the project file yet, and continue searching.
|
||||
Err(e) => {
|
||||
if e.kind() != ErrorKind::NotFound {
|
||||
return Err(FmtError::from(e));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// If the current directory has no parent, we're done searching.
|
||||
|
|
Loading…
Reference in a new issue