-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Switch expressions assist conversion with OR removes comments #56597
Comments
Summary: The Dart switch expression conversion with OR operator removes comments associated with individual cases, leading to code that is less readable and harder to understand. The user suggests preserving comments by placing them after the OR operator, but this results in inconsistent formatting. |
Issue created dart-lang/dart_style#1551 |
This also inspired me to create #59529. |
Also: return switch (value) {
0 || //case 0
1 || //case 1
2 //case 2
=>
2,
_ => 3,
}; Becomes: switch (value) {
case 0 || //case 0
1 || //case 1
2:
return 2;
default:
return 3;
} So we are still losing the last comment here. So if you pick the first example and convert it twice you lose every comment there. Really bad if #58862 ever happens. |
Converting the following does keep the comments, but if converting back it loses the last comment as mentioned above: switch (value) {
case 0 || //case 0
1 || //case 1
2: // case 2
return 2;
default:
return 3;
} Just point it out so tests can also be added for this case. |
Thanks for all of these examples @FMorschel! |
NP! He had already seen this issue since he added the priority. Also, something to keep in mind would be #56602 because as you can see in the first example, it doesn't format the output. I completely ignored it first since it is so easy to format in the IDE but my colleague pointed that when fixing via CLI with the possible future lint this would not be expected. |
From an example posted by @pq in #58862:
Turns into the following losing all comments:
After formatted:
A smaller example:
Turns into:
I believe it should become something along the lines of:
But I think the result being alone is weird in all of the above so I suggest doing:
Currently, in the formatter, if you have the above, it formats the
=>
in one line and the result in a new one. Will file an issue there and link here.The text was updated successfully, but these errors were encountered: