Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit d312ffa

Browse files
committed
1 parent 7390e5a commit d312ffa

File tree

1 file changed

+92
-4
lines changed

1 file changed

+92
-4
lines changed

src/site/articles/style-guide/index.markdown

+92-4
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ bool convertToBool(arg) {
606606
#### DO name types using `UpperCamelCase`.
607607
{:.no_toc}
608608

609-
Classes and typedefs should capitalize the first letter of each word (including
610-
the first word), and use no separators.
609+
Classes, enums, and typedefs should capitalize the first letter of each word
610+
(including the first word), and use no separators.
611611

612612
<div class="good" markdown="1">
613613
{% prettify dart %}
@@ -628,7 +628,8 @@ typedef num Adder(num x, num y);
628628
{:.no_toc}
629629
<!-- https://github.com/dart-lang/www.dartlang.org/issues/831 -->
630630

631-
In new code, use `lowerCamelCase` for constant variables.
631+
In new code, use `lowerCamelCase` for constant variables, including enum
632+
values.
632633

633634
In existing code that uses `ALL_CAPS_WITH_UNDERSCORES` for constants, you
634635
may continue to use all caps to stay consistent.
@@ -1009,7 +1010,7 @@ compact. Do you really need to call that class
10091010
`AbstractWidgetFactoryManagerBuilder`?
10101011

10111012

1012-
#### DO place the operator on the preceding line in a multi-line expression.
1013+
#### DO place binary operators on the preceding line in a multi-line expression.
10131014
{:.no_toc}
10141015

10151016
There are valid arguments for both styles but most of our code seems to go this
@@ -1042,6 +1043,31 @@ bobLikes()
10421043
</div>
10431044

10441045

1046+
#### DO place ternary operators on the next line in a multi-line expression.
1047+
{:.no_toc}
1048+
1049+
Also, if you break the line before one of the operators, prefer breaking
1050+
around both.
1051+
1052+
<div class="good">
1053+
{% prettify dart %}
1054+
return someCondition
1055+
? whenTrue
1056+
: whenFalse;
1057+
{% endprettify %}
1058+
</div>
1059+
1060+
<div class="bad">
1061+
{% prettify dart %}
1062+
return someCondition ?
1063+
whenTrue :
1064+
whenFalse;
1065+
return someCondition
1066+
? whenTrue : whenFalse;
1067+
{% endprettify %}
1068+
</div>
1069+
1070+
10451071
#### DO place the `.` on the next line in a multi-line expression.
10461072
{:.no_toc}
10471073

@@ -1527,3 +1553,65 @@ followed by more alphanumeric text, the `{}` can and should be omitted.
15271553
"Wear your wildest ${decade}'s outfit."
15281554
{% endprettify %}
15291555
</div>
1556+
1557+
1558+
## Ordering
1559+
1560+
#### DO specify dart: imports, then package: imports, and then relative imports
1561+
{:.no_toc}
1562+
1563+
Separate import sections from each other with a single blank line.
1564+
1565+
Within each section, prefer sorting alphabetically. If you use a
1566+
`package:` import to import from your own package, consider putting
1567+
that import in the relative import section.
1568+
1569+
<div class="good">
1570+
{% prettify dart %}
1571+
import 'dart:async';
1572+
import 'dart:convert' show JSON;
1573+
import 'dart:html';
1574+
1575+
import 'package:bar/bar.dart'
1576+
import 'package:bar/foo.dart'
1577+
import 'package:foo/bar.dart'
1578+
1579+
import 'a.dart';
1580+
{% endprettify %}
1581+
</div>
1582+
1583+
<div class="bad">
1584+
{% prettify dart %}
1585+
import 'dart:html';
1586+
import 'dart:async';
1587+
import 'dart:convert' show JSON;
1588+
1589+
import 'a.dart';
1590+
import 'package:bar/bar.dart'
1591+
import 'package:foo/bar.dart'
1592+
import 'package:bar/foo.dart'
1593+
{% endprettify %}
1594+
</div>
1595+
1596+
#### PREFER specifying exports in a separate section after all imports
1597+
{:.no_toc}
1598+
1599+
Put a single blank line above the exports section.
1600+
1601+
<div class="good">
1602+
{% prettify dart %}
1603+
import 'src/error.dart';
1604+
import 'src/string_source.dart';
1605+
1606+
export 'src/error.dart';
1607+
{% endprettify %}
1608+
</div>
1609+
1610+
<div class="bad">
1611+
{% prettify dart %}
1612+
import 'src/error.dart';
1613+
export 'src/error.dart';
1614+
1615+
import 'src/string_source.dart';
1616+
{% endprettify %}
1617+
</div>

0 commit comments

Comments
 (0)