Format `external` and `abstract` on variables.
Fix #946.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a865194..ae83093 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
* Split help into verbose and non-verbose lists (#938).
* Don't crash when non-ASCII whitespace is trimmed (#901).
* Split all conditional expressions (`?:`) when they are nested (#927).
+* Handle `external` and `abstract` fields and variables (#946).
# 1.3.6
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 04a2bee..1f63c6c 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -1425,7 +1425,9 @@
visitMetadata(node.metadata);
_simpleStatement(node, () {
+ modifier(node.externalKeyword);
modifier(node.staticKeyword);
+ modifier(node.abstractKeyword);
modifier(node.covariantKeyword);
visit(node.fields);
});
@@ -2613,6 +2615,7 @@
visitMetadata(node.metadata);
_simpleStatement(node, () {
+ modifier(node.externalKeyword);
visit(node.variables);
});
}
diff --git a/pubspec.lock b/pubspec.lock
index eea1964..41681b6 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -7,14 +7,14 @@
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
- version: "2.0.0"
+ version: "8.0.0"
analyzer:
dependency: "direct main"
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
- version: "0.39.5"
+ version: "0.40.0"
archive:
dependency: transitive
description:
@@ -56,7 +56,7 @@
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
- version: "0.1.3+2"
+ version: "0.1.4"
collection:
dependency: transitive
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index 3d8b8ed..9850217 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -29,3 +29,8 @@
executables:
dartfmt: format
dartformat: format # Allow the old name for compatibility.
+
+# TODO(rnystrom): Remove this and change the normal dependency on analyzer to
+# this when a version of test that supports analyzer-0.40.0 is published.
+dependency_overrides:
+ analyzer: ^0.40.0
diff --git a/test/splitting/members.unit b/test/splitting/members.unit
index ecde98f..68af26c 100644
--- a/test/splitting/members.unit
+++ b/test/splitting/members.unit
@@ -26,7 +26,7 @@
VeryLongTypeAnnotation
set veryLongSetter(v) {}
}
->>> do not split after "covariant" in field (at least for now)
+>>> do not split after "covariant" in field
class Foo {
covariant var soMuchSoVeryLongFieldNameHere;
covariant VeryLongTypeAnnotation field;
@@ -37,3 +37,25 @@
covariant VeryLongTypeAnnotation
field;
}
+>>> do not split after "external" in field
+class Foo {
+ external var soMuchSoVeryLongFieldNameHere;
+ external SuperLongTypeAnnotation field;
+}
+<<<
+class Foo {
+ external var soMuchSoVeryLongFieldNameHere;
+ external SuperLongTypeAnnotation
+ field;
+}
+>>> do not split after "abstract" in field
+class Foo {
+ abstract var soMuchSoVeryLongFieldNameHere;
+ abstract SuperLongTypeAnnotation field;
+}
+<<<
+class Foo {
+ abstract var soMuchSoVeryLongFieldNameHere;
+ abstract SuperLongTypeAnnotation
+ field;
+}
\ No newline at end of file
diff --git a/test/whitespace/classes.unit b/test/whitespace/classes.unit
index f306f5a..a4ea79f 100644
--- a/test/whitespace/classes.unit
+++ b/test/whitespace/classes.unit
@@ -144,4 +144,16 @@
late final int i;
late int i;
late var i;
+}
+>>> abstract fields
+class Foo {
+abstract covariant var a , b ;
+ abstract final int c;
+ abstract int i;
+}
+<<<
+class Foo {
+ abstract covariant var a, b;
+ abstract final int c;
+ abstract int i;
}
\ No newline at end of file
diff --git a/test/whitespace/external.unit b/test/whitespace/external.unit
new file mode 100644
index 0000000..52abb83
--- /dev/null
+++ b/test/whitespace/external.unit
@@ -0,0 +1,45 @@
+40 columns |
+>>> top-level function
+ external
+void
+printToConsole(line);
+<<<
+external void printToConsole(line);
+>>> top-level variable
+ external final a , b ;
+ external final Set < int > a , b ;
+ external var a ;
+ external List < int > a ;
+<<<
+external final a, b;
+external final Set<int> a, b;
+external var a;
+external List<int> a;
+>>> static field
+class C {
+ external static final a , b ;
+external static final Set < int > a , b ;
+ external static var a ;
+ external static List < int > a ;
+}
+<<<
+class C {
+ external static final a, b;
+ external static final Set<int> a, b;
+ external static var a;
+ external static List<int> a;
+}
+>>> instance field
+class C {
+ external final a , b ;
+ external final Set < String > a , b ;
+ external var a ;
+ external List < int > a ;
+}
+<<<
+class C {
+ external final a, b;
+ external final Set<String> a, b;
+ external var a;
+ external List<int> a;
+}
\ No newline at end of file
diff --git a/test/whitespace/functions.unit b/test/whitespace/functions.unit
index f12fbeb..82db3d1 100644
--- a/test/whitespace/functions.unit
+++ b/test/whitespace/functions.unit
@@ -1,10 +1,4 @@
40 columns |
->>> external
- external
-void
-printToConsole(line);
-<<<
-external void printToConsole(line);
>>> nested functions
x(){y(){z(){}}}
<<<
diff --git a/test/whitespace/metadata.unit b/test/whitespace/metadata.unit
index 1168e89..c25e98f 100644
--- a/test/whitespace/metadata.unit
+++ b/test/whitespace/metadata.unit
@@ -354,4 +354,30 @@
@meta
late int d;
}
+}
+>>> on external variable
+@meta external var x;
+<<<
+@meta
+external var x;
+>>> on external field
+class C {
+ @meta external static var x;
+ @meta external var x;
+}
+<<<
+class C {
+ @meta
+ external static var x;
+ @meta
+ external var x;
+}
+>>> on abstract field
+class C {
+ @meta abstract var x;
+}
+<<<
+class C {
+ @meta
+ abstract var x;
}
\ No newline at end of file