forked from rust-lang/rustfmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge configs from parent directories
Currently, `rustfmt` stops building its configuration after one configuration file is found. However, users may expect that `rustfmt` includes configuration options inhereted by configuration files in parent directories of the directory `rustfmt` is run in. The motivation for this commit is for a use case involving files that should be ignored by `rustfmt`. Consider the directory structure ``` a |-- rustfmt.toml |-- b |-- rustfmt.toml |-- main.rs ``` Suppose `a/rustfmt.toml` has the option `ignore = ["b/main.rs"]`. A user may expect that running `rusfmt` in either directory `a/` or `b/` will ignore `main.rs`. Today, though, if `rustfmt` is run in `b/`, `main.rs` will be formatted because only `b/rustfmt.toml` will be used for configuration. Although motivated by the use case for ignored files, this change sets up `rustfmt` to incrementally populate all configuration options from parent config files. The priority of population is closest config file to most transient config file. To avoid churn of the existing implementation for ignoring files, populating the ignored files config option with multiple config files is done by computing a join. Given config files "outer" and "inner", where "inner" is of higher priority (nested in the directory of) "outer", we merge their `ignore` configurations by finding the ignore files specified in "outer" that are present in the "inner" directory, and appending this to the files ignored by "inner". This means that printing an `ignore` configuration may not be entirely accurate, as it could be missing files that are not in the current directory specified by transient configurations. These files are out of the scope the `rustfmt` instance's operation, though, so for practical purposes I don't think this matters. Closes rust-lang#3881
- Loading branch information
Showing
4 changed files
with
233 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.