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

Consider how to format method call chains whose target is a split delimited expression #1583

Open
loic-sharma opened this issue Oct 22, 2024 · 1 comment

Comments

@loic-sharma
Copy link

loic-sharma commented Oct 22, 2024

We should consider whether method call chains should be indented if the target is a split delimited expression:

// Without indentation
Widget build(BuildContext context) {
  return Container(
    color: Colors.blue,
    padding: EdgeInsets.all(8.0),
  )
  .clipOval();
}

// With indentation - looks weird?
Widget build(BuildContext context) {
  return Container(
    color: Colors.blue,
    padding: EdgeInsets.all(8.0),
  )
    .clipOval();
}

Also, we should consider whether method call chains on single-line constructor expressions should be indented:

// With indentation
Widget build(BuildContext context) {
  return Container(color: Colors.blue)
    .clipOval()
    .center();
}

Prior art

SwiftUI indents method call chains on single-line expressions but does not indent method call chains on split delimited expressions (example).

@munificent
Copy link
Member

I spent a little time looking into this. Aesthetically, I really like the proposed style. A call chain following a split delimited expression like a function call or collection literal has always looked pretty wonky and simply not indenting the chain at all so that it lines up with the closing ) or ] in the target seems like a nice fix.

I would still want to test it on a larger corpus and see if it looks weird in some contexts.

However, I haven't been able to actually implement it yet. :( It's running into, I think, the same limitation in the new formatter's IR that is getting in the way of #1465 and #1466. I have some thoughts on how to make the formatter able to handle these cases but so far I haven't been able to get anything working.

I'll try to think about it more.

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

No branches or pull requests

2 participants