Skip to content

[buildifier] Only the first unusued loaded symbol is marked as autofixable #1462

Description

@nataliejameson

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 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions