dart-lang / dart_style

An opinionated formatter/linter for Dart code
https://pub.dev/packages/dart_style
BSD 3-Clause "New" or "Revised" License
645 stars 117 forks source link

Don't use AssignPiece for for-in loop "in" clauses. #1485

Closed munificent closed 3 months ago

munificent commented 3 months ago

One of the reasons that AssignPiece is so hairy is because it handles both splitting after the operator ("=", ":", etc.) and before "in".

Splitting out for-in loops to their own Piece class lets us get rid of a little of that complexity.

Also, I thought that was the only reason that the operator is a separate Piece. That's actually not true because we also need the LHS to be its own piece for applyConstraints().

Even so, I still think it's a little easier to understand with for-in loops being their own piece.

I also slightly tweaked the formatting of for-in loops. In the rare case where the left side block splits, we now indent it and split at "in". This is consistent with the old style. I don't have a strong preference, but I think it looks a little neater this way.