Always put a newline after a binop def body

This commit is contained in:
Richard Feldman 2022-07-13 22:30:46 -04:00
parent 9e19baef59
commit 8178f22ce4
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798

View file

@ -324,6 +324,7 @@ pub fn fmt_body<'a, 'buf>(
) {
pattern.format_with_options(buf, Parens::InApply, Newlines::No, indent);
buf.push_str(" =");
if body.is_multiline() {
match body {
Expr::SpaceBefore(sub_def, spaces) => {
@ -347,6 +348,22 @@ pub fn fmt_body<'a, 'buf>(
);
}
}
Expr::BinOps(_, _) => {
// Binop chains always get a newline. Otherwise you can have things like:
//
// something = foo
// |> bar baz
//
// By always inserting a newline, this becomes:
//
// something =
// foo
// |> bar baz
//
// This makes it clear what the binop is applying to!
buf.newline();
body.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent + INDENT);
}
_ => {
buf.spaces(1);
body.format_with_options(buf, Parens::NotNeeded, Newlines::Yes, indent);