Repository navigation
Add new How-to article on automatic formatting of Flutter code - #322
Conversation
|
Hi @sethladd, please review |
|
We should remove https://github.com/flutter/flutter/wiki/Early-Access%3A-Auto-Formatting once this lands |
| * TOC Placeholder | ||
| {:toc} | ||
|
|
||
| ## Flutter formatting guidelines |
There was a problem hiding this comment.
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.
|
|
||
| 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 |
There was a problem hiding this comment.
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.
| ### 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)). |
There was a problem hiding this comment.
Not sure we need the - in dart-plugin ? Or, broaden the backticks? What is the formal name of the plugin?
There was a problem hiding this comment.
The formal name is Dart -- fixed the caps, but the tics are correct
| 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 |
| `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 |
There was a problem hiding this comment.
missing a word after "can" ?
|
|
||
| ### Automatically formatting code in the CLI | ||
|
|
||
| You can also automatically format code in the CLI (command line interface) using |
There was a problem hiding this comment.
s/in the CLI.../with the flutter format command.
| -h, --help Print this usage information. | ||
| ``` | ||
|
|
||
| ### Using 'trailing commas' |
There was a problem hiding this comment.
I wonder if we should put this at top? This is the critical part.
|
|
||
| Here is an example of automatically formatted code *with* trailing commas: | ||
|
|
||
|  |
There was a problem hiding this comment.
When committing PNGs, please use a PNG optimizer like optipng (installable by homebrew)
| ### 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 |
| 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. |
There was a problem hiding this comment.
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. :)
|
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. |
Fixes flutter/flutter#6418