bazel-contrib / bazel-contrib/rules_go
nogo should provide a json tree with suggested fixes.
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 762
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
What version of rules_go are you using?
v0.36.0
What version of gazelle are you using?
v0.28.0
What version of Bazel are you using?
v5.3.2
Does this issue reproduce with the latest releases of all the above?
Yes
What operating system and processor architecture are you using?
Linux
Any other potentially useful information about your toolchain?
No
What did you do?
bazel build --output_groups=nogo_json_tree //path_to_target/...
What did you expect to see?
A json tree with suggested fixes from analyzers
What did you see instead?
Nothing.
Current state of the world
At the moment, nogo, creates a similar output to what an analyzer will output using the standard go toolchain if there is a diagnostic from any analyzer setup in nogo.
nogo output:
> bazel build …
bazel_workspace/example/example.go:43:3: This is an error message from our custom analyzer. (analyzer_name)
go unitchecker output:
> go run . example/example.go
example/example.go:43:3: This is an error message from our custom analyzer.
The error message from bazel is better as it contains the analyzer name; this becomes handy when there is more than one diagnostic.
Go analysis API provides suggested fixes as part of analysis.Diagnostic struct. These suggested fixes are used by unitchecker to fix the file.
In the latest version of https://pkg.go.dev/golang.org/x/tools there is a new -json flag that we can pass to unitchecker that will show us JSON with all the information needed to apply those fixes.
Example:
> go run . -json examples/example.go
{
"command-line-arguments": {
"useprint": [
{
"posn": "examples/example.go:10:2",
"message": "update this line",
"suggested_fixes": [
{
"message": "use fmt.Print() instead",
"edits": [
{
"filename": "/examples/example.go",
"start": 73,
"end": 93,
"new": "fmt.Print(\"hello\")"
}
]
}
]
}
]
}
}
It is not part of nogo to apply those fixes, but we should be able to get this JSON tree and create a small tool that provides this functionality.
Proposal
Add a new option in --output_groups that outputs the value of this JSON tree.
> bazel build --output_groups=nogo_json_tree //path_to_target/...
{
"nogo": {
"custom_analyzer": [
{
"posn": "examples/example.go:10:2",
"message": "update this line",
"suggested_fixes": [
{
"message": "use fmt.Print() instead",
"edits": [
{
"filename": "/examples/example.go",
"start": 73,
"end": 93,
"new": "fmt.Print(\"hello\")"
}
]
}
]
}
]
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing nogo's existing diagnostic output and the Bazel --output_groups handling; the issue does not name specific files or tests. Compare the Go analysis Diagnostic data and unitchecker -json output, then define the output-group path and verify that builds emit the requested JSON tree with suggested fixes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100