-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
Using external analyzers with nogo results in cycle #2759
Comments
Could you confirm |
I am running into the same issue on my end
Can confirm that it's defined with package main
import (
"log"
"os"
"strings"
"text/template"
"golang.org/x/tools/go/analysis"
"honnef.co/go/tools/staticcheck"
)
const (
analyzersTpl = `package {{ .Key }}
import (
_ "golang.org/x/tools/go/analysis"
"honnef.co/go/tools/staticcheck"
)
var Analyzer = staticcheck.Analyzers["{{ .Key }}"]
`
buildTpl = `# gazelle:ignore
load("@io_bazel_rules_go//go:def.bzl", "go_tool_library")
go_tool_library(
name = "{{ .Key }}",
srcs = ["analyzer.go"],
importpath = "domain/group/repo/projects/staticcheck-codegen/_gen/{{ .Key }}",
deps = [
"@co_honnef_go_tools//staticcheck",
"@org_golang_x_tools//go/analysis:go_tool_library",
],
visibility = ["//visibility:public"],
)`
)
func main() {
tpl := template.Must(template.New("source").Parse(analyzersTpl))
buildTpl := template.Must(template.New("source").Parse(buildTpl))
err := os.RemoveAll("_gen")
if err != nil {
log.Fatalf("os.RemoveAll: %v", err)
}
err = os.Mkdir("_gen", os.ModePerm)
if err != nil {
log.Fatalf("os.Mkdir: %v", err)
}
for k, v := range staticcheck.Analyzers {
k = strings.ToLower(k)
err = os.Chdir("_gen")
if err != nil {
log.Fatalf("os.Chdir: %v", err)
}
log.Println("Creating " + k)
err = os.Mkdir(k, os.ModePerm)
if err != nil {
log.Fatalf("os.Mkdir: %v", err)
}
err = os.Chdir(k)
if err != nil {
log.Fatalf("os.Chdir: %v", err)
}
tplFiles := []struct {
tmplate *template.Template
fileName string
}{
{tpl, "analyzer.go"},
{buildTpl, "BUILD.bazel"},
}
data := struct {
Key string
Analyzer *analysis.Analyzer
}{
Key: k,
Analyzer: v,
}
for _, tplFile := range tplFiles {
outFile, err := os.Create(tplFile.fileName)
if err != nil {
log.Fatalf("os.Create: %v", err)
}
if err = tplFile.tmplate.Execute(outFile, data); err != nil {
log.Fatalf("template.Execute failed: %v", err)
}
}
os.Chdir("../../")
}
} |
This should just work now that |
@robfig I can confirm that the issue has been fixed on master's latest commit If you guys can tag a new release of rules_go for this, I could supply an update to https://github.com/sluongng/staticcheck-codegen that would help setup |
I have updated https://github.com/sluongng/staticcheck-codegen with latest code of mine that included some sugar helper:
Have a look at the README and try it for yourself <3 |
@sluongng we have discussed this topic with the team already, but adding support for staticcheck directly in rules_go would be great imho |
@steeve no objection to that... my current approach do feels a bit hacky (manual code gen) so I didn't want to put it inside rules_go. Let me know if you have any suggestions. |
I guess the same problem would be wether to run all the analyzers in staticcheck or have some kind of ui to chose which |
You can choose which analyzer to run on which package via the current I think the better UX would be something like this:
(1) and (2) are possible to put in rules_go today with a bit of work. For (3) it's not possible, at least not with the current implementation of |
What version of rules_go are you using?
v0.24.9
What version of gazelle are you using?
v0.22.2
What version of Bazel are you using?
Does this issue reproduce with the latest releases of all the above?
Yes.
What operating system and processor architecture are you using?
Any other potentially useful information about your toolchain?
Pretty vanilla.
What did you do?
Reference an external repository to use a nogo analyzer.
What did you expect to see?
Successful build.
What did you see instead?
I think the problem is that gazelle generates go_library for the exportloopref dependency. I'm not sure how to work around this.
The text was updated successfully, but these errors were encountered: