dart-lang / dart_style

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

[tall style] Multi-line variable declarations (without initializers) indentation #1541

Closed dcharkes closed 2 months ago

dcharkes commented 3 months ago

Very long typed final variables do not get indented:

  String renameMember(Declaration declaration, String member) =>
      renameMemberFunc(declaration, member);
  final String Function(Declaration declaration, String member)
      renameMemberFunc;

->

  String renameMember(Declaration declaration, String member) =>
      renameMemberFunc(declaration, member);
  final String Function(Declaration declaration, String member)
  renameMemberFunc;

I'm not sure if this is intended. I could probably get used to the new style.

Source file: https://github.com/dart-lang/native/blob/main/pkgs/ffigen/lib/src/config_provider/config_impl.dart

munificent commented 2 months ago

Yeah, this is working as intended.

It's a little strange but, honestly, there's probably no perfect style here. I chose this approach in the new style in part because it felt weird to me to indent the variable name, when the variable type is subordinate to it. The new style has a similar approach for function return types:

SomeVeryLongReturnType
function() {
  ...
}

And likewise there it would feel weird to me to indent the function name when it "owns" the return type.

So I decided to not indent at all whenever we split between a type annotation and the thing it annotates. Also, I think it looks pretty nice, especially in things like parameter lists.