Add unstable .editorconfig support - #7130
Open
kleinesfilmroellchen wants to merge 2 commits into
Open
kleinesfilmroellchen wants to merge 2 commits into
kleinesfilmroellchen wants to merge 2 commits into
Conversation
kleinesfilmroellchen
force-pushed
the
editorconfig
branch
2 times, most recently
from
September 21, 2026 13:58
c7b4cb5 to
15d5530
Compare
A new unstable option `--use-editorconfig` allows rustfmt to respect .editorconfig, which configures several basic (all stable) options of rustfmt. For the user, .editorconfig obviates the need for rustfmt.toml in most basic use cases, and allows IDEs (most of which respect .editorconfig) and LSPs (most of which use rustfmt to format code interactively) to better work together for Rust code formatting. In terms of implementation, this code mainly affects `load_config`, the central entry point for configuration discovery. This function’s argument previously always received a folder from which to search for rustfmt.toml (despite confusingly being named "file_path"). Now, this argument may alternatively receive a file path directly, as most users now do, wherever practical. In this case, and if the options allow this behavior, .editorconfig is loaded and respected, overall almost identically to rustfmt.toml. This adds a dependency to ec4rs, the best .editorconfig implementation in Rust, which passes the editorconfig specification test suite and overall behaves exactly as expected. These changes have approximately 95% test coverage, including almost every practically possible error case and all possible .editorconfig configurations and their effects. This option does not affect rustfmt’s stable behavior in any way. The current rustfmt maintainer stance is that .editorconfig should never be respected by default, so this will likely remain the case after stabilization. The commits after this one will adjust documentation and add pass-through support for cargo-fmt.
kleinesfilmroellchen
force-pushed
the
editorconfig
branch
from
September 21, 2026 14:10
15d5530 to
0dcb25e
Compare
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds unstable support for configuring rustfmt via .editorconfig.
Background and context
Detailed design and featureset
See also the zulip thread above, which gives a more detailed rationale as to why which option is supported in what way.
See the commit descriptions for implementation notes.
The following is copied from CHANGELOG.md:
rustfmt now has unstable support for .editorconfig, enabled with
--unstable-features --use-editorconfig.The following
.editorconfigoptions are respected when applied to Rust source files:Note that only the configuration for the entry point (e.g.
main.rs,lib.rs, or integration tests) is respected, but not for child modules.Use a
[*.rs]section in your .editorconfig to avoid surprises.There is no dedicated support in
cargo-fmt; usecargo fmt -- --unstable-features --use-editorconfigto pass the option through to rustfmt.Open questions
Since this is my first r-l and rustfmt contribution (but by far not my first time writing Rust code), I’m not confident about the following points:
Misc
The test cases in this PR cover about 95% of the functionality introduced, according to llvm-cov (which is a better ratio than the rest of rustfmt :3), including every error case I could spot. Let me know if I missed anything.
This PR is not intended for squash-merging, and will be rebased/amended to address code review.
Footnotes
No slopmachine output has ever, or will ever, be used by me to author any software, including any communication on this PR. 100% cat-made software, meow >.< :3 ↩