-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add support for SuggestedFixes #1779
Comments
I'm working on and for now, I'm able to apply suggestions from For the other, the problem is a bit more complex because the fix must be applied on multiple lines. |
I think we need to print the suggested fixes if they are not applied (without |
In some cases, it will be very weird to display the suggestions, because a suggestion can be a |
agree |
we can print a |
@ldez |
I think we can support both as the first step, but I'm thinking about it, I need more time. |
Here is the code of how to apply SuggestedFixes: https://github.com/golang/tools/blob/54dc8c5edb561003330ec7e649333181bbd0a9bd/go/analysis/internal/checker/checker.go#L316 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@ldez I guess this will be the next major feature after the generics issues are fixed? The developer productivity and happiness enabled by just clicking Apply Suggested fixes is quite significant on a Go ecosystem scale. |
This issue is not related to GitHub review suggestions. |
Is there anything that can be done about this on a per-linter basis? In nunnatsa/ginkgolinter#63 (comment) it was pointed out that for some linters, fixing already works. |
I plan to handle the topic by a breaking change, I don't want to introduce several ways to handle fixes. |
I'm currently coming up against this issue. I'm building a custom linter and have SuggestedFixes implemented. They work fine when I use the binary with Was any work ever started here? Is there a rough outline of what needs to be done to implement this? I'm new to this codebase but may be able to help implement it if I can get a high level overview of what's needed |
I will handle this issue. This will be my work for this week. https://bsky.app/profile/golangcilint.bsky.social/post/3lcfpfu5lbc24 |
UPDATE I will give some details of my current work on the topic. My plan is to replace the current implementation (based on FYI, the current implementation is not "friendly", and is completely different than something based It's a long job, so it will take me more than one week. Maybe at the end, I will just create a kind of "compatibility layer". FYI, currently, my only revenue comes from community sponsors, I work full-time on OSS, and I'm fully transparent with my revenues (everything is public), so if you want to help me: |
Update I have a working PoC (it's a draft), I keep it locally for now because it's a bit too raw. Currently, golangci-lint is able to "autofix" reports from 13 linters:
I converted 8 linters of those currently supported linters to About the other linters, I'm able to use "autofix" for the totality of linters that support
Also, the new "autofix" system is less powerful: there are some limitations on multiple fixes on the same line. For now, I don't know if I will be able to improve that. This is still under development. Until it is fully working, I do not consider my current implementation as a working solution. If you want to help me: |
Could you expand on this point? My understanding of SuggestedFixes was that it could apply fixes as long as they didn't overlap, so you have to specify starts and ends if you have multiple fixes on the same line. Was that not true of the previous implementation? How did it handle overlapping fixes? |
My sentence was not clear: the new system is less powerful. (I edited my previous post) Remember, this is a rewrite from scratch (#1779 (comment)) and this is a draft. |
The previous (current) implementation does not support this, e.g #1490, #4885, #1510, #3819, #3454. I don't know what the new implementation looks like but the idea of using I think for now, just using |
This is more subtle: the current implementation is able, in some cases, to support that (and some overlap cases). For example, run package sandbox
import "log"
// langauge langauge
func langaugeMisspell() {
var langauge, langaugeAnd string
log.Printf("it's becouse of them: %s, %s", langauge, langaugeAnd)
} This example contains several problems on the same line. FYI the problems from the issues about imports are also more subtle than overlap or same line, the problem is that each linter reports "identical" changes but not on the same line. |
Perhaps overlapping fixes can be handled incrementally, as in "apply some fixes that don't overlap, rerun analysis, apply again, until nothing pops up anymore"? Just a thought. |
Update I think I win the fight against the most complex part: the "formaters" ( So the 12 currently supported linters, and 15 linters that support
Now, I have to handle Reports on the same line (not overlapping) are still not supported. This is still in WIP. If you want to help me: |
Update The problem of changes on the same line is fixed: the fun fact is it was just a missing condition inside an Also overlapping is now managed in a stable way. The situation:
This situation is 99% related to formaters because they want to apply changes to the same sections but not in the same way, so not in the same positions. Before/Currently: The overlap was managed by picking "randomly" one change for one of both linters (L4). The result was a mix of non-consistent changes: deletion of imports, duplication of imports, etc. The problem here is not the overlaps by themselves (because they are "managed") but the other changes. With my implementation: If there are overlaps, only one of the 2 linters is "allowed" to apply changes on the targeted file (ex: L4, L5, not L6). I tested my implementation with the examples from the issues, and it works as expected: no unexpected deletions, and no duplications. I still have to handle I'm increasingly confident in my current implementation. If you benefit from this change, and you want to help me: |
Update
The "autofix" is now working for the 28 linters 🎉 Now, I should clean the implementation, add new linter tests, create a reviewable PR, and maybe add some bonuses ✨. It will take one or two days so I will create a PR this weekend. The go1.24.0-rc1 release will happen very soon, I already prepared a PR but this could take some time too. This will be the last update in this issue as the next step is to create a PR. I already worked 10 days on this topic, and my only revenue is donations. If you enjoy this change, and you or your company want to help golangci-lint or me: |
We use thanks.dev for donation distribution and I just added https://github.com/golangci/golangci-lint as a manual inclusion. You can quickly sign up and then it connects with your GitHub sponsors, if that would work for you. Thank you for your great work! |
I already have a thanks.dev account but I didn't find how to add golangci-lint. |
It's not much I know, but I just put in $20 for you for this, and am still waiting to hear if my employer will sponsor ongoing. |
Update Sadly, I have an "extra" update 😢 I'm fighting against CGO and friends, so I must add tests everywhere and adjust the linter implementations when needed. I do my best but I will not be able to open a PR today. edit1: When I fix CGO, it breaks yacc directives... |
Just threw 20€ in the hat, thank you for your continued work! |
Update After a very very long tunnel to add tests, run tests, and analyze the results, I have some conclusions:
I evaluate this topic as independent: I postpone the problems with cgo and yacc, I will handle this later. I will remove all the yacc tests (but keep the cgo tests), clean everything, and open a PR. It was a difficult and exciting tunnel, a bit extreme, and now I need some rest. |
🎉 The PR ready: #5232 |
Awesome! Can't wait to try this in a new release :D |
Is your feature request related to a problem? Please describe.
Add support for SuggestedFixes.
https://github.com/golang/tools/blob/b4639ccb830b1c9602f1c96eba624bbbe20650ea/go/analysis/doc/suggested_fixes.md
Describe the solution you'd like
Be able to apply automatically the fixes via
--fix
.Describe alternatives you've considered
Display the suggestion as extra information.
Additional context
https://github.com/golang/tools/blob/b4639ccb830b1c9602f1c96eba624bbbe20650ea/go/analysis/diagnostic.go#L23-L28
Current linters that support
SuggestedFixes
:goerr113
ruleguard
staticcheck
nlreturn
exportloopref
exhaustive
govet
Related to #1728
If you want to help me:
Latest update: #1779 (comment)
The text was updated successfully, but these errors were encountered: