You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**What type of PR is this?**
> Feature
**What does this PR do? Why is it needed?**
nogo analyzers may produce fixes as
analysis.[Diagnostic](https://pkg.go.dev/golang.org/x/tools/go/analysis#Diagnostic).
This PR allows rules_go to save the fixes as patches, one per target.
The patch and the command to apply the patch is printed out to the
terminal for users to manually apply. The patch is also available in the
"nogo_fix" output group. This allows people to get patches for all
targets without failing the build by passing `--norun_validations
--output_groups nogo_fix`.
Example output:
```
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
nogo: errors found by nogo during build-time code analysis:
src/example.com/send_request.go:133:4: Add and Done should not both exist inside the same goroutine block (example_nogo_analyzer)
-------------------Suggested Fix-------------------
--- src/example.com/send_request.go
+++ src/example.com/send_request.go
@@ -123,6 +123,7 @@
for !isComplete {
<-ticker.C
+ concurrentJobs.Add(1)
go func() {
text, hasMore := <-line
if !hasMore {
@@ -130,7 +131,6 @@
return
}
- concurrentJobs.Add(1)
defer concurrentJobs.Done()
atomic.AddInt32(&totalSend, 1)
-----------------------------------------------------
To apply the suggested fix, run the following command:
$ patch -p1 < bazel-out/k8-fastbuild/bin/src/example.com/send_request.nogo.patch
Target //src/example.com:send_request failed to build
Use --verbose_failures to see the command lines of failed build steps.
```
**Other notes for review**
An analyzer may suggest multiple alternative fixes to one issue. Only
the first one is selected by default, unless it conflicts with other
fixes, in which case it moves on to try the next alternative. If all
alternatives are tried but still have conflicts, they will be skipped.
In such case, the user will have to apply the patch first, and run nogo
again to get the fix to the issue.
---------
Co-authored-by: Zhongpeng Lin <[email protected]>
0 commit comments