Skip to content
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 @@
# 2.3.2-dev

* Don't force split on a line comment before a switch expression case (#1215).

# 2.3.1

* Hide `--fix` and related options in `--help`. The options are still there and
Expand Down
2 changes: 1 addition & 1 deletion lib/src/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2824,7 +2824,7 @@ class SourceVisitor extends ThrowingAstVisitor {
if (whenClause != null) {
// Wrap the when clause rule around the pattern so that if the pattern
// splits then we split before "when" too.
builder.startRule();
builder.startLazyRule();
builder.nestExpression(indent: Indent.block);
}

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: 2.3.1
version: 2.3.2-dev
description: >-
Opinionated, automatic Dart source code formatter.
Provides an API and a CLI tool.
Expand Down
12 changes: 12 additions & 0 deletions test/comments/switch.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ e = switch (n) {
1 => one, // comment
2 => two // comment
};
>>> line comment before case with guard does not force split
e = switch (n) {
0 => zero,
// comment
1 when true => one,
};
<<<
e = switch (n) {
0 => zero,
// comment
1 when true => one,
};
>>> line comment
switch (e) {
// comment
Expand Down
14 changes: 14 additions & 0 deletions test/regression/1200/1215.stmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
>>>
return switch (level) {
0 => a,
// Comment.
1
when flag =>
b,
};
<<<
return switch (level) {
0 => a,
// Comment.
1 when flag => b,
};