bazel-contrib / bazel-contrib/buildtools
[buildifier] Only the first unusued loaded symbol is marked as autofixable
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.2k
- Forks
- 470
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 13
Description
When a file has multiple unused symbols in a single load statement, only the first unused symbol emits a warning with autoFixable: true. Subsequent symbols are marked as "actionable", but not "autoFixable". However, if you run buildifier with -lint fix, it will remove both unused symbols. This is annoying when writing linter wrappers as I can't tell which things from --lint warn will be handled for me (so I don't need to show them to the user) on a subsequent run with --lint fix.
Simple repro here on v8.5.1:
$ .local/bin/buildifier --version
buildifier version: 8.5.1
buildifier scm revision: v8.5.1
$ echo -e 'load("foo.bzl", "bar", "baz", "quz")\nbar(name="target")' | .local/bin/buildifier -lint warn -mode check -format json -path BUILD.bazel | jq '.files[0]'
{
"filename": "BUILD.bazel",
"formatted": false,
"valid": true,
"warnings": [
{
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 28
},
"category": "load",
"actionable": true,
"autoFixable": true,
"message": "Loaded symbol \"baz\" is unused. Please remove it.\nTo disable the warning, add '@unused' in a comment.",
"url": "https://github.com/bazelbuild/buildtools/blob/main/WARNINGS.md#load"
},
{
"start": {
"line": 1,
"column": 32
},
"end": {
"line": 1,
"column": 35
},
"category": "load",
"actionable": true,
"autoFixable": false,
"message": "Loaded symbol \"quz\" is unused. Please remove it.\nTo disable the warning, add '@unused' in a comment.",
"url": "https://github.com/bazelbuild/buildtools/blob/main/WARNINGS.md#load"
}
]
}
$ { PROG=$(echo -e 'load("foo.bzl", "bar", "baz", "quz")\nbar(name="target")'); diff -u <((echo "$PROG")) <((echo "$PROG" | .local/bin/buildifier -lint fix -path BUILD.bazel)); }
--- /dev/fd/63 2026-04-14 09:44:01
+++ /dev/fd/62 2026-04-14 09:44:01
@@ -1,2 +1,3 @@
-load("foo.bzl", "bar", "baz", "quz")
-bar(name="target")
+load("foo.bzl", "bar")
+
+bar(name = "target")
I'm guessing there's something to do with how multiple fixes on the same line are handled, but haven't dug into the buildifier code too much to verify where it's coming from .
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 with the buildifier CLI behavior shown for BUILD.bazel: reproduce the load statement with multiple unused symbols using -lint warn -mode check -format json, then compare it with -lint fix. Trace how the load warnings and fixes are generated; done means every unused symbol removed by -lint fix is reported with autoFixable: true by -lint warn.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100