0

I've got the dart formatter running on my code, and for some reason it insists on the following formatting:

  String get display => switch (type) {
        ListType.star => 'Starred',
        ListType.bookmark => 'Bookmarked',
        ListType.custom => custom!,
      };

That's three levels of indentation on the second line, which to my mind only requires a single one. What's going on? Is there a way to stop that in Visual Studio Code?

6
  • Google developers don't think so, despite what a reasonable person might think. They believe that indents should be increased (in this case) at least threefold. Commented Nov 14 at 16:33
  • The logic is that the switch in this case is all a single expression rather than a code block, so it should be formatted as a multiline expression with additional indentation rather than a nested code block. It's certainly a controversial choice, but the Dart formatter is notoriously opinionated and not extensible (see stackoverflow.com/questions/59815378/…) and there isn't a fully featured community formatting tool yet. In other words, the Dart team follows the Google guidelines, and for everyone else, their stance is, generally speaking, "deal with it". Commented Nov 14 at 23:35
  • @Abion47 A fully functional community formatting tool is useless because if source code is not formatted according to Google's guidelines, it will result in Google intentionally downgrading the rating of that software on pub.dev. The following will be stated as the reason for downgrading the software quality rating: doesn't match the Dart formatter. So there is no point in even mentioning what is not acceptable for Google (I mean the alternative formatting method). Commented Nov 15 at 13:59
  • Interesting fact: The Dart SDK developers don't use the Dart formatter and don't claim that their code is of lower quality. They say something like, "It's a matter of taste." But if someone's taste doesn't match Google's requirements, then such software will be considered of lower quality. At least on pub.dev. And it will be marked with a lower quality rating (In pseudo points). Commented Nov 15 at 14:08
  • @mezoni That was correct in the past but the Dart SDK are now fully formatted using the formatter. They also do a reformat when the dart formatter have seen changes to likely get an idea of consequences of such updates. Similar, Flutter also now formats their code using the formatter. Commented Nov 15 at 16:40

1 Answer 1

0

Maybe it's because it looks very elegant?
Look at the number 1 in the binary expression length > 1.
There's simply no better place for that number 1.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.