Skip analyzers that don't emit facts when ignoring diagnostics#4402
Merged
Skip analyzers that don't emit facts when ignoring diagnostics#4402
Conversation
jayconrod
approved these changes
Jul 29, 2025
Contributor
|
After upgrading I used |
Member
Author
|
Could you share one of these analyzers? Is it possible that they are failing in a way that doesn't cause nogo itself to fail (we had issues with panics in the past, but those have been fixed). Do you have analyzers that don't emit facts but depend on analyzers that do? |
Contributor
|
Tested with this dummy analyzer: package dummy
import (
"golang.org/x/tools/go/analysis"
)
var Analyzer = &analysis.Analyzer{
Name: "dummy",
Doc: "Dummy analyzer",
Run: func(pass *analysis.Pass) (any, error) {
return nil, nil
},
}nogo(
name = "nogo",
config = "//:.nogoconfig.json",
visibility = ["//visibility:public"],
deps = [
"<my analyzer>",
],
)go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.nogo(
nogo = "<my nogo target>",
)
❌
✔️ |
fmeum
pushed a commit
that referenced
this pull request
Aug 11, 2025
**What type of PR is this?** Bug fix **What does this PR do? Why is it needed?** After #4402, it is no longer possible to use a custom analyzer without having to declare a new `Fact` type. The build of a Go library will fail if the library contains any external dependencies. That's the case for executing gazelle by example (if we don't use a precompiled binary): ``` $ bazel run //:gazelle ERROR: .../external/gazelle++go_deps+org_golang_x_sync/errgroup/BUILD.bazel:3:11: output 'external/gazelle++go_deps+org_golang_x_sync/errgroup/errgroup.facts' was not created ERROR: .../external/gazelle++go_deps+org_golang_x_sync/errgroup/BUILD.bazel:3:11: Running nogo on @@gazelle++go_deps+org_golang_x_sync//errgroup:errgroup failed: not all outputs were created or valid ERROR: .../external/gazelle++go_deps+com_github_bazelbuild_buildtools/labels/BUILD.bazel:3:11: output 'external/gazelle++go_deps+com_github_bazelbuild_buildtools/labels/labels.facts' was not created ERROR: .../external/gazelle++go_deps+com_github_bazelbuild_buildtools/labels/BUILD.bazel:3:11: Running nogo on @@gazelle++go_deps+com_github_bazelbuild_buildtools//labels:labels failed: not all outputs were created or valid ERROR: .../external/gazelle++go_deps+in_gopkg_yaml_v3/BUILD.bazel:5:11: output 'external/gazelle++go_deps+in_gopkg_yaml_v3/yaml_v3.facts' was not created ERROR: .../external/gazelle++go_deps+in_gopkg_yaml_v3/BUILD.bazel:5:11: Running nogo on @@gazelle++go_deps+in_gopkg_yaml_v3//:yaml_v3 failed: not all outputs were created or valid ERROR: .../external/gazelle++go_deps+org_golang_x_sys/execabs/BUILD.bazel:3:11: output 'external/gazelle++go_deps+org_golang_x_sys/execabs/execabs.facts' was not created ERROR: .../external/gazelle++go_deps+org_golang_x_sys/execabs/BUILD.bazel:3:11: Running nogo on @@gazelle++go_deps+org_golang_x_sys//execabs:execabs failed: not all outputs were created or valid ... ``` **Other notes for review** This review continue to skip analysers when ignoring diagnostics, but return a valid `pkg` to create the missing `.facts` file required by the validation action, and incidentally, fix a potential crash at line https://github.com/bazel-contrib/rules_go/blob/1f993522f463c142c5516f94852c3d6597f717c6/go/tools/builders/nogo_main.go#L98.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Performance improvement
What does this PR do? Why is it needed?
Avoid unnecessary work by skipping analyzers that don't emit facts when reported diagnostics are known to be ignored.
Which issues(s) does this PR fix?
Work towards #4327
Other notes for review