Skip to content

Feature Request: Migrate Buildifier to Bazel Lint Umbrella #9858

@oharboe

Description

@oharboe

If we agree on this, then we can convert this into PR at a click of a button.

Description

Buildifier (format + lint for BUILD, .bzl, and MODULE.bazel files) currently
runs as a standalone GitHub Actions workflow
(.github/workflows/buildifier.yaml) that downloads its own binary and
caches it independently. This should be migrated to the Bazel lint umbrella
(//:lint_test and //:fix_lint) for consistency with how TCL linting
already works.

Current state

The GitHub Actions workflow does two things:

# Format check
./buildifier -r -mode=check -lint=off .

# Lint check
./buildifier -r -lint=warn .

The tool version (v8.2.1) is pinned in the workflow YAML, not in Bazel's
dependency management. A .buildifier.json config already exists at the
repo root.

Problem

  1. Cannot run locally — developers must push and wait for CI to discover
    buildifier violations. This violates
    POLA:
    bazelisk run //:fix_lint should fix everything it can and report the
    rest, but currently it knows nothing about BUILD files.

  2. Version drift — the buildifier version is pinned in GitHub Actions
    YAML, separate from Bazel's hermetic dependency management
    (bazel/requirements.in, MODULE.bazel). It can drift out of sync
    with what developers run locally (if they run it at all).

  3. Inconsistent pattern — TCL linting already uses the Bazel lint
    umbrella. Every additional language that stays outside the umbrella is
    a special case that new contributors have to discover separately.

Proposed targets

Per the naming convention:

Target What it does
//:lint_bzl_test buildifier -r -mode=check -lint=warn . (read-only)
//:fmt_bzl_test buildifier -r -mode=check -lint=off . (format only)
//:tidy_bzl buildifier -r -mode=fix -lint=fix . (auto-fix)

Wire into umbrellas:

  • Add lint_bzl_test and fmt_bzl_test to //:lint_test
  • Add buildifier fix step to bazel/fix_lint.sh

Suggested Solution

  1. Add buildifier as a Bazel-managed tool dependency (it's already available
    as a @buildifier Bazel module)
  2. Create bazel/bzl_lint_test.sh, bazel/bzl_fmt_test.sh, bazel/bzl_tidy.sh
    following the same pattern as bazel/tcl_lint_test.sh etc.
  3. Add sh_test / sh_binary targets in BUILD.bazel
  4. Wire into //:lint_test and bazel/fix_lint.sh
  5. Once validated, retire .github/workflows/buildifier.yaml

The .buildifier.json config (mode: fix, lint: fix, warnings: all)
already exists and can be reused by the new scripts.

Additional Context

  • Bazel Lint Targets — umbrella framework and naming convention
  • Shell Script Conventions — idiom for new wrapper scripts
  • .github/workflows/buildifier.yaml — current CI workflow to be retired
  • .buildifier.json — existing buildifier config

Suggested Solution

No response

Additional Context

No response

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