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

Formatter for Flutter (or, tree-aware code) #2025

Open
sethladd opened this issue Feb 19, 2016 · 20 comments
Open

Formatter for Flutter (or, tree-aware code) #2025

sethladd opened this issue Feb 19, 2016 · 20 comments
Labels
c: new feature Nothing broken; request for a new capability P3 Issues that are less important to the Flutter project team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels. triaged-tool Triaged by Flutter Tool team

Comments

@sethladd
Copy link
Contributor

dartfmt is a really great utility, but it doesn't know about code that is trying to represent a tree. Which, is what Flutter does a lot of :)

We would like an automatic formatter that knows that Flutter code has a lot of tree-like structures, and retains a formatting style that makes tree-like structures easy to read.

Ideally, we'd then use this formatter in our CLI and Atom tools.

@sethladd sethladd added c: new feature Nothing broken; request for a new capability tool Affects the "flutter" command-line tool. See also t: labels. labels Feb 19, 2016
@sethladd sethladd added this to the Flutter 1.0 milestone Feb 19, 2016
@eseidelGoogle
Copy link
Contributor

@Hixie do you have a list/doc of specific wishes for a Flutter formatter?

@Hixie
Copy link
Contributor

Hixie commented Mar 5, 2016

I think dart-lang/dart_style#442 is the main list right now.

@sethladd
Copy link
Contributor Author

See also #4509 which talks about formatting the codelab.

@Hixie
Copy link
Contributor

Hixie commented Jun 11, 2016

@abarth is the work you did on this available?

@abarth
Copy link
Contributor

abarth commented Jun 11, 2016

@eseidelGoogle
Copy link
Contributor

Note that these days dart-fmt supports trailing commas which has answered at least the most common complaint from Flutter customers, e.g.

return new MyWidget(
  foo: foo,
  bar: bar, // This trailing comma causes dart-fmt not to collapse this into one line.
);

@HansMuller
Copy link
Contributor

Does dart-fmt DTRT with if then statements that lack curly braces?

if (foo)
  bar();

I count over 9000 occurrences of this in our repo, about 1800 in packages/flutter.

@Hixie
Copy link
Contributor

Hixie commented Jan 27, 2017

It does something that IMHO is less readable than our style. (removes the newline and wraps)

@eseidelGoogle
Copy link
Contributor

I think I'm going to file a new bug that more clearly states our goal. We just want automated formatting for Flutter, that doesn't make us feel like we're compromising too far from our readability goals expressed in our style guide.

@sethladd
Copy link
Contributor Author

sethladd commented Feb 3, 2017

I'd be more specific:

"We just want automated formatting for Flutter's SDK code, which is distinct from the code our users will write"

This issue is written from the perspective of our users: they want formatting of tree-related code, often found in build() methods. We have that now, with trailing commas.

I believe we can close this issue, and open two issues if they don't exist:

  • One issue with the dartfmt utility, asking for a formatting solution that doesn't require trailing commas

  • One issue with the editor/analyzer, asking for "auto-insert of trailing commas"

@a14n
Copy link
Contributor

a14n commented Mar 27, 2017

Is the final plan to use dartfmt with trailing commas on flutter codebase?

@Hixie
Copy link
Contributor

Hixie commented Mar 27, 2017

No, that's not sufficient yet.

@rock3r
Copy link
Contributor

rock3r commented Mar 19, 2018

Hello, any update on this? I would love to be able to call flutter format -n --set-exit-if-changed (dry run, set exit code) as part of my CI pipeline to assert that the code is properly formatted. Currently there's no way to run format without the flag. See #12797 for details.

@willlarche
Copy link
Member

Any update on this?

@Hixie Hixie modified the milestones: Stretch Goals, New Stretch Goals Jan 7, 2020
@jmagman jmagman added this to Awaiting triage in Tools - team support review via automation Jan 13, 2020
@zanderso zanderso moved this from Awaiting triage to Engineer reviewed in Tools - team support review Jan 17, 2020
@kf6gpe kf6gpe added the P3 Issues that are less important to the Flutter project label May 29, 2020
@kf6gpe kf6gpe modified the milestone: Stretch Goals Jun 1, 2020
@kf6gpe kf6gpe removed this from the Stretch Goals milestone Jun 1, 2020
@Hixie Hixie removed this from the [DEPRECATED] Stretch Goals milestone Jun 16, 2020
@kf6gpe kf6gpe removed this from the [DEPRECATED] Stretch Goals milestone Jul 7, 2020
@kf6gpe kf6gpe modified the milestone: [DEPRECATED] Stretch Goals Jul 22, 2020
@Hixie Hixie removed this from the - milestone Aug 17, 2020
@venkatd
Copy link

venkatd commented Mar 30, 2021

Hi, I plan to contribute to Flutter in the coming weeks for the first time. Is there some configuration I can set in my editor to format according to the official guidelines? If not, what process do developers on the Flutter team follow to format their code?

@guidezpl
Copy link
Member

guidezpl commented Apr 2, 2021

Hi, we currently format "by hand". It's not too far off from what the formatter does, save for a few things such as alignment and (not) wrapping lines for readibility. @eseidelGoogle Did you file the issue you mentioned in #2025 (comment)?

@mit-mit
Copy link
Member

mit-mit commented Mar 20, 2024

@munificent can we consider this done with your formatter re-work?

@munificent
Copy link
Contributor

Well, the new formatter isn't done yet (dart-lang/dart_style#1403), but once it is, yes, I think it will qualify as addressing this. :)

@sethladd
Copy link
Contributor Author

Excited!

@munificent
Copy link
Contributor

Not as excited as I am to see you back on Flutter! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability P3 Issues that are less important to the Flutter project team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels. triaged-tool Triaged by Flutter Tool team
Projects
Tools - team support review
  
Engineer reviewed
Development

No branches or pull requests