rust-lang / rust-lang/rustfmt

Allow local overrides of rustfmt configuration

Open
#4,843 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

rustfmt configuration makes it wonderfully flexible, however, the configuration must be the same for the whole project. The are some settings that I would like to control on a per-file or even per-function basis. For example, match_arm_blocks -- most of the time I like it set to false, but some matches IMO look a lot better when it is set to true. (In fact they'd look even better if I could set match_arm_blocks to something like Force, where all arms in a match get braces.)

This is probably very non-trivial to implement, but I was imagining something like having an attribute to control rustfmt behavior locally:

#[rustfmt::configure(match_arm_blocks = true)]
fn foo() {
 ...
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by investigating how rustfmt reads project-wide configuration and how Rust attributes could express local settings; then clarify the supported file and function scopes and configuration semantics. Done should include a workable local override for the match_arm_blocks example, with tests covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.