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

Line breaks should favor method chaining for long statements #581

Closed
tvolkert opened this issue Feb 1, 2017 · 3 comments
Closed

Line breaks should favor method chaining for long statements #581

tvolkert opened this issue Feb 1, 2017 · 3 comments

Comments

@tvolkert
Copy link

tvolkert commented Feb 1, 2017

This following was formatted by dartfmt:

          expect(
              events[0],
              invokesMethod('file').on(fs).withPositionalArguments(
                  <String>['/foo']).withResult(isFile));

But there's clearly a method chain happening here, and it would be significantly more readable if it were expressed as:

          expect(
              events[0],
              invokesMethod('file')
                  .on(fs)
                  .withPositionalArguments(<String>['/foo'])
                  .withResult(isFile));

(separate issue is why events[0] is put on its own line, but that's lower priority).

@tvolkert
Copy link
Author

tvolkert commented Feb 1, 2017

@Hixie

@munificent
Copy link
Member

Yeah, it would be nice if it recognized the chain better here. I think the problem is the list literal. When you have collection literals in a method chain, it also considers formatting it like:

method([
  stuff...
].method([
  more stuff...
]);

In theory, it can handle both styles, but determining which to choose is difficult for it and there may be some interaction between the two.

@munificent
Copy link
Member

The forthcoming tall style handles this better and gives you:

          expect(
            events[0],
            invokesMethod('file')
                .on(fs)
                .withPositionalArguments(<String>['/foo'])
                .withResult(isFile),
          );

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

2 participants