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: Add trailing comma if a named parameter's value is splitted #1543

Closed alexeyinkin closed 2 months ago

alexeyinkin commented 3 months ago

This:

void main() async {
  fn(
    param1: true,
    paraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaam2: [
      ['value'],
    ],
  );
}

becomes:

void main() async {
  fn(param1: true, paraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaam2: [
    ['value'],
  ]);
}

This is similar to

fn([a], [
  b
  c,
]);

The problem is, with named parameters, a name is very important, and name-value pair should stay coupled and ideally separate from other pairs. If a distinction of a line break is introduced between param2 and its value, at least the same distinction should be introduced between the pairs.

I take the rule of pair distinction further, and my personal preference is to have a trailing comma if we have at least 2 named parameters:

void main() async {
  fn(
    param1: true,
    param2: true,
  );
}