Feature request: Option to have one "use" statement per file
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Currently imports_granularity = 'One' merges all imports into one "use" statement. In my opinion, functionally it does two separate things: 1) Combine all "use" statements; 2) apply imports_granularity = 'Crate' inside the braces. Obviously it has the advantage of having no duplicate "use". However, I also really like the style of imports_granularity = 'Module'. It's visually much clearer, and easier to modify one import without affecting other imports. Ideally, I'd love to see a style where it can combine the "one" use statement with the module style. For example,
use {
foo::b::{f, g},
foo::d::e,
foo::{a, b, c},
qux::{h, i},
};
I think imports_granularity is orthogonal to this one "use" statement style, so why not introduce a separate option like one_use_statement? With this new option, we will have 6 combinations in total:
-
imports_granularity = 'Crate'+one_use_statement = false -
imports_granularity = 'Module'+one_use_statement = false -
imports_granularity = 'Item'+one_use_statement = false
These 3 will be exactly the same as current -
imports_granularity = 'Crate'+one_use_statement = true
This is basically identical to the currentimports_granularity = 'One' -
imports_granularity = 'Module'+one_use_statement = true
The example is shown above -
imports_granularity = 'Item'+one_use_statement = true
use {
foo::a,
foo::b,
foo::b::f,
foo::b::g,
foo::c,
foo::d::e,
qux::h,
qux::i,
};
With this new option, imports_granularity = 'One' is no longer needed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue does not name files, tests, or an entry point. Start by locating rustfmt's existing imports_granularity configuration and related import-formatting tests, then determine how a separate one-use-statement option should interact with the existing modes and update coverage for the proposed combinations.
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
- 35/100