parent
518ece2272
commit
911395a451
8 changed files with 19 additions and 139 deletions
|
|
@ -6,7 +6,7 @@ A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:
|
|||
|
||||
```toml
|
||||
indent_style = "Block"
|
||||
reorder_imported_names = true
|
||||
reorder_imports = false
|
||||
```
|
||||
|
||||
Each configuration option is either stable or unstable.
|
||||
|
|
@ -1240,31 +1240,10 @@ fn dolor() -> usize {}
|
|||
fn adipiscing() -> usize {}
|
||||
```
|
||||
|
||||
## `reorder_imported_names`
|
||||
|
||||
Reorder lists of names in import statements alphabetically
|
||||
|
||||
- **Default value**: `false`
|
||||
- **Possible values**: `true`, `false`
|
||||
- **Stable**: No
|
||||
|
||||
#### `false` (default):
|
||||
|
||||
```rust
|
||||
use super::{lorem, ipsum, dolor, sit};
|
||||
```
|
||||
|
||||
#### `true`:
|
||||
|
||||
```rust
|
||||
use super::{dolor, ipsum, lorem, sit};
|
||||
```
|
||||
|
||||
See also [`reorder_imports`](#reorder_imports).
|
||||
|
||||
## `reorder_imports`
|
||||
|
||||
Reorder import statements alphabetically
|
||||
Reorder import and extern crate statements alphabetically
|
||||
|
||||
- **Default value**: `false`
|
||||
- **Possible values**: `true`, `false`
|
||||
|
|
@ -1288,98 +1267,6 @@ use lorem;
|
|||
use sit;
|
||||
```
|
||||
|
||||
See also [`reorder_imported_names`](#reorder_imported_names), [`reorder_imports_in_group`](#reorder_imports_in_group).
|
||||
|
||||
## `reorder_imports_in_group`
|
||||
|
||||
Reorder import statements in group
|
||||
|
||||
- **Default value**: `false`
|
||||
- **Possible values**: `true`, `false`
|
||||
- **Stable**: No
|
||||
|
||||
**Note:** This option takes effect only when [`reorder_imports`](#reorder_imports) is set to `true`.
|
||||
|
||||
#### `true` (default):
|
||||
|
||||
```rust
|
||||
use std::io;
|
||||
use std::mem;
|
||||
|
||||
use dolor;
|
||||
use ipsum;
|
||||
use lorem;
|
||||
use sit;
|
||||
```
|
||||
|
||||
#### `false`:
|
||||
|
||||
|
||||
```rust
|
||||
use dolor;
|
||||
use ipsum;
|
||||
use lorem;
|
||||
use sit;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
```
|
||||
|
||||
See also [`reorder_imports`](#reorder_imports).
|
||||
|
||||
## `reorder_extern_crates`
|
||||
|
||||
Reorder `extern crate` statements alphabetically
|
||||
|
||||
- **Default value**: `true`
|
||||
- **Possible values**: `true`, `false`
|
||||
- **Stable**: No
|
||||
|
||||
#### `true` (default):
|
||||
|
||||
```rust
|
||||
extern crate dolor;
|
||||
extern crate ipsum;
|
||||
extern crate lorem;
|
||||
extern crate sit;
|
||||
```
|
||||
|
||||
#### `false`:
|
||||
|
||||
```rust
|
||||
extern crate lorem;
|
||||
extern crate ipsum;
|
||||
|
||||
extern crate dolor;
|
||||
extern crate sit;
|
||||
```
|
||||
|
||||
See also [`reorder_extern_crates_in_group`](#reorder_extern_crates_in_group).
|
||||
|
||||
## `reorder_extern_crates_in_group`
|
||||
|
||||
Reorder `extern crate` statements in group
|
||||
|
||||
- **Default value**: `true`
|
||||
- **Possible values**: `true`, `false`
|
||||
- **Stable**: No
|
||||
|
||||
#### `false` (default):
|
||||
|
||||
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.
|
||||
|
||||
#### `true`:
|
||||
|
||||
**Note:** This only takes effect when [`reorder_extern_crates`](#reorder_extern_crates) is set to `true`.
|
||||
|
||||
```rust
|
||||
extern crate a;
|
||||
extern crate b;
|
||||
|
||||
extern crate dolor;
|
||||
extern crate ipsum;
|
||||
extern crate lorem;
|
||||
extern crate sit;
|
||||
```
|
||||
|
||||
## `reorder_modules`
|
||||
|
||||
|
|
|
|||
|
|
@ -68,14 +68,9 @@ create_config! {
|
|||
imports_layout: ListTactic, ListTactic::Mixed, false, "Item layout inside a import block";
|
||||
|
||||
// Ordering
|
||||
reorder_extern_crates: bool, true, false, "Reorder extern crate statements alphabetically";
|
||||
reorder_extern_crates_in_group: bool, true, false, "Reorder extern crate statements in group";
|
||||
reorder_imports: bool, true, false, "Reorder import statements alphabetically";
|
||||
reorder_imports_in_group: bool, true, false, "Reorder import statements in group";
|
||||
reorder_imported_names: bool, true, false,
|
||||
"Reorder lists of names in import statements alphabetically";
|
||||
reorder_modules: bool, true, false, "Reorder module statemtents alphabetically in group";
|
||||
reorder_impl_items: bool, false, false, "Reorder impl items";
|
||||
reorder_imports: bool, true, false, "Reorder import and extern crate statements alphabetically";
|
||||
reorder_modules: bool, true, false, "Reorder module statements alphabetically in group";
|
||||
|
||||
// Spaces around punctuation
|
||||
type_punctuation_density: TypeDensity, TypeDensity::Wide, false,
|
||||
|
|
|
|||
|
|
@ -485,6 +485,7 @@ fn rewrite_nested_use_tree(
|
|||
);
|
||||
(tactic, remaining_width)
|
||||
};
|
||||
|
||||
let ends_with_newline = context.config.imports_indent() == IndentStyle::Block
|
||||
&& tactic != DefinitiveListTactic::Horizontal;
|
||||
let fmt = ListFormatting {
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ use std::time::Duration;
|
|||
use syntax::ast;
|
||||
pub use syntax::codemap::FileName;
|
||||
use syntax::codemap::{CodeMap, FilePathMapping};
|
||||
use syntax::errors::emitter::{ColorConfig, EmitterWriter};
|
||||
use syntax::errors::{DiagnosticBuilder, Handler};
|
||||
use syntax::errors::emitter::{ColorConfig, EmitterWriter};
|
||||
use syntax::parse::{self, ParseSess};
|
||||
|
||||
use checkstyle::{output_footer, output_header};
|
||||
|
|
|
|||
|
|
@ -198,18 +198,18 @@ impl ReorderableItemKind {
|
|||
|
||||
pub fn is_reorderable(&self, config: &Config) -> bool {
|
||||
match *self {
|
||||
ReorderableItemKind::ExternCrate => config.reorder_extern_crates(),
|
||||
ReorderableItemKind::ExternCrate => config.reorder_imports(),
|
||||
ReorderableItemKind::Mod => config.reorder_modules(),
|
||||
ReorderableItemKind::Use => config.reorder_imports(),
|
||||
ReorderableItemKind::Other => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn in_group(&self, config: &Config) -> bool {
|
||||
pub fn in_group(&self) -> bool {
|
||||
match *self {
|
||||
ReorderableItemKind::ExternCrate => config.reorder_extern_crates_in_group(),
|
||||
ReorderableItemKind::Mod => config.reorder_modules(),
|
||||
ReorderableItemKind::Use => config.reorder_imports_in_group(),
|
||||
ReorderableItemKind::ExternCrate => false,
|
||||
ReorderableItemKind::Mod => true,
|
||||
ReorderableItemKind::Use => true,
|
||||
ReorderableItemKind::Other => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -268,7 +268,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
let item_kind = ReorderableItemKind::from(items[0]);
|
||||
if item_kind.is_reorderable(self.config) {
|
||||
let visited_items_num =
|
||||
self.walk_reorderable_items(items, item_kind, item_kind.in_group(self.config));
|
||||
self.walk_reorderable_items(items, item_kind, item_kind.in_group());
|
||||
let (_, rest) = items.split_at(visited_items_num);
|
||||
items = rest;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
// rustfmt-normalize_comments: true
|
||||
|
||||
extern crate foo;
|
||||
extern crate foo as bar;
|
||||
|
||||
extern crate bar;
|
||||
extern crate chrono;
|
||||
extern crate dotenv;
|
||||
extern crate futures;
|
||||
|
||||
extern crate bar;
|
||||
extern crate foo;
|
||||
|
||||
// #2315
|
||||
extern crate foo;
|
||||
extern crate foo as bar;
|
||||
extern crate futures;
|
||||
extern crate proc_macro;
|
||||
// #2315
|
||||
extern crate proc_macro2;
|
||||
|
||||
extern "C" {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
|
||||
use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, dddddddd};
|
||||
use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc,
|
||||
ddddddddd};
|
||||
use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ use foo::{baz, qux as bar};
|
|||
|
||||
// With absolute paths
|
||||
use foo;
|
||||
use Foo;
|
||||
use foo::Bar;
|
||||
use foo::{Bar, Baz};
|
||||
use Foo;
|
||||
use {Bar, Baz};
|
||||
|
||||
// Root globs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue