Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing formatting on unrelated cascades #760

Closed
munificent opened this issue Nov 29, 2018 · 2 comments
Closed

Confusing formatting on unrelated cascades #760

munificent opened this issue Nov 29, 2018 · 2 comments

Comments

@munificent
Copy link
Member

The formatter produces this output:

main() {
  foo.bar.create(Thing()
    ..a = b
    ..c = d)
    ..method().chain((_) => lambda);
}

Note that the last cascade (..method()) is not on the same receiver as the previous ones even though it's indented the same.

@munificent
Copy link
Member Author

I spent some time looking into this, but wasn't able to come up with a fix that didn't push a lot of other formatting around in generally worse ways. The main problem is that this interacts poorly with the special rule that cascades indent deeper than a preceding method chain even though technically the method chain is a subexpression:

object
    .method()
    .method()
      ..cascade()
      ..cascade();

We can possibly lose that special rule. I ran it on a corpus and I can't honestly say I think the rule carries its weight. However, a side effect of that is that a lot of expressions preceding cascades go from +2 indentation to +4 because now they get normal expression indentation.

I'm not sure if that's a net win, so sitting on this for now.

@munificent
Copy link
Member Author

The forthcoming tall style moves ) to the next line when an argument list which happens to resolve the weird formatting here too. With the new style, you get:

main() {
  foo.bar.create(
    Thing()
      ..a = b
      ..c = d,
  )..method().chain((_) => lambda);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant