Skip to content

Commit d0e471f

Browse files
committed
Declare & implement space_around_attr_eq config.
This configuration setting controls the spacing around `=` when found inside of attributes. Eg: ```rust #[cfg(target_os="linux")] // vs #[cfg(target_os = "linux")] ``` The config setting `space_around_attr_eq` takes a bool value. Closes #4039
1 parent facba6a commit d0e471f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

rustfmt-core/rustfmt-config/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ create_config! {
7373
"Determines if '+' or '=' are wrapped in spaces in the punctuation of types";
7474
space_before_colon: bool, false, false, "Leave a space before the colon";
7575
space_after_colon: bool, true, false, "Leave a space after the colon";
76+
space_around_attr_eq: bool, true, false,
77+
"Determines if '=' are wrapped in spaces in attributes.";
7678
spaces_around_ranges: bool, false, false, "Put spaces around the .. and ..= range operators";
7779
binop_separator: SeparatorPlace, SeparatorPlace::Front, false,
7880
"Where to put a binary operator when a binary expression goes multiline";

rustfmt-core/rustfmt-lib/src/attr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ impl Rewrite for ast::MetaItem {
252252
// See #2479 for example.
253253
let value = rewrite_literal(context, literal, lit_shape)
254254
.unwrap_or_else(|| context.snippet(literal.span).to_owned());
255-
format!("{} = {}", path, value)
255+
if context.config.space_around_attr_eq() {
256+
format!("{} = {}", path, value)
257+
} else {
258+
format!("{}={}", path, value)
259+
}
256260
}
257261
})
258262
}

0 commit comments

Comments
 (0)