-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add support for "fix all" in the analysis server #37228
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
Comments
We have a command-line tool called One interesting design question that we still haven't answered for dartfix is which fix to apply in the cases where there are multiple supported fixes. For something like Another interesting design question is how to control which problems to fix. Do all users want members sorted? Which lints should be fixed? For dartfix we're allowing users to specify on the command line the set of fixes to apply. We have a default set that we use if none are specified, but I'm not sure how well the default set matches what our users want. For something like this, would we decide for users what to fix, or would we have some way for users to configure it (maybe in the analysis options file)? |
I looked at
so I wasn't sure if this were related (though maybe migrating to new syntax is just a set of particular fixes).
I think this relates a little to #37227. I think if there isn't an clear best fix, we shouldn't apply any (at least in the case for things like VS Code's "fix all" that can be run on-save.. it might be different in an interactive setting where the user could express a preference).
If they're enabled a lint that raises warnings when things are not sorted, I would say sorting them seems like the obvious fix the user would do, so we should do it. That said, sort members is more disruptive than most, and I think in VS Code they can already set that to run on-save, so we might want to leave it out (which might mean allowing the IDE to provide exclusions to the server or something).
I don't know these will enough to be confident in this answer, but I'd generally say if a user has enabled a lint that's what they want. Not wanting it is probably the exception (for me, I tend to enable all lints, then when I see a few warnings on code I think is fine, I'll just turn a lint off). If we got lots of reports from users that said they want to use auto-fix-on-save but there are some lints that they want enabled, but not auto-fixed (which doesn't sound like it should be that common to me) we could always extend analysis options with a list of "lints to exclude from auto fix" (this seems less maintenance than duping the whole list of lints for which ones should auto-fix)? |
We might even be able to share a single server protocol between the two uses if we're careful with the design. |
I didn't take it to mean that, I think pointing to it makes sense (I think when I read the description I dismissed it too quickly). There does seem like a lot of overlap here.., for ex:
Whether all syntax migrations would work as a lint to enforce using the new one (and a fix), I'm not sure - but it does seem like there's a lot that could be shared here :-) |
For VS Code when using LSP, there's now a Fix All command that fixes anything "dart fix" would for the current file (it can also be set to run on-save): That takes care of my original request here, though I'm not sure if this should remain open to add something similar for IntelliJ/AS? |
I believe that it's working in IntelliJ as well. I just tried it using the following test case: void f(int a, int b) {
(a + b);
(b + a);
} and I got the expected "fix in file" item in the menu. As a result, I'm going to close the issue. |
Related to discussion in Dart-Code/Dart-Code#1393 (and a little #37227). Having a server action (similar to "sort members" of format) that can apply all minor fixes in a file (in a set of edits from a single call) would allow people to set it up to run on-save (eg. via VS Code's support).
In many cases these might by the same as the preferred fixes in #37227, though I'm not sure if always. It'd certainly be a nice way to fix up a lot of lints (for ex. if you enable
always_specify_types
and this just fixed all the places they were missing).The text was updated successfully, but these errors were encountered: