dart-lang / dart_style

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

Allow an unsplit method target on the same line as an assignment #1466

Open munificent opened 3 months ago

munificent commented 3 months ago

This issue is somewhat similar to #1465. Where that one relates to conditional expressions on the right-hand side of "assignments" (=, :, =>), this is about method chains. A method chain can split in a few ways:

// Unsplit:
target.method(arg).another(arg);

// Block split:
target.method(arg).another(
  arg,
);

// Chain split:
target
    .method(arg)
    .another(arg);

Currently, if the right-hand side of an assignment is a method chain that chain splits, it also splits the assignment, like:

thing = 
    target
        .method(arg)
        .another(arg);

It would be nice to allow the target to stay on the same line as the assignment:

thing = target
    .method(arg)
    .another(arg);

This would only apply if the target itself doesn't split. A split in the target would still force the assignment to split. So:

// Disallowed:
thing = (veryLong +
        targetExpression)
    .method(arg)
    .another(arg);

// Allowed:
thing =
    (veryLong +
            targetExpression)
        .method(arg)
        .another(arg);