Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no extra-indent of expression function as argument with trailing comma #794

Merged
merged 1 commit into from
Jun 4, 2019
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
17 changes: 15 additions & 2 deletions lib/src/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1022,11 +1022,24 @@ class SourceVisitor extends ThrowingAstVisitor {

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();

Expand Down
13 changes: 12 additions & 1 deletion test/splitting/function_arguments.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,15 @@ longFunction(
b: () {
;
},
c: argument);
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,
),
);