dart-lang / dart_style

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

Handle imports with "as" and "if" clauses in either order. #1555

Closed munificent closed 2 months ago

munificent commented 2 months ago

PR #1550 fixed the bug where if you had both clauses, it would output them in the wrong order. But it turns out that the parser today allows them in either order even though the language spec doesn't.

Since I've seen a handful of cases like this in the wild, instead of just failing to format, simply preserve the clause order that the user wrote.

natebosch commented 2 months ago

instead of just failing to format

Does it fail to format, or does it change the order to the correct one in the formatted code?

munificent commented 2 months ago

Prior to this PR, it would change the order to the correct one in the formatter output. But that would then cause the formatter's own internal "I only make whitespace changes" sanity check to fail since it would see that as a non-whitespace change, which would then cause the formatter to abort writing that file.

With this PR, it just keeps the order that the user wrote, which also then means it is only making whitespace changes.

natebosch commented 2 months ago

Oh I see from the other thread it trips the detection that something other than whitespace changed...