3 ms·
> For dartfmt, I did my best to keep the original requirements even thought it meant a much more complex formatter. That made my implementation job harder. But
by vjeux 8y ago
> For dartfmt, I did my best to keep the original requirements even thought it meant a much more complex formatter. That made my implementation job harder. But it made the political job of convincing everyone inside Google (and most users outside) to use dartfmt much easier because the output was closer to what they wanted.
I couldn't have said it better :)
I added a ton of special cases in the step that takes an AST and outputs the IR to handle those two things (and many many more).
For 1), I special case functions that look like `test(` and completely ignore the 80 column rule so that the name stays in one line. https://github.com/prettier/prettier/blob/3e0dceda9954658860ffdbc7e04465fcf5737d12/src/language-js/printer-estree.js#L1047-L1058 https://github.com/prettier/prettier/blob/3e0dceda9954658860...
For 2), member chains is actually the most complex piece of prettier, but it was important to get right. There's plenty of comments in the implementation: https://github.com/prettier/prettier/blob/3e0dceda9954658860ffdbc7e04465fcf5737d12/src/language-js/printer-estree.js#L4222-L4584 https://github.com/prettier/prettier/blob/3e0dceda9954658860...
I'm sure you did something similar as well :)
- munificent 8y agoYes! There is a whole separate class just to handle formatting method chains: https://github.com/dart-lang/dart_style/blob/master/lib/src/call_chain_visitor.dart https://github.com/dart-lang/dart_style/blob/master/lib/src/...