Skip to content

Commit

Permalink
Try to keep function-typed parameters parameter lists with the parame…
Browse files Browse the repository at this point in the history
…ter name.

I can't repro the original issue in google#58, so other nested list changes likely took
care of that, but this addresses the other comments on that bug.

Fixes google#58.

BUG=dart-lang/dart_style#58
R=kevmoo@google.com

Review URL: https://chromiumcodereview.appspot.com//830543002
  • Loading branch information
munificent committed Dec 29, 2014
1 parent 732de8e commit b5a0af3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/src/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,12 @@ class SourceVisitor implements AstVisitor {

visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
visitNode(node.returnType, after: space);

// Try to keep the function's parameters with its name.
_writer.startSpan();
visit(node.identifier);
visit(node.parameters);
_writer.endSpan();
}

visitHideCombinator(HideCombinator node) {
Expand Down
7 changes: 7 additions & 0 deletions test/regression/58.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
>>>
bool doStuff(String firstArgX, {String secondArg, String arg3foo, Map<String,
String> anotherArg, bool yetAnotherArg: false, bool tooManyArgs: true}) {}
<<<
bool doStuff(String firstArgX, {String secondArg, String arg3foo,
Map<String, String> anotherArg, bool yetAnotherArg: false,
bool tooManyArgs: true}) {}
17 changes: 16 additions & 1 deletion test/splitting/parameters.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,19 @@ reallyLongMethod(parameter,
reallyLongMethod(parameter, {foo, bar}) {}
<<<
reallyLongMethod(parameter,
{foo, bar}) {}
{foo, bar}) {}
>>> avoid splitting in function type parameters
bool doStuff(parameter1, void printFn(param1, param2)) {}
<<<
bool doStuff(parameter1,
void printFn(param1, param2)) {}
>>>
doStuff(param1, void printFn(param1, param2)) {}
<<<
doStuff(param1,
void printFn(param1, param2)) {}
>>> allow splitting in function type parameters
doStuff(callback(parameter1, parameter2, parameter3, parameter4)) {}
<<<
doStuff(callback(parameter1, parameter2,
parameter3, parameter4)) {}

0 comments on commit b5a0af3

Please sign in to comment.