Skip to content

Commit fdf9d12

Browse files
authored
Support URIs in part-of directives. (#626)
* Support URIs in part-of directives. Fix #615. * Add tests for and tweak how function types are formatted. * Remove duplicate test.
1 parent 89a5c18 commit fdf9d12

File tree

8 files changed

+151
-4
lines changed

8 files changed

+151
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.6
2+
3+
* Support URIs in part-of directives (#615).
4+
15
# 1.0.5
26

37
* Support the latest version of `pkg/analyzer`.

bin/format.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'package:dart_style/src/io.dart';
1414
import 'package:dart_style/src/source_code.dart';
1515

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

1919
void main(List<String> args) {
2020
var parser = new ArgParser(allowTrailingOptions: true);

lib/src/source_visitor.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,15 @@ class SourceVisitor extends ThrowingAstVisitor {
11901190
}
11911191

11921192
visitGenericFunctionType(GenericFunctionType node) {
1193-
visit(node.returnType, after: space);
1193+
builder.startLazyRule();
1194+
builder.nestExpression();
1195+
1196+
visit(node.returnType, after: split);
11941197
token(node.functionKeyword);
1198+
1199+
builder.unnest();
1200+
builder.endRule();
1201+
11951202
_visitParameterSignature(node.typeParameters, node.parameters);
11961203
}
11971204

@@ -1516,7 +1523,11 @@ class SourceVisitor extends ThrowingAstVisitor {
15161523
space();
15171524
token(node.ofKeyword);
15181525
space();
1526+
1527+
// Part-of may have either a name or a URI. Only one of these will be
1528+
// non-null. We visit both since visit() ignores null.
15191529
visit(node.libraryName);
1530+
visit(node.uri);
15201531
});
15211532
}
15221533

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dart_style
22
# Note: See tool/grind.dart for how to bump the version.
3-
version: 1.0.5
3+
version: 1.0.6
44
author: Dart Team <[email protected]>
55
description: Opinionated, automatic Dart source code formatter.
66
homepage: https://github.com/dart-lang/dart_style

test/splitting/function_types.unit

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
40 columns |
2+
>>> many parameters
3+
Function(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth,
4+
tenth, eleventh, twelfth) f;
5+
<<<
6+
Function(
7+
first,
8+
second,
9+
third,
10+
fourth,
11+
fifth,
12+
sixth,
13+
seventh,
14+
eighth,
15+
ninth,
16+
tenth,
17+
eleventh,
18+
twelfth) f;
19+
>>> parameters fit but ) does not
20+
Function(int firstArgume, int argumentTo) f;
21+
<<<
22+
Function(
23+
int firstArgume, int argumentTo) f;
24+
>>> keep mandatory and positional on same line
25+
Function(param, [foo, bar]) f;
26+
<<<
27+
Function(param, [foo, bar]) f;
28+
>>> keep mandatory and named on same line
29+
Function(param, {T foo, T bar}) f;
30+
<<<
31+
Function(param, {T foo, T bar}) f;
32+
>>> move just optional positional to second line even though all fit on second
33+
Function(parameter, [int foo, String bar]) f;
34+
<<<
35+
Function(parameter,
36+
[int foo, String bar]) f;
37+
>>> move just named to second line even though all fit on second
38+
Function(parameter, {int foo, String bar}) f;
39+
<<<
40+
Function(parameter,
41+
{int foo, String bar}) f;
42+
>>> avoid splitting in function type parameters
43+
Function(parameter1, void printFn(param1, param2)) f;
44+
<<<
45+
Function(parameter1,
46+
void printFn(param1, param2)) f;
47+
>>> allow splitting in function type parameters
48+
Function(v callback(parameter1, parameter2, parameter3, parameter4)) f;
49+
<<<
50+
Function(
51+
v callback(parameter1, parameter2,
52+
parameter3, parameter4)) f;
53+
>>> split optional onto one per line if they don't fit on one line
54+
Function([parameter1, parameter2, parameter3]) f;
55+
<<<
56+
Function(
57+
[parameter1,
58+
parameter2,
59+
parameter3]) f;
60+
>>> split between type and name
61+
Function(VerylongParameterType parameterName) f;
62+
<<<
63+
Function(
64+
VerylongParameterType
65+
parameterName) f;
66+
>>> split in function type and on variable name
67+
Function(VeryVeryVeryVeryLongParameterType) veryLongVariableName;
68+
<<<
69+
Function(
70+
VeryVeryVeryVeryLongParameterType)
71+
veryLongVariableName;
72+
>>> split in nested function type forces outer split
73+
Function(int, String, Function(parameter1, parameter2, parameter3)) f;
74+
<<<
75+
Function(
76+
int,
77+
String,
78+
Function(parameter1, parameter2,
79+
parameter3)) f;
80+
>>> split in type arguments and variable
81+
Function<Parameter1, Parameter2, Parameter3>() veryVeryLongVariableName;
82+
<<<
83+
Function<Parameter1, Parameter2,
84+
Parameter3>()
85+
veryVeryLongVariableName;
86+
>>> split after return type
87+
GenericClass<Parameter1, Parameter2> Function() f;
88+
<<<
89+
GenericClass<Parameter1, Parameter2>
90+
Function() f;
91+
>>> chained return types
92+
Function<Argument>(String) Function<Argument>(num) Function<Argument>(int) Function<Argument>(bool) longVariable;
93+
<<<
94+
Function<Argument>(String)
95+
Function<Argument>(num)
96+
Function<Argument>(int)
97+
Function<Argument>(bool)
98+
longVariable;

test/splitting/part.unit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
40 columns |
2+
>>> part of with uri that fits
3+
part of "uri.dart";
4+
<<<
5+
part of "uri.dart";
6+
>>> part of with uri does not split on long line
7+
part of "very_very_very_very_long_uri.dart";
8+
<<<
9+
part of "very_very_very_very_long_uri.dart";

test/whitespace/directives.unit

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ import 'a' if (b.c.d) 'e';
5757
>>> configuration
5858
export'a'if(b . c=='d' )'e';
5959
<<<
60-
export 'a' if (b.c == 'd') 'e';
60+
export 'a' if (b.c == 'd') 'e';
61+
>>> part-of with uri
62+
part of'uri.dart' ;
63+
<<<
64+
part of 'uri.dart';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
40 columns |
2+
>>>
3+
Function ( ) f;
4+
<<<
5+
Function() f;
6+
>>>
7+
void Function( int i, String s) f;
8+
<<<
9+
void Function(int i, String s) f;
10+
>>>
11+
Function( int i, [ String s, bool b ] ) f;
12+
<<<
13+
Function(int i, [String s, bool b]) f;
14+
>>>
15+
Function( int i, { String s, bool b } ) f;
16+
<<<
17+
Function(int i, {String s, bool b}) f;
18+
>>>
19+
Function < T extends S > () f;
20+
<<<
21+
Function<T extends S>() f;

0 commit comments

Comments
 (0)