Skip to content

Feature/sliding imports #5383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:

```toml
indent_style = "Block"
reorder_imports = false
reorder_imports = "Off"
```

Each configuration option is either stable or unstable.
Expand Down Expand Up @@ -2016,14 +2016,14 @@ impl Iterator for Dummy {

## `reorder_imports`

Reorder import and extern crate statements alphabetically in groups (a group is
Reorder import and extern crate statements in groups (a group is
separated by a newline).

- **Default value**: `true`
- **Possible values**: `true`, `false`
- **Stable**: Yes
- **Default value**: `"Alphabetically"`
- **Possible values**: `"Alphabetically"`, `"Length"`, `"Off"`
- **Stable**: No

#### `true` (default):
#### `"Alphabetically"` (default):

```rust
use dolor;
Expand All @@ -2032,7 +2032,7 @@ use lorem;
use sit;
```

#### `false`:
#### `"Off"`:

```rust
use lorem;
Expand Down
4 changes: 4 additions & 0 deletions src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ macro_rules! create_config {
}
)+
}
/*#[allow(unreachable_pub)]
pub fn reorder_imports(&self) -> ReorderImports {
self.reorder_imports
}*/

fn set_width_heuristics(&mut self, heuristics: WidthHeuristics) {
let max_width = self.max_width.2;
Expand Down
5 changes: 3 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ create_config! {
merge_imports: bool, false, false, "(deprecated: use imports_granularity instead)";

// Ordering
reorder_imports: bool, true, true, "Reorder import and extern crate statements alphabetically";
reorder_imports: ReorderImports, ReorderImports::Alphabetically, false,
"Reorder import and extern crate statements";
reorder_modules: bool, true, true, "Reorder module statements alphabetically in group";
reorder_impl_items: bool, false, false, "Reorder impl items";

Expand Down Expand Up @@ -547,7 +548,7 @@ imports_indent = "Block"
imports_layout = "Mixed"
imports_granularity = "Preserve"
group_imports = "Preserve"
reorder_imports = true
reorder_imports = "Alphabetically"
reorder_modules = true
reorder_impl_items = false
type_punctuation_density = "Wide"
Expand Down
10 changes: 10 additions & 0 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,13 @@ pub enum MatchArmLeadingPipe {
/// Preserve any existing leading pipes
Preserve,
}

/// Reorder imports
#[config_type]
pub enum ReorderImports {
Alphabetically,

Length,

Off,
}
Loading