Dangerous code. Do not use. Definitely breaks code in some cases. MIT license.
Here is a prototype I have so far (patch-ing vs 1.4.36 of rustfmt)
Main goal is to make Rust code look a bit more like idiomatic Clojure, i.e. https://github.com/bbatsov/clojure-style-guide where we avoid lines that consists solely or ")" or "}"
diff --git a/src/expr.rs b/src/expr.rs
index 33add30c..14117e4b 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1640,6 +1640,7 @@ fn rewrite_struct_lit<'a>(
let fields_str =
wrap_struct_field(context, &attrs, &fields_str, shape, v_shape, one_line_width)?;
+ let fields_str = fields_str.trim_end(); // ugly hack; so sorry
Some(format!("{} {{{}}}", path_str, fields_str))
// FIXME if context.config.indent_style() == Visual, but we run out
diff --git a/src/items.rs b/src/items.rs
index 10654a2a..73a0c2b5 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -520,7 +520,6 @@ impl<'a> FmtVisitor<'a> {
let list = write_list(&items, &fmt)?;
result.push_str(&list);
- result.push_str(&original_offset.to_string_with_newline(self.config));
result.push('}');
Some(result)
}
@@ -788,13 +787,12 @@ pub(crate) fn format_impl(
visitor.format_missing(item.span.hi() - BytePos(1));
let inner_indent_str = visitor.block_indent.to_string_with_newline(context.config);
- let outer_indent_str = offset.block_only().to_string_with_newline(context.config);
result.push_str(&inner_indent_str);
result.push_str(visitor.buffer.trim());
- result.push_str(&outer_indent_str);
} else if need_newline || !context.config.empty_item_single_line() {
result.push_str(&sep);
+
}
result.push('}');
@@ -1161,7 +1159,6 @@ pub(crate) fn format_trait(
result.push_str(&inner_indent_str);
result.push_str(visitor.buffer.trim());
- result.push_str(&outer_indent_str);
} else if result.contains('\n') {
result.push_str(&outer_indent_str);
}
@@ -1354,13 +1351,13 @@ pub(crate) fn format_struct_struct(
Some(format!("{} {} }}", result, items_str))
} else {
Some(format!(
- "{}\n{}{}\n{}}}",
+ "{}\n{}{}}}",
result,
offset
.block_indent(context.config)
.to_string(context.config),
items_str,
- offset.to_string(context.config)
+ // offset.to_string(context.config)
))
}
}
diff --git a/src/matches.rs b/src/matches.rs
index a43aed09..1fcab024 100644
--- a/src/matches.rs
+++ b/src/matches.rs
@@ -132,13 +132,12 @@ pub(crate) fn rewrite_match(
} else {
let span_after_cond = mk_sp(cond.span.hi(), span.hi());
Some(format!(
- "match {}{}{{\n{}{}{}\n{}}}",
+ "match {}{}{{\n{}{}{}}}",
cond_str,
block_sep,
inner_attrs_str,
nested_indent_str,
rewrite_match_arms(context, arms, shape, span_after_cond, open_brace_pos)?,
- shape.indent.to_string(context.config),
))
}
}
diff --git a/src/visitor.rs b/src/visitor.rs
index 34e8536b..16d1c005 100644
--- a/src/visitor.rs
+++ b/src/visitor.rs
@@ -369,7 +369,6 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
self.block_indent = self.block_indent.block_indent(self.config);
}
self.block_indent = self.block_indent.block_unindent(self.config);
- self.push_str(&self.block_indent.to_string_with_newline(config));
self.push_str("}");
}