Merge pull request #762 from dart-lang/set-literals
Add support for set literals.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a5a79df..c28fa53 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 1.2.2
+
+* Support set literals (#751).
+
# 1.2.1
* Add `--fix-function-typedefs` to convert the old typedef syntax for function
diff --git a/bin/format.dart b/bin/format.dart
index 2aba2fd..f3ee673 100644
--- a/bin/format.dart
+++ b/bin/format.dart
@@ -15,7 +15,7 @@
import 'package:dart_style/src/style_fix.dart';
// Note: The following line of code is modified by tool/grind.dart.
-const version = "1.2.1";
+const version = "1.2.2";
void main(List<String> args) {
var parser = new ArgParser(allowTrailingOptions: true);
diff --git a/lib/src/dart_formatter.dart b/lib/src/dart_formatter.dart
index afd0626..448e13e 100644
--- a/lib/src/dart_formatter.dart
+++ b/lib/src/dart_formatter.dart
@@ -114,6 +114,7 @@
// Parse it.
var parser = new Parser(stringSource, errorListener);
parser.enableOptionalNewAndConst = true;
+ parser.enableSetLiterals = true;
AstNode node;
if (source.isCompilationUnit) {
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 1233b01..29f014d 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -1834,6 +1834,11 @@
newline();
}
+ visitSetLiteral(SetLiteral node) {
+ _visitCollectionLiteral(
+ node, node.leftBracket, node.elements, node.rightBracket);
+ }
+
visitShowCombinator(ShowCombinator node) {
_visitCombinator(node.keyword, node.shownNames);
}
diff --git a/pubspec.lock b/pubspec.lock
index c6f0505..31ad51f 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -14,7 +14,7 @@
name: args
url: "https://pub.dartlang.org"
source: hosted
- version: "1.5.0"
+ version: "1.5.1"
async:
dependency: "direct dev"
description:
@@ -70,7 +70,7 @@
name: csslib
url: "https://pub.dartlang.org"
source: hosted
- version: "0.14.5"
+ version: "0.14.6"
front_end:
dependency: transitive
description:
@@ -105,7 +105,7 @@
name: http
url: "https://pub.dartlang.org"
source: hosted
- version: "0.11.3+17"
+ version: "0.12.0"
http_multi_server:
dependency: transitive
description:
@@ -203,7 +203,7 @@
name: package_resolver
url: "https://pub.dartlang.org"
source: hosted
- version: "1.0.4"
+ version: "1.0.6"
path:
dependency: "direct main"
description:
@@ -273,7 +273,7 @@
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
- version: "0.10.7"
+ version: "0.10.8"
source_span:
dependency: "direct main"
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index 5ec4fbd..de496ce 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
name: dart_style
# Note: See tool/grind.dart for how to bump the version.
-version: 1.2.1
+version: 1.2.2
author: Dart Team <misc@dartlang.org>
description: Opinionated, automatic Dart source code formatter.
homepage: https://github.com/dart-lang/dart_style
diff --git a/test/comments/sets.stmt b/test/comments/sets.stmt
new file mode 100644
index 0000000..6d310c6
--- /dev/null
+++ b/test/comments/sets.stmt
@@ -0,0 +1,108 @@
+40 columns |
+>>> indented line comment (dartbug.com/16383)
+var set = <int>{
+ // comment
+};
+<<<
+var set = <int>{
+ // comment
+};
+>>> line comment on opening line
+var set = <int>{ // comment
+};
+<<<
+var set = <int>{
+ // comment
+};
+>>> indented block comment
+var set = <int>{
+ /* comment */
+};
+<<<
+var set = <int>{
+ /* comment */
+};
+>>> block comment with trailing newline
+var set = <int>{/* comment */
+};
+<<<
+var set = <int>{
+ /* comment */
+};
+>>> block comment with leading newline
+var set = <int>{
+ /* comment */};
+<<<
+var set = <int>{
+ /* comment */
+};
+>>> inline block comment
+var set = <int>{ /* comment */ };
+<<<
+var set = <int>{/* comment */};
+>>> multiple comments on opening line
+var set = <int>{ /* first */ // second
+};
+<<<
+var set = <int>{
+ /* first */ // second
+};
+>>> multiple inline block comments
+var set = <int>{ /* 1 */ /* 2 */ /* 3 */ };
+<<<
+var set =
+ <int>{/* 1 */ /* 2 */ /* 3 */};
+>>> multiline trailing block comment
+var set = <int>{ /* comment
+*/ };
+<<<
+var set = <int>{
+ /* comment
+*/
+};
+>>> line comment between items
+var set = {'a', 'b', // comment
+ 'c', 'd'};
+<<<
+var set = {
+ 'a', 'b', // comment
+ 'c', 'd'
+};
+>>> line comments after last item
+var set = {'a', 'b' // 1
+ // 2
+};
+<<<
+var set = {
+ 'a', 'b' // 1
+ // 2
+};
+>>> line comments after trailing comma
+var set = {'a', 'b', // 1
+ // 2
+};
+<<<
+var set = {
+ 'a', 'b', // 1
+ // 2
+};
+>>> inside set literal
+var set = {
+ // comment
+ 'foo'};
+<<<
+var set = {
+ // comment
+ 'foo'
+};
+>>> remove blank line before beginning of body
+var set = <int>{
+
+
+
+ // comment
+};
+<<<
+var set = <int>{
+ // comment
+};
\ No newline at end of file
diff --git a/test/splitting/sets.stmt b/test/splitting/sets.stmt
new file mode 100644
index 0000000..743498a
--- /dev/null
+++ b/test/splitting/sets.stmt
@@ -0,0 +1,173 @@
+40 columns |
+>>> empty set
+var s = <int> { };
+<<<
+var s = <int>{};
+>>> exactly 40 characters
+var s = {first, second, third, forth__};
+<<<
+var s = {first, second, third, forth__};
+>>>
+var s = {first, second, third, fourth, fifth, sixth};
+<<<
+var s = {
+ first,
+ second,
+ third,
+ fourth,
+ fifth,
+ sixth
+};
+>>> splits outer sets even if they fit
+var s = {a, {b, c}, d, {},
+ e, {f, {g, h} } };
+<<<
+var s = {
+ a,
+ {b, c},
+ d,
+ {},
+ e,
+ {
+ f,
+ {g, h}
+ }
+};
+>>> split indirect outer
+var s = {a, function({b, inner})};
+<<<
+var s = {
+ a,
+ function({b, inner})
+};
+>>> empty literal does not force outer split
+var s = {a, <int>{}, b, [], c, () {}};
+<<<
+var s = {a, <int>{}, b, [], c, () {}};
+>>> nested split set
+var s = {first, 1, second, {third, fourth}, fifth, 5, nested, {sixth, seventh, eighth, nine,
+ tenth, eleventh}};
+<<<
+var s = {
+ first,
+ 1,
+ second,
+ {third, fourth},
+ fifth,
+ 5,
+ nested,
+ {
+ sixth,
+ seventh,
+ eighth,
+ nine,
+ tenth,
+ eleventh
+ }
+};
+>>> force multi-line because of contained block
+var s = {first, 1, fn, () {"fn";},third,fourth};
+<<<
+var s = {
+ first,
+ 1,
+ fn,
+ () {
+ "fn";
+ },
+ third,
+ fourth
+};
+>>> containing comments
+var s = {first, one /* bang */, second, two};
+<<<
+var s = {
+ first,
+ one /* bang */,
+ second,
+ two
+};
+>>> const
+var set = const {"foo", "bar", "fuz", null};
+<<<
+var set =
+ const {"foo", "bar", "fuz", null};
+>>> trailing comma forces split
+var set = {"foo", "bar" , };
+<<<
+var set = {
+ "foo",
+ "bar",
+};
+>>> trailing comma multiline
+var set = {"foo", "bar", "fuzzy", null , };
+<<<
+var set = {
+ "foo",
+ "bar",
+ "fuzzy",
+ null,
+};
+>>> preserve newlines in sets containing a line comment
+var set = {
+ // yeah
+ a,b,c,d,
+ e,f,g,h
+};
+<<<
+var set = {
+ // yeah
+ a, b, c, d,
+ e, f, g, h
+};
+>>> wrap between elements even when newlines are preserved
+var set = {
+ // yes
+ first, "value", second, "value", third, "value",
+
+ fourth, "value", fifth, "value", sixth, "value", seventh, "value"
+};
+<<<
+var set = {
+ // yes
+ first, "value", second, "value",
+ third, "value",
+
+ fourth, "value", fifth, "value",
+ sixth, "value", seventh, "value"
+};
+>>> ignore line comment after the "}"
+var set = {
+ a,b,c,
+ d
+} // comment
+;
+<<<
+var set = {a, b, c, d} // comment
+ ;
+>>> preserves one blank line between elements
+var set = {
+
+
+ element,
+
+
+
+ // comment
+ element,
+
+
+
+ element
+
+
+};
+<<<
+var set = {
+ element,
+
+ // comment
+ element,
+
+ element
+};
\ No newline at end of file
diff --git a/test/whitespace/expressions.stmt b/test/whitespace/expressions.stmt
index 4cf871a..c1ed6b2 100644
--- a/test/whitespace/expressions.stmt
+++ b/test/whitespace/expressions.stmt
@@ -44,6 +44,10 @@
< int,int >{ };
<<<
<int, int>{};
+>>> generic set literal
+< int >{ };
+<<<
+<int>{};
>>> unqualified symbol
var x = #foo;
<<<