Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.1.0-dev

* Support generic function references and constructor tear-offs (#1028).

# 2.0.3

* Fix hang when reading from stdin (https://github.com/dart-lang/sdk/issues/46600).
Expand Down
1 change: 1 addition & 0 deletions lib/src/dart_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class DartFormatter {
var featureSet = FeatureSet.fromEnableFlags2(
sdkLanguageVersion: Version(2, 13, 0),
flags: [
'constructor-tearoffs',
'generic-metadata',
'nonfunction-type-aliases',
'triple-shift'
Expand Down
6 changes: 6 additions & 0 deletions lib/src/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,12 @@ class SourceVisitor extends ThrowingAstVisitor {
builder.endSpan();
}

@override
void visitFunctionReference(FunctionReference node) {
visit(node.function);
visit(node.typeArguments);
}

@override
void visitFunctionTypeAlias(FunctionTypeAlias node) {
visitMetadata(node.metadata);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_style
# Note: See tool/grind.dart for how to bump the version.
version: 2.0.3
version: 2.1.0-dev
description: >-
Opinionated, automatic Dart source code formatter.
Provides an API and a CLI tool.
Expand Down
10 changes: 9 additions & 1 deletion test/splitting/mixed.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,12 @@ var longVariableName = identifierSoLongItWraps is SomeClassName;
<<<
var longVariableName =
identifierSoLongItWraps
is SomeClassName;
is SomeClassName;
>>> generic function reference nested inside expression
veryLongFunction(argument, ConstructorTearOff<First, Second, Third, Fourth>, argument);
<<<
veryLongFunction(
argument,
ConstructorTearOff<First, Second,
Third, Fourth>,
argument);
41 changes: 40 additions & 1 deletion test/splitting/type_arguments.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,43 @@ new SomeClass<
fifth,
sixth,
seventh,
eighth);
eighth);
>>> generic instantiation all fit on one line
Foo<A,B,C,D>;
<<<
Foo<A, B, C, D>;
>>> generic instantiation split between args
LongClassName<First, Second, Third, Fourth>;
<<<
LongClassName<First, Second, Third,
Fourth>;
>>> generic instantiation split before first if needed
LongClassName<FirstTypeArgumentIsTooLong, Second>;
<<<
LongClassName<
FirstTypeArgumentIsTooLong, Second>;
>>> generic instantiation split in middle if fit in two lines
LongClassName<First, Second, Third, Fourth, Fifth, Sixth, Seventh>;
<<<
LongClassName<First, Second, Third,
Fourth, Fifth, Sixth, Seventh>;
>>> generic instantiation split one per line if they don't fit in two lines
LongClassName<First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>;
<<<
LongClassName<
First,
Second,
Third,
Fourth,
Fifth,
Sixth,
Seventh,
Eighth>;
>>> generic instantiation indent nested type arguments
LongClassName<First, Inner<Second, Third, Fourth, Fifth, Sixth, Seventh>, Eighth>;
<<<
LongClassName<
First,
Inner<Second, Third, Fourth, Fifth,
Sixth, Seventh>,
Eighth>;
18 changes: 17 additions & 1 deletion test/whitespace/expressions.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,20 @@ obj?[foo];
>>> generic function expression
var generic = < T,S >(){};
<<<
var generic = <T, S>() {};
var generic = <T, S>() {};
>>> generic method instantiation
void main() => id < int > ;
<<<
void main() => id<int>;
>>> generic method instantiation
void main() => id < int , String , bool > ;
<<<
void main() => id<int, String, bool>;
>>> generic constructor tear-off
var x = Class < int >;
<<<
var x = Class<int>;
>>> generic name constructor tear-off
var x = Class < int > . named;
<<<
var x = Class<int>.named;