Skip to content

Add new How-to article on automatic formatting of Flutter code - #322

Merged
mit-mit merged 6 commits into
flutter:masterfrom
mit-mit:master
Nov 8, 2016
Merged

mit-mit merged 6 commits into
flutter:masterfrom
mit-mit:master

Conversation

@mit-mit

@mit-mit mit-mit commented Nov 7, 2016

Copy link
Copy Markdown
Member

@mit-mit

mit-mit commented Nov 7, 2016

Copy link
Copy Markdown
Member Author

Hi @sethladd, please review

@mit-mit

mit-mit commented Nov 7, 2016

Copy link
Copy Markdown
Member Author

We should remove https://github.com/flutter/flutter/wiki/Early-Access%3A-Auto-Formatting once this lands

@sethladd sethladd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Comment thread formatting.md Outdated
* TOC Placeholder
{:toc}

## Flutter formatting guidelines

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this from this article. It really belongs in the CONTRIBUTING.md or similar document. This isn't useful for most people, only really for contributors to the SDK itself.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread formatting.md Outdated

The alternative is often tiring formatting debates during code reviews, where
time may be better spent on code behavior rather than code style. (*Note*:
Automatically formatting code may in some hard cases lead to different results

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop this parens. It's an interesting link but not in the critical path to enabling our developers to use the formatter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread formatting.md Outdated
### Automatically formatting code in IntelliJ

Automatic formatting of code is supported in IntelliJ if you have the
`dart`-plugin (see [IntelliJ setup](/setup/#flutter-intellij-ide-plugins)).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need the - in dart-plugin ? Or, broaden the backticks? What is the formal name of the plugin?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formal name is Dart -- fixed the caps, but the tics are correct

Comment thread formatting.md
Automatic formatting of code is supported in IntelliJ if you have the
`dart`-plugin (see [IntelliJ setup](/setup/#flutter-intellij-ide-plugins)).

To automatically format the code in the current source code window, right-click

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right click on what?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread formatting.md Outdated
`dart`-plugin (see [IntelliJ setup](/setup/#flutter-intellij-ide-plugins)).

To automatically format the code in the current source code window, right-click
and select `Reformat with Dart style`. You can a keyboard shortcut to this in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a word after "can" ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread formatting.md Outdated

### Automatically formatting code in the CLI

You can also automatically format code in the CLI (command line interface) using

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/in the CLI.../with the flutter format command.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread formatting.md
-h, --help Print this usage information.
```

### Using 'trailing commas'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should put this at top? This is the critical part.

Comment thread formatting.md

Here is an example of automatically formatted code *with* trailing commas:

![Automatically formatted code with trailing commas](/images/intellij/trailing-comma-with.png)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When committing PNGs, please use a PNG optimizer like optipng (installable by homebrew)

Comment thread formatting.md Outdated
### Using 'trailing commas'

Flutter code often involves building fairly deep tree-shaped data structures,
for example in a `build`-method. The automatic code formatting described above

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the -

Comment thread formatting.md Outdated
Flutter code often involves building fairly deep tree-shaped data structures,
for example in a `build`-method. The automatic code formatting described above
is shared with other Dart code, and per default may lead to sub-optimal
formatting of these deep structures.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop this last sentence. I think the main point for this section is:

  • use trailing commas for better nesting
  • here is a before and after. :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@mit-mit
mit-mit merged commit a882abc into flutter:master Nov 8, 2016
@sethladd

sethladd commented Nov 8, 2016

Copy link
Copy Markdown
Contributor

Thanks for the contribution, but please wait for a LGTM from someone. Unless it's a truly trivial change, then we can do a TBR.

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

Successfully merging this pull request may close these issues.

2 participants