Merge branch 'expression-function-as-arg' of https://github.com/a14n/dart_style into a14n-expression-function-as-arg
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index 8d649c0..184b4fb 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -1083,11 +1083,24 @@
 
     if (_isInLambda(node)) builder.endSpan();
 
-    builder.startBlockArgumentNesting();
+    // If this function invocation appears in an argument list with trailing
+    // comma, don't add extra nesting to preserve normal indentation.
+    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;
+      }
+    }
+
+    if (!isArgWithTrailingComma) builder.startBlockArgumentNesting();
     builder.startSpan();
     visit(node.expression);
     builder.endSpan();
-    builder.endBlockArgumentNesting();
+    if (!isArgWithTrailingComma) builder.endBlockArgumentNesting();
 
     if (node.expression is BinaryExpression) builder.endRule();
 
diff --git a/test/splitting/function_arguments.stmt b/test/splitting/function_arguments.stmt
index b7be6ef..5757a9d 100644
--- a/test/splitting/function_arguments.stmt
+++ b/test/splitting/function_arguments.stmt
@@ -200,4 +200,15 @@
     b: () {
       ;
     },
-    c: argument);
\ No newline at end of file
+    c: argument);
+>>> avoid extra-indent for expression function as argument with trailing comma
+function(() => P(p,),a: () => A(a,),);
+<<<
+function(
+  () => P(
+    p,
+  ),
+  a: () => A(
+    a,
+  ),
+);
\ No newline at end of file