Support "covariant" modifier.
Fix #572.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cb432b6..8795385 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 0.2.15
+
+* Support `covariant` modifier on methods.
+
# 0.2.14
* Update to analyzer 0.29.3. This should make dart_style a little more resilient
diff --git a/bin/format.dart b/bin/format.dart
index a003f8e..b43bf5d 100644
--- a/bin/format.dart
+++ b/bin/format.dart
@@ -14,7 +14,7 @@
import 'package:dart_style/src/source_code.dart';
// Note: The following line of code is modified by tool/grind.dart.
-const version = "0.2.14";
+const version = "0.2.15";
void main(List<String> args) {
var parser = new ArgParser(allowTrailingOptions: true);
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 4a77004..2370d2b 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -859,12 +859,14 @@
_simpleStatement(node, () {
modifier(node.staticKeyword);
+ modifier(node.covariantKeyword);
visit(node.fields);
});
}
visitFieldFormalParameter(FieldFormalParameter node) {
visitParameterMetadata(node.metadata, () {
+ modifier(node.covariantKeyword);
token(node.keyword, after: space);
visit(node.type, after: space);
token(node.thisKeyword);
@@ -1104,6 +1106,7 @@
visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
visitParameterMetadata(node.metadata, () {
+ modifier(node.covariantKeyword);
visit(node.returnType, after: space);
// Try to keep the function's parameters with its name.
@@ -1489,6 +1492,7 @@
visitSimpleFormalParameter(SimpleFormalParameter node) {
visitParameterMetadata(node.metadata, () {
+ modifier(node.covariantKeyword);
modifier(node.keyword);
visit(node.type, after: space);
visit(node.identifier);
diff --git a/pubspec.lock b/pubspec.lock
index 11160c8..2880aa1 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -6,7 +6,7 @@
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
- version: "0.29.3"
+ version: "0.29.5"
ansicolor:
description:
name: ansicolor
@@ -54,7 +54,7 @@
name: collection
url: "https://pub.dartlang.org"
source: hosted
- version: "1.12.0"
+ version: "1.13.0"
convert:
description:
name: convert
@@ -108,7 +108,7 @@
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
- version: "3.0.3"
+ version: "3.1.1"
isolate:
description:
name: isolate
@@ -156,7 +156,7 @@
name: node_preamble
url: "https://pub.dartlang.org"
source: hosted
- version: "1.0.0"
+ version: "1.2.0"
package_config:
description:
name: package_config
@@ -174,7 +174,7 @@
name: path
url: "https://pub.dartlang.org"
source: hosted
- version: "1.4.0"
+ version: "1.4.1"
plugin:
description:
name: plugin
@@ -198,13 +198,13 @@
name: scheduled_test
url: "https://pub.dartlang.org"
source: hosted
- version: "0.12.7"
+ version: "0.12.9"
shelf:
description:
name: shelf
url: "https://pub.dartlang.org"
source: hosted
- version: "0.6.7+1"
+ version: "0.6.7+2"
shelf_packages_handler:
description:
name: shelf_packages_handler
@@ -228,19 +228,19 @@
name: source_map_stack_trace
url: "https://pub.dartlang.org"
source: hosted
- version: "1.1.3"
+ version: "1.1.4"
source_maps:
description:
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
- version: "0.10.1+2"
+ version: "0.10.2"
source_span:
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
- version: "1.3.0"
+ version: "1.3.1"
stack_trace:
description:
name: stack_trace
@@ -252,7 +252,7 @@
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
- version: "1.5.0"
+ version: "1.6.0"
string_scanner:
description:
name: string_scanner
@@ -270,7 +270,7 @@
name: test
url: "https://pub.dartlang.org"
source: hosted
- version: "0.12.17"
+ version: "0.12.18+1"
typed_data:
description:
name: typed_data
diff --git a/pubspec.yaml b/pubspec.yaml
index da0a907..ad7f415 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,13 +1,13 @@
name: dart_style
# Note: See tool/grind.dart for how to bump the version.
-version: 0.2.14
+version: 0.2.15
author: Dart Team <misc@dartlang.org>
description: Opinionated, automatic Dart source code formatter.
homepage: https://github.com/dart-lang/dart_style
environment:
sdk: ">=1.8.0 <2.0.0"
dependencies:
- analyzer: '^0.29.3'
+ analyzer: '^0.29.5'
args: '>=0.12.1 <0.14.0'
path: '>=1.0.0 <2.0.0'
source_span: '>=1.1.1 <2.0.0'
diff --git a/test/formatter_test.dart b/test/formatter_test.dart
index 0960607..deb725c 100644
--- a/test/formatter_test.dart
+++ b/test/formatter_test.dart
@@ -186,6 +186,12 @@
expectedOutput += lines[i] + "\n";
}
+ // TODO(rnystrom): Stop skipping these tests when possible.
+ if (description.contains("(skip:")) {
+ print("skipping $description");
+ continue;
+ }
+
test(description, () {
var isCompilationUnit = p.extension(entry.path) == ".unit";
diff --git a/test/splitting/members.unit b/test/splitting/members.unit
index cb59d75..ebca8c5 100644
--- a/test/splitting/members.unit
+++ b/test/splitting/members.unit
@@ -25,4 +25,15 @@
class Foo {
VeryLongTypeAnnotation
set veryLongSetter(v) {}
-}
\ No newline at end of file
+}
+>>> do not split after "covariant" in field (at least for now) (skip: published version of analyzer doesn't support 'covariant yet')
+class Foo {
+ covariant var soMuchSoVeryLongFieldNameHere;
+ covariant VeryLongTypeAnnotation field;
+}
+<<<
+class Foo {
+ covariant var soMuchSoVeryLongFieldNameHere;
+ covariant VeryLongTypeAnnotation
+ field;
+}
diff --git a/test/splitting/parameters.unit b/test/splitting/parameters.unit
index 56d43f2..5ac592d 100644
--- a/test/splitting/parameters.unit
+++ b/test/splitting/parameters.unit
@@ -13,4 +13,34 @@
<<<
method(int firstArgument,
int argumentTwo) =>
- "very long body that must wrap";
\ No newline at end of file
+ "very long body that must wrap";
+>>> split before "covariant" (skip: published version of analyzer doesn't support 'covariant yet')
+class A {
+ longMethod(covariant parameterNameHere) {}
+}
+<<<
+class A {
+ longMethod(
+ covariant parameterNameHere) {}
+}
+>>> split before "covariant" with multiple parameters (skip: published version of analyzer doesn't support 'covariant yet')
+class A {
+ longMethod(covariant first, second, covariant int third(parameter), fourth) {}
+}
+<<<
+class A {
+ longMethod(
+ covariant first,
+ second,
+ covariant int third(parameter),
+ fourth) {}
+}
+>>> never split after "covariant" (at least for now) (skip: published version of analyzer doesn't support 'covariant yet')
+class A {
+ longMethod(covariant int veryLongParameterNameWow) {}
+}
+<<<
+class A {
+ longMethod(
+ covariant int veryLongParameterNameWow) {}
+}
\ No newline at end of file
diff --git a/test/whitespace/classes.unit b/test/whitespace/classes.unit
index 03d81d9..3e088fa 100644
--- a/test/whitespace/classes.unit
+++ b/test/whitespace/classes.unit
@@ -99,4 +99,17 @@
set f(value) {}
set g(value) => null;
var h = 1;
+}
+>>> covariant field (skip: published version of analyzer doesn't support 'covariant yet')
+class Foo {
+ covariant var bar;
+ covariant int baz;
+@wat covariant int zoop;
+}
+<<<
+class Foo {
+ covariant var bar;
+ covariant int baz;
+ @wat
+ covariant int zoop;
}
\ No newline at end of file
diff --git a/test/whitespace/metadata.unit b/test/whitespace/metadata.unit
index 08a3966..3d8abb3 100644
--- a/test/whitespace/metadata.unit
+++ b/test/whitespace/metadata.unit
@@ -231,4 +231,11 @@
@Other
@Third
longParameter2,
-) {}
\ No newline at end of file
+) {}
+>>> keep "covariant" with parameter
+function(@Annotation @VeryLongMetadataAnnotation covariant longParameter) {}
+<<<
+function(
+ @Annotation
+ @VeryLongMetadataAnnotation
+ covariant longParameter) {}
\ No newline at end of file
diff --git a/test/whitespace/methods.unit b/test/whitespace/methods.unit
index e70b8ef..35c09ca 100644
--- a/test/whitespace/methods.unit
+++ b/test/whitespace/methods.unit
@@ -34,4 +34,26 @@
var file = new File(path);
return file;
}
+}
+>>> covariant (skip: published version of analyzer doesn't support 'covariant yet')
+class A {
+ pos( covariant int a,covariant b );
+ opt([ covariant int a,covariant b ]);
+ named({ covariant int a,covariant b });
+ fn( covariant int f(bool b));
+}
+<<<
+class A {
+ pos(covariant int a, covariant b);
+ opt([covariant int a, covariant b]);
+ named({covariant int a, covariant b});
+ fn(covariant int f(bool b));
+}
+>>> covariant in initializing formal (not valid, but dartfmt should accept) (skip: published version of analyzer doesn't support 'covariant yet')
+class A {
+ A( covariant this.foo);
+}
+<<<
+class A {
+ A(covariant this.foo);
}
\ No newline at end of file