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

Tall style: single argument => with multiple .. is very tall #1603

Open
davidmorgan opened this issue Nov 21, 2024 · 1 comment
Open

Tall style: single argument => with multiple .. is very tall #1603

davidmorgan opened this issue Nov 21, 2024 · 1 comment

Comments

@davidmorgan
Copy link

Short style:

      final value = Value((b) => b
        ..anInt = 3
        ..aString = 'four');

Tall style:

      final value = Value(
        (b) =>
            b
              ..anInt = 3
              ..aString = 'four',
      );

Any ideas please? :)

I'd be open to pushing for a new special case syntax for "lambda that immediately does something to its only argument and never references it again" if that's what it takes ;)

@munificent
Copy link
Member

This is essentially the same issue as #1466. (=> and = are formatted using the same code, and cascades and method chains are mostly formatted using the same code.)

I agree, it doesn't look great. I haven't been able to come up with a fix that doesn't do the wrong thing in some cases. Here, if the cascade target expression was longer than just b, like b.someVeryLong.propertyChain that ended up splitting as well, then the formatter wouldn't do the right thing.

I have some ideas on how to fix this, #1466, and #1465, but I haven't been able to get them working with decent performance yet. It's a surprisingly hard problem.

One option might be to do a hacky fix where we don't split after the => if the target expression is suitably short/simple enough that we're confident that a split won't happen inside it. But I've tried to avoid those sorts of hacks in the new formatter as much as possible.

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