Add more tests and update CHANGELOG.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b765aa4..65250ae 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# 1.2.8
+
+* Better indentation of function expressions inside trailing comma argument
+ lists. (Thanks a14@!)
+
# 1.2.7
* Improve indentation of adjacent strings inside `=>` functions.
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 184b4fb..96f60bc 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -1088,12 +1088,7 @@
var isArgWithTrailingComma = false;
var parent = node.parent;
if (parent is FunctionExpression) {
- var argList = parent?.parent;
- if (argList is NamedExpression) argList = argList.parent;
- if (argList is ArgumentList &&
- argList.arguments.last.endToken.next.type == TokenType.COMMA) {
- isArgWithTrailingComma = true;
- }
+ isArgWithTrailingComma = _isTrailingCommaArgument(parent);
}
if (!isArgWithTrailingComma) builder.startBlockArgumentNesting();
@@ -2913,6 +2908,15 @@
builder.endRule();
}
+ /// Whether [node] is an argument in an argument list with a trailing comma.
+ bool _isTrailingCommaArgument(Expression node) {
+ var parent = node.parent;
+ if (parent is NamedExpression) parent = parent.parent;
+
+ return parent is ArgumentList &&
+ parent.arguments.last.endToken.next.type == TokenType.COMMA;
+ }
+
/// Whether [node] is a spread of a collection literal.
bool _isSpreadCollection(AstNode node) =>
_findSpreadCollectionBracket(node) != null;
diff --git a/pubspec.lock b/pubspec.lock
index 6369f5a..3b394d1 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -1,5 +1,5 @@
# Generated by pub
-# See https://www.dartlang.org/tools/pub/glossary#lockfile
+# See https://dart.dev/tools/pub/glossary#lockfile
packages:
analyzer:
dependency: "direct main"
@@ -7,7 +7,7 @@
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
- version: "0.36.0"
+ version: "0.36.3"
args:
dependency: "direct main"
description:
@@ -64,13 +64,20 @@
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
+ csslib:
+ dependency: transitive
+ description:
+ name: csslib
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.16.0"
front_end:
dependency: transitive
description:
name: front_end
url: "https://pub.dartlang.org"
source: hosted
- version: "0.1.15"
+ version: "0.1.18"
glob:
dependency: transitive
description:
@@ -85,6 +92,13 @@
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.3"
+ html:
+ dependency: transitive
+ description:
+ name: html
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.14.0+2"
http:
dependency: transitive
description:
@@ -133,7 +147,7 @@
name: kernel
url: "https://pub.dartlang.org"
source: hosted
- version: "0.3.15"
+ version: "0.3.18"
matcher:
dependency: transitive
description:
diff --git a/test/splitting/function_arguments.stmt b/test/splitting/function_arguments.stmt
index 5757a9d..a94e99d 100644
--- a/test/splitting/function_arguments.stmt
+++ b/test/splitting/function_arguments.stmt
@@ -201,14 +201,31 @@
;
},
c: argument);
->>> avoid extra-indent for expression function as argument with trailing comma
-function(() => P(p,),a: () => A(a,),);
+>>> no extra indent for expression function argument with trailing comma
+function(() => P(p,),a: () => [a,],);
<<<
function(
() => P(
p,
),
- a: () => A(
+ a: () => [
a,
+ ],
+);
+>>> indents body if not block style
+function(() => inner(argument1, argument2, argument3),);
+<<<
+function(
+ () => inner(
+ argument1, argument2, argument3),
+);
+>>> split in expression function parameter list argument with trailing comma
+function((parameter1, parameter2, parameter3) => P(p,),);
+<<<
+function(
+ (parameter1, parameter2,
+ parameter3) =>
+ P(
+ p,
),
);
\ No newline at end of file