Open DanTup opened 11 months ago
Thanks for filing this. The intent has always been that DartFormatter
objects are lightweight and short-lived, but it does seem confusing and not useful that it persists the inferred line endings across multiple calls.
I'm not sure if this is strictly a bug, but it feels incorrect. I was investigating an issue at https://github.com/Dart-Code/Dart-Code/issues/4865 where sometimes lots of blank lines were being added when formatting documents.
It seems like there may be two issues:
\n
to\r\n
\r\n
as if it's two newlines if the file is set toLF
mode but contains CRLF.The reason the first was occurring is that in the analysis server we are currently reusing the
DartFormatter
instance. This class caches the line ending on first format if it's not explicitly provided. This means if you format a document that uses CRLF and then one that uses LF, it will output CRLF for the second file:I'm going to remove the reuse of this instance from the server (we were discussing this because of language versions anyway), but I thought it was worth raising this because it's not clear if this is expected behaviour.