-
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
auto fix unnecessary duplication of receiver #52476
Comments
On the other hand, it seems like it ought to be fairly simple to expand the range over which the fix is being made available; in general it ought to be offered anywhere inside the diagnostic's highlight range. |
My preference is for a single action that fixes all of the cascades in a single action. |
Would be good addition to have this... |
The fix not triggering on that line was fixed by https://dart-review.googlesource.com/c/sdk/+/386860. I still think this can be left open to track the bulk fix. |
After some discussion on Discord with @bwilkerson and @DanTup, taking #58662 (false positives/negatives) into consideration. This issue could mean that the multi/bulk fix for transforming every statement into a cascade could create code that didn't have the same meaning as before. So we decided that the best approach would be to create a "convert this and related to cascade" and keep both fixes so the user can decide which to use. For the above case, it would fix all together but it would still need to be manually triggered for every set of possible transformations in the file. Here is the current CL https://dart-review.googlesource.com/c/sdk/+/390421. E.g.: final subnet = Subnet();
subnet.name = parts[0];
subnet.zone = parts[1];
subnet.network = parts[2];
subnet.range = parts[3];
subnets.add(subnet);
final subnet2 = Subnet();
subnet2.name = parts[0];
subnet2.zone = parts[1]; If we select the new fix on any of the lints before the empty line, we get: final subnet = Subnet()
..name = parts[0]
..zone = parts[1]
..network = parts[2]
..range = parts[3];
subnets.add(subnet);
final subnet2 = Subnet();
subnet2.name = parts[0];
subnet2.zone = parts[1]; If we had selected the same after the empty line, the second set would have transformed but not the first. |
I originally reported this for Dart-Code but Dan asked for the issue to be raised here:
Dart-Code/Dart-Code#4550
The following code generates a warning:
cascade_invocations
Unnecessary duplication of receiver.\nTry using a cascade to avoid the duplication.
It would be useful to have an auto fix which changes the code to:
There are potentially two issues here.
In vs code if you click on the third line :
an auto-fix appears for changing to cascade notation.
However, I would also expect that the 2nd line should also offer to convert to cascade notation (as it also triggers the cascade_invocation lint) but it does not.
Of course, if we implement the - fix all, and that fixes all lines as suggested, then it may not be worth fixing the fix single bug.
The text was updated successfully, but these errors were encountered: