Skip to content

Should argument lists with named arguments always split? #1647

@munificent

Description

@munificent

There's been discussion on #1253 and elsewhere that some users would prefer some argument lists to split even when they would fit within a single line. I'm open to the idea, but I don't know what heuristics would work best. A very simple one (at least as I understand it) suggested by @koji-1009 is: Always split argument lists with named arguments.

This has a couple of nice properties:

  • My intuition is that users generally expect positional argument lists to be dense and single line when possible.
  • Flutter code, which is almost more like "markup" than "code" seems to be where users want argument lists to split even when they don't have to. And those constructor calls tend to mostly use named arguments.

On the other hand, I'm sure there are function calls with named arguments that aren't inside Flutter build code and which would look pretty bad if forcibly split. Off the top of my head, I can't see anyone preferring:

Duration(
  minutes: 1,
);

Over:

Duration(minutes: 1);

There is a rule in the formatter for collection literals that says a collection literal will always split if it contains any nested ones. That gives you:

[
  [1],
]

Instead of:

[[1]]

Perhaps a similar rule for argument lists would help here. We could consider always splitting an argument list if it has named arguments and at least one of those arguments is also a function call. However note that that rule would not work for the actual example brought up by @koji-1009:

EdgeInsets.only(
  top: 10.0,
  right: 20.0,
)

(Personally, if this were my code, I would prefer that call to not be split if possible.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions