← Back to Pull requests

build(bazel): buildifier as a required pre-commit check, format Bazel files #4040

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 17, 2026 22:56 UTC
Author

Merge order: land after #4039. #4039 rewrites dev/bazel/cc.bzl (and TODO.md, AGENTS.md), which the formatting commit also rewrites. If #4039 lands first, this PR has to be regenerated on the new main with the one-liner below before it merges.

Summary

Two commits, in review order:

build(bazel): buildifier pre-commit hook in check mode     b01ba738b   hook config + docs
build(bazel): format Bazel files with buildifier 8.2.1     2cba8f932   formatting, skip in review (also load() order and 5 label rewrites, see Evidence)

The .git-blame-ignore-revs entry for the formatting commit comes as a follow-up PR after this merges, with the formatting commit's real SHA on main. A merge may not keep the SHA of this branch.

.pre-commit-config.yaml
  keith/pre-commit-buildifier @ 8.2.1  (hook pins buildifier v8.2.1 by sha256)
    buildifier: -mode=check -lint=off -buildifier_disable=listsort -buildifier_disable=callsort
    exclude: \.tpl\.
dev/bazel/AGENTS.md, dev/bazel/TODO.md   how to format; lint and sort follow-ups

  • Hook. buildifier runs in check mode: it fails and does not rewrite a file it would reformat. Azure FormatterChecks runs pre-commit run --all-files, so this is the required check.

  • Lint is off (-lint=off). buildifier -lint=warn reports 140 warnings in 14 categories, mostly unused load() symbols, missing docstrings and constant-glob. Fixing them is a semantic change to review on its own, so they are a TODO item. Turn lint on once they are fixed.

  • Sort is off (-buildifier_disable=listsort -buildifier_disable=callsort). Buildifier sorts deps and srcs, and reorders keyword arguments. A sorted deps list reorders the -I/-D flags of compile actions, which changes the aquery output. Sorting keyword arguments moves comments, which fails the two-line comment-block check. The formatting keeps list order and argument order. (The flag takes one rewrite name per occurrence; a comma list disables nothing.)

  • Templates are skipped. some .tpl.BUILD files are not valid Starlark until expand_template fills them in; formatting the others would only be churn.

  • Scope: 203 files match (BUILD, BUILD.bazel, MODULE.bazel, .bzl, .BUILD); 177 need reformatting. dev/bazel/AGENTS.md lists the same set. The count is 177, not 178 as before: dev/bazel/flags.bzl came in formatted with #4041.
  • Regenerate the formatting on top of another branch (run from the repo root):

    git ls-files | grep -E '(^|/)(BUILD|BUILD\.bazel|MODULE\.bazel)$|\.bzl$|\.BUILD$' | grep -v '\.tpl\.' | xargs buildifier -mode=fix -lint=off -buildifier_disable=listsort -buildifier_disable=callsort
    

    Evidence

  • Rebased: onto origin/main 7301a40f1 (includes #4014, #4038, #4041 and #4050). The hook commit was cherry-picked; the only overlapping hunk (in dev/bazel/TODO.md) auto-merged. The formatting commit was regenerated with buildifier 8.2.1 and the flags above, and the blame-ignore entry is left to a follow-up after merge. Nothing was conflict-resolved by hand.

  • Before: the unformatted tree under buildifier -mode=check fails on 177 files (the -mode=fix run changes exactly those files).

  • After: buildifier -mode=check with the same flags over all 203 files: exit 0. A second -mode=fix pass changes nothing (idempotent). python3 dev/bazel/tests/check_starlark_policy.py .: OK (2 allowed site(s)).

  • Semantics: bazel query '//...' (2682 lines) and bazel aquery 'deps(//:release)' (3463 actions) are byte-identical to origin/main 7301a40f1. bazel aquery 'deps(//dev/bazel/...)' (15425 actions) differs only in ActionKey on 40 runfiles actions: the source manifests and runfiles trees of the dev/bazel/tests targets, whose inputs are the reformatted files. Their command lines, inputs and outputs are identical.

  • Beyond whitespace (commit 2): buildifier also moves load() statements above package() and sorts them and their symbols (161 of the 177 files). It shortens 5 labels in 2 files, @x//:x to @x (Bazel resolves both to the same label). dal_deps labels are not rewritten. A Python AST comparison of each changed file before and after: 14 identical, 161 identical once load order and load symbol order are ignored, 2 identical once the label rewrites are also normalized, 0 other (14 + 161 + 2 = 177).

  • Scope check: 203 files match, 177 changed; dev/bazel/AGENTS.md lists the same set for this tree. The hook's files regex is wider (it also matches .bazel, .sky, WORKSPACE), so a new file of those kinds would trip the hook but not the one-liner.
  • Merge Danger

    Door: two-way. The formatting commit reverts with git revert; the hook can be removed from the config.

    Blast Radius: Bazel file diffs only (177 files). No code, no build flags, no targets change, but every open Bazel PR that edits a reformatted file will conflict on rebase. The hook also downloads buildifier from GitHub on the first run; CI needs bash and sha256sum or shasum, which the Linux agents have.

    🤖 Generated with Claude Code

    <details>
    <summary>Checklist:</summary>

    Completeness and readability

  • I have commented my code, particularly in hard-to-understand areas.

  • I have updated the documentation to reflect the changes or created a separate PR with updates and provided its number in the description, if necessary.

  • Git commit message contains an appropriate signed-off-by string.

  • I have resolved any merge conflicts that might occur with the base branch. (Rebased onto origin/main 7301a40f1; the formatting commit was regenerated, not conflict-resolved.)
  • Testing

  • I have run it locally and tested the changes extensively.

  • All CI jobs are green or I have provided justification why they aren't. ("Nightly-test / oneDAL Windows Bazel test" runs main's workflow via workflow_run and fails on its Windows DPC++ pca link step, LNK1104, also red on #4049, which removes that step. CodeFactor is external and still running.)
  • Performance

  • I have provided justification why performance and/or quality metrics have changed or why changes are not expected: no compiled code changes; query and the //:release aquery are byte-identical to the base, and the //dev/bazel/... aquery differs only in ActionKey on 40 runfiles actions (see Evidence).
  • </details>

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: Alexandr-Solovev Review duration: 7039m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4040"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%