Skip to content

Support URIs in part-of directives. #626

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

Merged
merged 3 commits into from
May 10, 2017
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.6

* Support URIs in part-of directives (#615).

# 1.0.5

* Support the latest version of `pkg/analyzer`.
Expand Down
2 changes: 1 addition & 1 deletion bin/format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:dart_style/src/io.dart';
import 'package:dart_style/src/source_code.dart';

// Note: The following line of code is modified by tool/grind.dart.
const version = "1.0.5";
const version = "1.0.6";

void main(List<String> args) {
var parser = new ArgParser(allowTrailingOptions: true);
Expand Down
13 changes: 12 additions & 1 deletion lib/src/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,15 @@ class SourceVisitor extends ThrowingAstVisitor {
}

visitGenericFunctionType(GenericFunctionType node) {
visit(node.returnType, after: space);
builder.startLazyRule();
builder.nestExpression();

visit(node.returnType, after: split);
token(node.functionKeyword);

builder.unnest();
builder.endRule();

_visitParameterSignature(node.typeParameters, node.parameters);
}

Expand Down Expand Up @@ -1516,7 +1523,11 @@ class SourceVisitor extends ThrowingAstVisitor {
space();
token(node.ofKeyword);
space();

// Part-of may have either a name or a URI. Only one of these will be
// non-null. We visit both since visit() ignores null.
visit(node.libraryName);
visit(node.uri);
});
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_style
# Note: See tool/grind.dart for how to bump the version.
version: 1.0.5
version: 1.0.6
author: Dart Team <[email protected]>
description: Opinionated, automatic Dart source code formatter.
homepage: https://github.com/dart-lang/dart_style
Expand Down
98 changes: 98 additions & 0 deletions test/splitting/function_types.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
40 columns |
>>> many parameters
Function(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth,
tenth, eleventh, twelfth) f;
<<<
Function(
first,
second,
third,
fourth,
fifth,
sixth,
seventh,
eighth,
ninth,
tenth,
eleventh,
twelfth) f;
>>> parameters fit but ) does not
Function(int firstArgume, int argumentTo) f;
<<<
Function(
int firstArgume, int argumentTo) f;
>>> keep mandatory and positional on same line
Function(param, [foo, bar]) f;
<<<
Function(param, [foo, bar]) f;
>>> keep mandatory and named on same line
Function(param, {T foo, T bar}) f;
<<<
Function(param, {T foo, T bar}) f;
>>> move just optional positional to second line even though all fit on second
Function(parameter, [int foo, String bar]) f;
<<<
Function(parameter,
[int foo, String bar]) f;
>>> move just named to second line even though all fit on second
Function(parameter, {int foo, String bar}) f;
<<<
Function(parameter,
{int foo, String bar}) f;
>>> avoid splitting in function type parameters
Function(parameter1, void printFn(param1, param2)) f;
<<<
Function(parameter1,
void printFn(param1, param2)) f;
>>> allow splitting in function type parameters
Function(v callback(parameter1, parameter2, parameter3, parameter4)) f;
<<<
Function(
v callback(parameter1, parameter2,
parameter3, parameter4)) f;
>>> split optional onto one per line if they don't fit on one line
Function([parameter1, parameter2, parameter3]) f;
<<<
Function(
[parameter1,
parameter2,
parameter3]) f;
>>> split between type and name
Function(VerylongParameterType parameterName) f;
<<<
Function(
VerylongParameterType
parameterName) f;
>>> split in function type and on variable name
Function(VeryVeryVeryVeryLongParameterType) veryLongVariableName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] this isn't a VeryVeryVeryVeryLongParameterType it's a veryVeryVeryVeryLongParameterName

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually a type (though it doesn't matter either way for this test). Unlike the old function type syntax, the new syntax wisely assumes if you omit one identifier, you're omitting the name, not the type.

<<<
Function(
VeryVeryVeryVeryLongParameterType)
veryLongVariableName;
>>> split in nested function type forces outer split
Function(int, String, Function(parameter1, parameter2, parameter3)) f;
<<<
Function(
int,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] this is misleading... IIUC this is a parameter named 'int' of type 'dynamic'. Or am I wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

String,
Function(parameter1, parameter2,
parameter3)) f;
>>> split in type arguments and variable
Function<Parameter1, Parameter2, Parameter3>() veryVeryLongVariableName;
<<<
Function<Parameter1, Parameter2,
Parameter3>()
veryVeryLongVariableName;
>>> split after return type
GenericClass<Parameter1, Parameter2> Function() f;
<<<
GenericClass<Parameter1, Parameter2>
Function() f;
>>> chained return types
Function<Argument>(String) Function<Argument>(num) Function<Argument>(int) Function<Argument>(bool) longVariable;
<<<
Function<Argument>(String)
Function<Argument>(num)
Function<Argument>(int)
Function<Argument>(bool)
longVariable;
9 changes: 9 additions & 0 deletions test/splitting/part.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
40 columns |
>>> part of with uri that fits
part of "uri.dart";
<<<
part of "uri.dart";
>>> part of with uri does not split on long line
part of "very_very_very_very_long_uri.dart";
<<<
part of "very_very_very_very_long_uri.dart";
6 changes: 5 additions & 1 deletion test/whitespace/directives.unit
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ import 'a' if (b.c.d) 'e';
>>> configuration
export'a'if(b . c=='d' )'e';
<<<
export 'a' if (b.c == 'd') 'e';
export 'a' if (b.c == 'd') 'e';
>>> part-of with uri
part of'uri.dart' ;
<<<
part of 'uri.dart';
21 changes: 21 additions & 0 deletions test/whitespace/function_types.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
40 columns |
>>>
Function ( ) f;
<<<
Function() f;
>>>
void Function( int i, String s) f;
<<<
void Function(int i, String s) f;
>>>
Function( int i, [ String s, bool b ] ) f;
<<<
Function(int i, [String s, bool b]) f;
>>>
Function( int i, { String s, bool b } ) f;
<<<
Function(int i, {String s, bool b}) f;
>>>
Function < T extends S > () f;
<<<
Function<T extends S>() f;