munificent Support "block argument" formatting. (#1322)
28fa4be Nov 17, 2023
Support "block argument" formatting. (#1322)
Support "block argument" formatting.

Sometimes in an argument list, we don't want to force it to full split
even if an argument contains an inner newline. In other words, we want
to prefer:

```
test('hi', () {
  body;
});
```

Over:

```
test(
  'hi',
  () {
    body;
  },
);
```

The latter is what you would normally get when an argument contains a
newline. This change enables the former. The heuristics for what kinds
of arguments are allowed to have this block-like formatting, how many
of them, and what other arguments are allowed are pretty fuzzy.

I picked a simple set of rules here (which follow the prototype), but
left some TODOs because I suspect we will iterate on them later once we
can run the new formatter on larger codebases.

The heuristic for what kinds of arguments are block-like is the same
rule that we use for "delimited" expressions after an assignment. I
think it's good that those two agree and helps make the style overall
more consistent. Basically, any time the right-hand side of an `=` or
`:` doesn't need to split, that same kind of expression can be block
formatted:

```
var list = [
  element,
];

function([
  element,
]);
```

Block formatting is used for argument lists, asserts, and switch values.

I also simplified AssignPiece. It used an extra unnecessary to allow
newlines inside delimited value expressions without splitting after "=".

Also renamed "isDelimited" (never a great name) to "canBlockSplit",
which I think better captures its use.
28fa4be