Skip to content

Commit

Permalink
Declare & implement space_around_attr_eq config. (#4040)
Browse files Browse the repository at this point in the history
  • Loading branch information
thedodd authored Apr 16, 2020
1 parent 45ac003 commit 9ace1de
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,28 @@ fn main() {
}
```

## `space_around_attr_eq`

Determines if '=' are wrapped in spaces in attributes.

- **Default value**: `true`
- **Possible values**: `true`, `false`
- **Stable**: No

#### `true` (default):

```rust
#[cfg(not(target_os = "pi"))]
println!("os is not pi!");
```

#### `false`

```rust
#[cfg(not(target_os="pi"))]
println!("os is not pi!");
```

## `struct_field_align_threshold`

The maximum diff of width between struct fields to be aligned with each other.
Expand Down
3 changes: 3 additions & 0 deletions rustfmt-core/rustfmt-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ create_config! {
"Determines if '+' or '=' are wrapped in spaces in the punctuation of types";
space_before_colon: bool, false, false, "Leave a space before the colon";
space_after_colon: bool, true, false, "Leave a space after the colon";
space_around_attr_eq: bool, true, false,
"Determines if '=' are wrapped in spaces in attributes.";
spaces_around_ranges: bool, false, false, "Put spaces around the .. and ..= range operators";
binop_separator: SeparatorPlace, SeparatorPlace::Front, false,
"Where to put a binary operator when a binary expression goes multiline";
Expand Down Expand Up @@ -514,6 +516,7 @@ reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
space_around_attr_eq = true
spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
Expand Down
6 changes: 5 additions & 1 deletion rustfmt-core/rustfmt-lib/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ impl Rewrite for ast::MetaItem {
// See #2479 for example.
let value = rewrite_literal(context, literal, lit_shape)
.unwrap_or_else(|| context.snippet(literal.span).to_owned());
format!("{} = {}", path, value)
if context.config.space_around_attr_eq() {
format!("{} = {}", path, value)
} else {
format!("{}={}", path, value)
}
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// rustfmt-space_around_attr_eq: false

fn attr_eq_test() {
#[cfg(not(target_os = "pi"))]
println!("os is not pi!");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// rustfmt-space_around_attr_eq: true

fn attr_eq_test() {
#[cfg(not(target_os="pi"))]
println!("os is not pi!");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// rustfmt-space_around_attr_eq: false

fn attr_eq_test() {
#[cfg(not(target_os="pi"))]
println!("os is not pi!");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// rustfmt-space_around_attr_eq: true

fn attr_eq_test() {
#[cfg(not(target_os = "pi"))]
println!("os is not pi!");
}

0 comments on commit 9ace1de

Please sign in to comment.