Skip to content

Commit 999380c

Browse files
authored
Don't force split on a line comment before a switch expression case. (#1219)
Fix #1215.
1 parent 4f9681d commit 999380c

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.3.2-dev
2+
3+
* Don't force split on a line comment before a switch expression case (#1215).
4+
15
# 2.3.1
26

37
* Hide `--fix` and related options in `--help`. The options are still there and

lib/src/source_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2824,7 +2824,7 @@ class SourceVisitor extends ThrowingAstVisitor {
28242824
if (whenClause != null) {
28252825
// Wrap the when clause rule around the pattern so that if the pattern
28262826
// splits then we split before "when" too.
2827-
builder.startRule();
2827+
builder.startLazyRule();
28282828
builder.nestExpression(indent: Indent.block);
28292829
}
28302830

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: 2.3.1
3+
version: 2.3.2-dev
44
description: >-
55
Opinionated, automatic Dart source code formatter.
66
Provides an API and a CLI tool.

test/comments/switch.stmt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ e = switch (n) {
145145
1 => one, // comment
146146
2 => two // comment
147147
};
148+
>>> line comment before case with guard does not force split
149+
e = switch (n) {
150+
0 => zero,
151+
// comment
152+
1 when true => one,
153+
};
154+
<<<
155+
e = switch (n) {
156+
0 => zero,
157+
// comment
158+
1 when true => one,
159+
};
148160
>>> line comment
149161
switch (e) {
150162
// comment

test/regression/1200/1215.stmt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
>>>
2+
return switch (level) {
3+
0 => a,
4+
// Comment.
5+
1
6+
when flag =>
7+
b,
8+
};
9+
<<<
10+
return switch (level) {
11+
0 => a,
12+
// Comment.
13+
1 when flag => b,
14+
};

0 commit comments

Comments
 (0)