File tree Expand file tree Collapse file tree 4 files changed +49
-2
lines changed Expand file tree Collapse file tree 4 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -616,6 +616,19 @@ mixin PieceFactory {
616
616
return ;
617
617
}
618
618
619
+ // Hoist any comments before the function so they don't force a split
620
+ // between the return type and function. In most cases, this doesn't matter
621
+ // because the [SequenceBuilder] for the surrounding code will separate out
622
+ // the leading comment. But if there is a metadata annotation followed by
623
+ // a comment, then the function, then the comment doesn't get captured by
624
+ // the [SequenceBuilder], as in:
625
+ //
626
+ // @meta
627
+ // // Weird place for comment.
628
+ // int f() {}
629
+ var leadingComments =
630
+ pieces.takeCommentsBefore (returnType.firstNonCommentToken);
631
+
619
632
var returnTypePiece = pieces.build (() {
620
633
for (var keyword in modifiers) {
621
634
pieces.modifier (keyword);
@@ -628,7 +641,8 @@ mixin PieceFactory {
628
641
writeFunction ();
629
642
});
630
643
631
- pieces.add (VariablePiece (returnTypePiece, [signature], hasType: true ));
644
+ pieces.add (prependLeadingComments (leadingComments,
645
+ VariablePiece (returnTypePiece, [signature], hasType: true )));
632
646
}
633
647
634
648
/// If [parameter] has a [defaultValue] then writes a piece for the parameter
Original file line number Diff line number Diff line change @@ -21,4 +21,12 @@ main() {
21
21
// nested
22
22
}
23
23
}
24
+ }
25
+ >>> Don't split return type if comment before.
26
+ // Comment.
27
+ int f() {;}
28
+ <<<
29
+ // Comment.
30
+ int f() {
31
+ ;
24
32
}
Original file line number Diff line number Diff line change 95
95
@metadata
96
96
@another(argument, argument)
97
97
callback() = constantFunction,
98
- ]) {}
98
+ ]) {}
99
+ >>> Don't split return type if comment after metadata.
100
+ @meta
101
+ // Comment.
102
+ int f() {;}
103
+ <<<
104
+ @meta
105
+ // Comment.
106
+ int f() {
107
+ ;
108
+ }
Original file line number Diff line number Diff line change @@ -39,4 +39,19 @@ main() {
39
39
.transform(utf8.decoder)
40
40
.transform(const LineSplitter())
41
41
.asBroadcastStream();
42
+ }
43
+ >>> Don't split return type if comment after metadata annotation.
44
+ class Benchmark {
45
+ @override
46
+ // A rate of one run per 2s, with a millisecond of noise. Some variation is
47
+ // needed for Golem's noise-based filtering and regression detection.
48
+ double
49
+ measure() => (2000 + Random().nextDouble() - 0.5) * 1000;
50
+ }
51
+ <<<
52
+ class Benchmark {
53
+ @override
54
+ // A rate of one run per 2s, with a millisecond of noise. Some variation is
55
+ // needed for Golem's noise-based filtering and regression detection.
56
+ double measure() => (2000 + Random().nextDouble() - 0.5) * 1000;
42
57
}
You can’t perform that action at this time.
0 commit comments