buildifier task ran a Bazel target (defaulting to //:buildifier.check) that invoked buildifier in check mode against the workspace’s Starlark files, surfacing lint warnings and formatting diffs as CI annotations.
There are two ways to replace it with Aspect CLI tasks:
- config.axl alias (recommended) — register
aspect buildifieras a first-class CLI command via aformat.alias()declaration in.aspect/config.axl. No BUILD target needed, norules_lintdependency. - BUILD target approach — declare a Starlark-only
format_multiruntarget and pointaspect formatat it via--formatter-target.
What changed
| Area | YAML-configured tasks | Aspect CLI tasks |
|---|---|---|
| Invocation | rosetta run buildifier | aspect buildifier (config.axl alias) or aspect format --formatter-target=//tools/format:format-starlark (BUILD target approach) |
| Check target | target: (default //:buildifier.check) | formatter_target default set in config.axl, or passed via --formatter-target on the CLI |
| Fix target | fix_target: (default //:buildifier) | Both approaches run the fix target by default; the legacy “check then suggest fix” annotation is replaced by aspect format’s pre/post-snapshot diff flow |
| Lint warnings | Surfaced as a separate annotation pointing at buildtools/WARNINGS.md | Not surfaced separately — buildifier’s -mode=fix applies what it can fix; warnings appear in aspect format’s output and the unified format check-run |
| Diff archival | Reused the legacy format task’s diff handling when invoked via bazel run | aspect format --upload-format-diff archives the patch as format.patch via ArtifactsTrait. See aspect format → Diff archival |
| Soft-fail | soft_fail: true downgraded the failure to a warning | --soft-fail. See aspect format → Soft-fail |
| Ignore patterns | n/a | --ignore-pattern (repeatable). See aspect format → Ignore patterns |
config.axl alias approach (recommended)
This approach registersaspect buildifier as a real CLI command by declaring a format.alias() in .aspect/config.axl. It does not require a BUILD target or a rules_lint dependency — only buildifier_prebuilt.
Setup
MODULE.bazel:
.aspect/config.axl (create if it doesn’t exist):
format.alias() creates an aspect buildifier command pre-configured with a formatter_target and include_patterns. Running aspect buildifier is equivalent to running aspect format with those defaults baked in — only Starlark files are touched, no other formatters run.
ctx.tasks.add(buildifier) registers the alias as a CLI command. Until that line is present, aspect buildifier won’t exist.CI configuration
Add a dedicatedbuildifier job alongside your other Aspect CLI tasks. If your repo also runs aspect format for other languages, run both jobs in parallel — they don’t overlap because include_patterns in the alias limits buildifier to Starlark files.
BUILD target approach
Use this approach if you prefer to keep buildifier wired through a Bazel target intools/format/BUILD.bazel.
Wiring buildifier into your formatter target
The default formatter target is//tools/format:format. Add starlark = to its format_multirun invocation, pointing at a buildifier binary from buildifier_prebuilt:
MODULE.bazel:
tools/format/BUILD.bazel:
aspect format will now run buildifier on Starlark files as part of its normal flow. No new task wiring, no new CI step required.
The legacy task’s
target and fix_target (//:buildifier.check / //:buildifier) are no longer used. format_multirun produces both the fix target (//tools/format:format) and a check-only sibling (//tools/format:format.check) automatically; aspect format invokes the fix target and decides pass/fail by diffing the working tree before and after. You can delete the old labels once nothing references them.Running buildifier as a dedicated task
Some repos want buildifier on its own CI step — a fast Starlark-only check that runs in parallel with (and finishes well before) the bigger language formatters. The legacybuildifier task gave that for free.
The new pattern: declare a second format_multirun target that only sets starlark =, then point a dedicated aspect format invocation at it via --formatter-target. The default formatter target in tools/format:format keeps every other language; the Starlark-only target lives alongside it.
tools/format/BUILD.bazel:
aspect format steps in parallel — one for buildifier and one for everything else. Use --task:name to give each a distinct status check name, and --ignore-pattern to keep them from doing duplicate work:
format_multirun per group of formatters you want as a separate CI step (e.g. one for Starlark, one for JavaScript/TypeScript/CSS via Prettier, one for everything else), and use --ignore-pattern on the catch-all step to avoid re-formatting files the dedicated step already handled.
Pinning
--formatter-target for a dedicated buildifier step at the CLI flag level — rather than in .aspect/config.axl — is intentional. config.axl is global to all aspect format invocations, so setting formatter_target there would also redirect your default aspect format (the one developers run locally). Per-CI-step overrides belong on the CLI. (This constraint does not apply to the config.axl alias approach, which registers a separate buildifier command rather than overriding format.)Lint warnings: use aspect lint
The legacy task surfaced buildifier’s lint warnings (the --lint=warn output that lists rule violations like module-docstring, name-conventions, etc.) as a dedicated annotation pointing at buildtools/WARNINGS.md.
In the new world, that lives in aspect lint, not aspect format. format_multirun (and the config.axl alias) runs buildifier in fix mode and auto-applies what it can; warnings buildifier won’t auto-fix don’t surface as a status check from aspect format. To gate on those warnings, wire buildifier in as a rules_lint lint aspect and run it from aspect lint.
tools/lint/linters.bzl:
bzl_library targets. To lint BUILD.bazel, MODULE.bazel, or other Starlark files, add tags = ["starlark"] (or tags = ["lint-with-buildifier"]) to a target listing them in srcs:
//tools/lint:linters.bzl%buildifier to your aspect lint invocation — either as --aspect on the CLI or in .aspect/config.axl. See the aspect lint migration guide for the wiring details. Output is SARIF, deduplicated and (on GitHub Actions, by default) posted as PR comments by the GithubLintComments feature.
Recommended split:
| Concern | Task | Mode |
|---|---|---|
| Auto-applied formatting + simple fixes | aspect buildifier or aspect format (Starlark via buildifier) | --lint=fix (in-place edits) |
| Warnings that need human attention | aspect lint --aspect=…%buildifier | --lint=warn (SARIF + PR comments) |
format_multirun, diagnostics in the lint aspect — so the buildifier wiring matches the rest of your linters.
