Merge branch 'master' into better-empty-spread-collection
# Conflicts:
# CHANGELOG.md
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e61b59a..4234f1b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
* Add support for formatting extension methods (#830).
* Format `?` in types.
* Format the `late` modifier.
+* Format the `required` modifier.
* Better formatting of empty spread collections (#831).
# 1.2.10
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index c0cc9c6..35b0396 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -1534,6 +1534,7 @@
visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
visitParameterMetadata(node.metadata, () {
if (!_insideNewTypedefFix) {
+ modifier(node.requiredKeyword);
modifier(node.covariantKeyword);
visit(node.returnType, after: space);
// Try to keep the function's parameters with its name.
@@ -2920,6 +2921,7 @@
void _beginFormalParameter(FormalParameter node) {
builder.startLazyRule(Rule(Cost.parameterType));
builder.nestExpression();
+ modifier(node.requiredKeyword);
modifier(node.covariantKeyword);
}
diff --git a/test/fixes/function_typedefs.unit b/test/fixes/function_typedefs.unit
index 281ca08..c7d7473 100644
--- a/test/fixes/function_typedefs.unit
+++ b/test/fixes/function_typedefs.unit
@@ -252,4 +252,10 @@
>>> nullable old style function-typed formal
typedef Foo(foo()?);
<<<
-typedef Foo = Function(Function()? foo);
\ No newline at end of file
+typedef Foo = Function(Function()? foo);
+>>> required parameters
+typedef Foo({required a, required b()});
+<<<
+typedef Foo = Function(
+ {required dynamic a,
+ required Function() b});
\ No newline at end of file
diff --git a/test/fixes/named_default_separator.unit b/test/fixes/named_default_separator.unit
index 026562a..de119b9 100644
--- a/test/fixes/named_default_separator.unit
+++ b/test/fixes/named_default_separator.unit
@@ -33,4 +33,14 @@
{a = // b
// c
- 1}) {}
\ No newline at end of file
+ 1}) {}
+>>> on required parameter
+class A {
+foo({required int b: 1, required c(): f}) {}
+}
+<<<
+class A {
+ foo(
+ {required int b = 1,
+ required c() = f}) {}
+}
\ No newline at end of file
diff --git a/test/splitting/parameters.unit b/test/splitting/parameters.unit
index c41e857..8bbb2da 100644
--- a/test/splitting/parameters.unit
+++ b/test/splitting/parameters.unit
@@ -45,6 +45,47 @@
covariant int
veryLongParameterNameWow) {}
}
+>>> split before "required"
+class A {
+ longMethod({required parameterNameHere}) {}
+}
+<<<
+class A {
+ longMethod(
+ {required parameterNameHere}) {}
+}
+>>> split before "required" with multiple parameters
+class A {
+ longMethod({required first, second, required int third(parameter), fourth}) {}
+}
+<<<
+class A {
+ longMethod(
+ {required first,
+ second,
+ required int third(parameter),
+ fourth}) {}
+}
+>>> never split after "required" (at least for now)
+class A {
+ longMethod({required int veryLongParameterNameWow}) {}
+}
+<<<
+class A {
+ longMethod(
+ {required int
+ veryLongParameterNameWow}) {}
+}
+>>> don't split between "required" and "covariant"
+class A {
+ longMethod({required covariant int veryLongParameterNameWow}) {}
+}
+<<<
+class A {
+ longMethod(
+ {required covariant int
+ veryLongParameterNameWow}) {}
+}
>>> split between field type and name
class Foo {
Foo(VerylongParameterType this.parameterName) {}
diff --git a/test/whitespace/cascades.stmt b/test/whitespace/cascades.stmt
index 4fc7329..03377d2 100644
--- a/test/whitespace/cascades.stmt
+++ b/test/whitespace/cascades.stmt
@@ -142,4 +142,29 @@
1,
]..cascade(() {
;
- });
\ No newline at end of file
+ });
+>>> allow same-line cascades to mix null-aware
+list
+ ?..add("baz")
+ ..add("bar");
+<<<
+list?..add("baz")..add("bar");
+>>> mixed
+foo?..a()..b()..c();
+<<<
+foo
+ ?..a()
+ ..b()
+ ..c();
+>>> null-aware getter
+foo?..baz..baz;
+<<<
+foo
+ ?..baz
+ ..baz;
+>>> null-aware setter
+foo?..baz = 3..baz=5;
+<<<
+foo
+ ?..baz = 3
+ ..baz = 5;
\ No newline at end of file
diff --git a/test/whitespace/functions.unit b/test/whitespace/functions.unit
index 1eb3c3a..fc3f7e7 100644
--- a/test/whitespace/functions.unit
+++ b/test/whitespace/functions.unit
@@ -169,4 +169,36 @@
>>> nullable old style function typed parameter
function(int? callback()?) {}
<<<
-function(int? callback()?) {}
\ No newline at end of file
+function(int? callback()?) {}
+>>> required parameters
+class A {
+f({ required int a,required b}) {}
+}
+<<<
+class A {
+ f({required int a, required b}) {}
+}
+>>> required covariant
+class A {
+f({ required covariant int a}) {}
+}
+<<<
+class A {
+ f({required covariant int a}) {}
+}
+>>> required function-typed formal
+class A {
+f({ required callback()}) {}
+}
+<<<
+class A {
+ f({required callback()}) {}
+}
+>>> required initializing formal
+class A {
+A({ required this.b}) {}
+}
+<<<
+class A {
+ A({required this.b}) {}
+}
\ No newline at end of file
diff --git a/test/whitespace/metadata.unit b/test/whitespace/metadata.unit
index 4a2a6ea..1168e89 100644
--- a/test/whitespace/metadata.unit
+++ b/test/whitespace/metadata.unit
@@ -256,6 +256,15 @@
@VeryLongMetadataAnnotation
covariant longParameter) {}
}
+>>> keep "required" with parameter
+class A { function({@Annotation @VeryLongMetadataAnnotation required longParameter}) {} }
+<<<
+class A {
+ function(
+ {@Annotation
+ @VeryLongMetadataAnnotation
+ required longParameter}) {}
+}
>>> metadata on function typedef
@foo typedef Fn = Function();
<<<