Skip to content

Commit 911395a

Browse files
committed
Squash the various 'reorder imports' option into one
cc #2185
1 parent 518ece2 commit 911395a

File tree

8 files changed

+19
-139
lines changed

8 files changed

+19
-139
lines changed

Configurations.md

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:
66

77
```toml
88
indent_style = "Block"
9-
reorder_imported_names = true
9+
reorder_imports = false
1010
```
1111

1212
Each configuration option is either stable or unstable.
@@ -1240,31 +1240,10 @@ fn dolor() -> usize {}
12401240
fn adipiscing() -> usize {}
12411241
```
12421242

1243-
## `reorder_imported_names`
1244-
1245-
Reorder lists of names in import statements alphabetically
1246-
1247-
- **Default value**: `false`
1248-
- **Possible values**: `true`, `false`
1249-
- **Stable**: No
1250-
1251-
#### `false` (default):
1252-
1253-
```rust
1254-
use super::{lorem, ipsum, dolor, sit};
1255-
```
1256-
1257-
#### `true`:
1258-
1259-
```rust
1260-
use super::{dolor, ipsum, lorem, sit};
1261-
```
1262-
1263-
See also [`reorder_imports`](#reorder_imports).
12641243

12651244
## `reorder_imports`
12661245

1267-
Reorder import statements alphabetically
1246+
Reorder import and extern crate statements alphabetically
12681247

12691248
- **Default value**: `false`
12701249
- **Possible values**: `true`, `false`
@@ -1288,98 +1267,6 @@ use lorem;
12881267
use sit;
12891268
```
12901269

