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

Add test that tickles subtree merging. #1488

Closed munificent closed 3 months ago

munificent commented 3 months ago

An important optimization in the formatter is that it will format a subtree of the Piece tree separately and weave the result back into the parent Solution when possible. Part of that process is adding in any bound states, overflow characters, and costs determined in the subtree.

Surprisingly, those rarely actually come into play in terms of affecting the outermost winning solution. I'm not sure exactly why, but if you just merge in the subtree solution's text and discard the bound states, overflow, and cost... all the tests still pass.

But after testing on a large corpus, it turns out that in more complex real-world examples, it is important to copy that data back over. So I grabbed an example whose formatting was affected and added this as a sort of regression test.