Description
Add a new variant and associated formatting to imports_granularity
that reformats all imports into a single use statement. The variant name should be One
or Single
, with One
being the leading contender (refer here for One and here for Single for respective community votes/feedback)
use {
futures::{
ready,
stream::{Stream, StreamExt},
},
std::pin::{Pin, Unpin},
};
Background
imports_granularity
is 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_granularity
option 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
- Updating the configuration option information
- Updating the imports merging logic to support the new granularity style
- Adding tests
For the configuration side:
- Documentation will need to be extended with the new variant details
- Adding the new variant
For implementation, refer to relevant sections in src/formatting/imports.rs
and src/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}.rs
for reference