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

no extra-indent of expression function as argument with trailing comma #794

Merged
merged 1 commit into from
Jun 4, 2019

Conversation

a14n
Copy link
Contributor

@a14n a14n commented Mar 31, 2019

Actual:

      onTap: () {
        Navigator.of(context).push(CupertinoPageRoute<void>(
          title: colorName,
          builder: (BuildContext context) => Tab1ItemPage(
                color: color,
                colorName: colorName,
                index: index,
              ),
        ));
      },

Expected:

      onTap: () {
        Navigator.of(context).push(CupertinoPageRoute<void>(
          title: colorName,
          builder: (BuildContext context) => Tab1ItemPage(
            color: color,
            colorName: colorName,
            index: index,
          ),
        ));
      },

@kevmoo
Copy link
Member

kevmoo commented Apr 1, 2019

I think this is by design. @munificent will have thoughts

@a14n
Copy link
Contributor Author

a14n commented Apr 1, 2019

I think this is by design.

As this looks similar to #382 (that is not closed) this change seems doable.

(Context: I try to apply dartfmt on flutter/examples and see what's the smallest set of changes to be done to use it (or a small customized version) on flutter examples. Ideally those changes should be part of the current dartfmt to limit divergencies)

@a14n a14n force-pushed the expression-function-as-arg branch from 71156cd to f6bdf13 Compare April 3, 2019 16:34
@a14n
Copy link
Contributor Author

a14n commented Apr 3, 2019

The same behaviour could be done on function declarations and method declarations (I did it in a14n@7a51442 - happy to include it in this PR).

@munificent
Copy link
Member

I'm a little swamped with other stuff to take a look at these right now, but I'll try to circle back when I can.

I have some vague concerns that this will do bad things on more complex cases, so I'll need to run it on a bigger corpus and see what the results look like. The output you have here looks nice to me. It's mostly a question of making sure it doesn't regress other things.

@a14n
Copy link
Contributor Author

a14n commented Apr 5, 2019

The only concern I have is when the function split after =>:

    onTap: () {
      Navigator.of(context).push(CupertinoPageRoute<void>(
        title: colorName,
        builder_______________________________________________: (BuildContext context) =>
            Tab1ItemPage(
          color: color,
          colorName: colorName,
          index: index,
        ),
      ));
    },

Ideally in this case I'd like to have:

    onTap: () {
      Navigator.of(context).push(CupertinoPageRoute<void>(
        title: colorName,
        builder_______________________________________________: (BuildContext context) =>
            Tab1ItemPage(
              color: color,
              colorName: colorName,
              index: index,
            ),
      ));
    },

But I don't manage to write the good code to handle this case and to produce what I'd like :-(

@kasperpeulen
Copy link

I think best would be this:

    onTap: () {
      Navigator.of(context).push(CupertinoPageRoute<void>(
        title: colorName,
        builder_______________________________________________: (BuildContext context) =>
          Tab1ItemPage(
            color: color,
            colorName: colorName,
            index: index,
          ),
      ));
    },

@a14n
Copy link
Contributor Author

a14n commented May 15, 2019

@munificent friendly reminder

@munificent
Copy link
Member

I tested this out on a big corpus locally. Overall, I like the output. However, like you note, the results are pretty weird when it needs to indent before the body of the function, as in:

  function(
    (parameter1, parameter2,
            parameter3) =>
        P(
      p,
    ),
  );

Cases like this seem pretty rare in the wild though, so I think it's still worth doing.

@munificent munificent merged commit f6bdf13 into dart-lang:master Jun 4, 2019
@a14n a14n deleted the expression-function-as-arg branch June 4, 2019 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants