-
Notifications
You must be signed in to change notification settings - Fork 1k
imports_granularity: implement One/Single variant #4669
Copy link
Copy link
Closed
Labels
1x-backport:completedA-importsArea: imports, e.g. `use` syntaxArea: imports, e.g. `use` syntaxC-feature-requestCategory: a feature request (not decided/implemented)Category: a feature request (not decided/implemented)E-help-wantedCall for participation: help is requested to fix this issueCall for participation: help is requested to fix this issuegood first issueIssues up for grabs, also good candidates for new rustfmt contributorsIssues up for grabs, also good candidates for new rustfmt contributors
Metadata
Metadata
Assignees
Labels
1x-backport:completedA-importsArea: imports, e.g. `use` syntaxArea: imports, e.g. `use` syntaxC-feature-requestCategory: a feature request (not decided/implemented)Category: a feature request (not decided/implemented)E-help-wantedCall for participation: help is requested to fix this issueCall for participation: help is requested to fix this issuegood first issueIssues up for grabs, also good candidates for new rustfmt contributorsIssues up for grabs, also good candidates for new rustfmt contributors
Type
Fields
Give feedbackNo fields configured for issues without a type.
Add a new variant and associated formatting to
imports_granularitythat reformats all imports into a single use statement. The variant name should beOneorSingle, withOnebeing the leading contender (refer here for One and here for Single for respective community votes/feedback)Background
imports_granularityis a configuration option that allows users to control the granularity of their use declarations (https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#imports_granularity)By default rustfmt will not modify the granularity and will preserve the developers original structure, but the
imports_granularityoption provides several different variants that users can leverage to instruct rustfmt to reformat their use statements with a specific level of granularity.Several different styles/granularity levels have been identified (summarized here, and already implemented, with the exception of the one/single granularity variant.
Implementation
There will be 3 high level tasks required here
For the configuration side:
For implementation, refer to relevant sections in
src/formatting/imports.rsandsrc/formatting/reorder.rs, some suggested starting points:rustfmt/src/formatting/imports.rs
Lines 872 to 875 in 79c3696
rustfmt/src/formatting/imports.rs
Lines 550 to 565 in 79c3696
rustfmt/src/formatting/reorder.rs
Lines 231 to 238 in 79c3696
For tests (more information on writing tests here):
Some unit tests for the other variants can be found here
https://github.com/rust-lang/rustfmt/blob/master/src/formatting/imports.rs#L1032-L1087
Additional files for the system/idempotence tests can be found under
tests/{src,target}/imports_granularity_{crate,item,module}.rsfor reference