1291-
See also [`reorder_imported_names`](#reorder_imported_names), [`reorder_imports_in_group`](#reorder_imports_in_group).
1292-
1293-
## `reorder_imports_in_group`
1294-
1295-
Reorder import statements in group
1296-
1297-
- **Default value**: `false`
1298-
- **Possible values**: `true`, `false`
1299-
- **Stable**: No
1300-
1301-
**Note:** This option takes effect only when [`reorder_imports`](#reorder_imports) is set to `true`.
1302-
1303-
#### `true` (default):
1304-
1305-
```rust
1306-
use std::io;
1307-
use std::mem;
1308-
1309-
use dolor;
1310-
use ipsum;
1311-
use lorem;
1312-
use sit;
1313-
```
1314-
1315-
#### `false`:
1316-
1317-
1318-
```rust
1319-
use dolor;
1320-
use ipsum;
1321-
use lorem;
1322-
use sit;
1323-
use std::io;
1324-
use std::mem;
1325-
```
1326-
1327-
See also [`reorder_imports`](#reorder_imports).
1328-
1329-
## `reorder_extern_crates`
1330-
1331-
Reorder `extern crate` statements alphabetically
1332-
1333-
- **Default value**: `true`
1334-
- **Possible values**: `true`, `false`
1335-
- **Stable**: No
1336-
1337-
#### `true` (default):
1338-
1339-
```rust
1340-
extern crate dolor;
1341-
extern crate ipsum;
1342-
extern crate lorem;
1343-
extern crate sit;
1344-
```
1345-
1346-
#### `false`:
1347-
1348-
```rust
1349-
extern crate lorem;
1350-
extern crate ipsum;
1351-
1352-
extern crate dolor;
1353-
extern crate sit;
1354-
```
1355-
1356-
See also [`reorder_extern_crates_in_group`](#reorder_extern_crates_in_group).
1357-
1358-
## `reorder_extern_crates_in_group`
1359-
1360-
Reorder `extern crate` statements in group
1361-
1362-
- **Default value**: `true`
1363-
- **Possible values**: `true`, `false`
1364-
- **Stable**: No
1365-
1366-
#### `false` (default):
1367-
1368-
This value has no influence beyond the effect of the [`reorder_extern_crates`](#reorder_extern_crates) option. Set [`reorder_extern_crates`](#reorder_extern_crates) to `false` if you do not want `extern crate` groups to be collapsed and ordered.
1369-
1370-
#### `true`:
1371-
1372-
**Note:** This only takes effect when [`reorder_extern_crates`](#reorder_extern_crates) is set to `true`.
1373-
1374-
```rust
1375-
extern crate a;
1376-
extern crate b;
1377-
1378-
extern crate dolor;
1379-
extern crate ipsum;
1380-
extern crate lorem;
1381-
extern crate sit;
1382-
```
13831270

13841271
## `reorder_modules`
13851272

src/config/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,9 @@ create_config! {
6868
imports_layout: ListTactic, ListTactic::Mixed, false, "Item layout inside a import block";
6969

7070
// Ordering
71-
reorder_extern_crates: bool, true, false, "Reorder extern crate statements alphabetically";
72-
reorder_extern_crates_in_group: bool, true, false, "Reorder extern crate statements in group";
73-
reorder_imports: bool, true, false, "Reorder import statements alphabetically";
74-
reorder_imports_in_group: bool, true, false, "Reorder import statements in group";
75-
reorder_imported_names: bool, true, false,
76-
"Reorder lists of names in import statements alphabetically";
77-
reorder_modules: bool, true, false, "Reorder module statemtents alphabetically in group";
7871
reorder_impl_items: bool, false, false, "Reorder impl items";
72+
reorder_imports: bool, true, false, "Reorder import and extern crate statements alphabetically";
73+
reorder_modules: bool, true, false, "Reorder module statements alphabetically in group";
7974

8075
// Spaces around punctuation
8176
type_punctuation_density: TypeDensity, TypeDensity::Wide, false,

src/imports.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ fn rewrite_nested_use_tree(
485485
);
486486
(tactic, remaining_width)
487487
};
488+
488489
let ends_with_newline = context.config.imports_indent() == IndentStyle::Block
489490
&& tactic != DefinitiveListTactic::Horizontal;
490491
let fmt = ListFormatting {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ use std::time::Duration;
4242
use syntax::ast;
4343
pub use syntax::codemap::FileName;
4444
use syntax::codemap::{CodeMap, FilePathMapping};
45-
use syntax::errors::emitter::{ColorConfig, EmitterWriter};
4645
use syntax::errors::{DiagnosticBuilder, Handler};
46+
use syntax::errors::emitter::{ColorConfig, EmitterWriter};
4747
use syntax::parse::{self, ParseSess};
4848

4949
use checkstyle::{output_footer, output_header};

src/reorder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,18 @@ impl ReorderableItemKind {
198198

199199
pub fn is_reorderable(&self, config: &Config) -> bool {
200200
match *self {
201-
ReorderableItemKind::ExternCrate => config.reorder_extern_crates(),
201+
ReorderableItemKind::ExternCrate => config.reorder_imports(),
202202
ReorderableItemKind::Mod => config.reorder_modules(),
203203
ReorderableItemKind::Use => config.reorder_imports(),
204204
ReorderableItemKind::Other => false,
205205
}
206206
}
207207

208-
pub fn in_group(&self, config: &Config) -> bool {
208+
pub fn in_group(&self) -> bool {
209209
match *self {
210-
ReorderableItemKind::ExternCrate => config.reorder_extern_crates_in_group(),
211-
ReorderableItemKind::Mod => config.reorder_modules(),
212-
ReorderableItemKind::Use => config.reorder_imports_in_group(),
210+
ReorderableItemKind::ExternCrate => false,
211+
ReorderableItemKind::Mod => true,
212+
ReorderableItemKind::Use => true,
213213
ReorderableItemKind::Other => false,
214214
}
215215
}
@@ -268,7 +268,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
268268
let item_kind = ReorderableItemKind::from(items[0]);
269269
if item_kind.is_reorderable(self.config) {
270270
let visited_items_num =
271-
self.walk_reorderable_items(items, item_kind, item_kind.in_group(self.config));
271+
self.walk_reorderable_items(items, item_kind, item_kind.in_group());
272272
let (_, rest) = items.split_at(visited_items_num);
273273
items = rest;
274274
} else {

tests/target/extern.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
// rustfmt-normalize_comments: true
22

3-
extern crate foo;
4-
extern crate foo as bar;
5-
3+
extern crate bar;
64
extern crate chrono;
75
extern crate dotenv;
8-
extern crate futures;
9-
10-
extern crate bar;
116
extern crate foo;
12-
13-
// #2315
7+
extern crate foo;
8+
extern crate foo as bar;
9+
extern crate futures;
1410
extern crate proc_macro;
11+
// #2315
1512
extern crate proc_macro2;
1613

1714
extern "C" {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
21
use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, dddddddd};
32
use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc,
43
ddddddddd};
4+
use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;

tests/target/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ use foo::{baz, qux as bar};
5454

5555
// With absolute paths
5656
use foo;
57+
use Foo;
5758
use foo::Bar;
5859
use foo::{Bar, Baz};
59-
use Foo;
6060
use {Bar, Baz};
6161

6262
// Root globs

0 commit comments

Comments
 (0)