This module provides reusable Bazel macros for formatting Starlark, Python, YAML, and Rust files using aspect-build/rules_lint and buildifier. Rust formatting uses the shared S-CORE policies via @score_tooling//format_checker:rustfmt_with_policies.
- ✅ Supports Python (
ruff), YAML (yamlfmt), Starlark (buildifier) and Rust (policy-backedrustfmtby default) - ✅ Provides
format.fixandformat.checktargets - ✅ Simple macro-based usage for local formatting scope
- ✅ Centralized logic without Bazel module extensions
├── BUILD.bazel
├── macros.bzl
└── README.mdDefines the main macro to use in projects:
def use_format_targets(fix_name = "format.fix", check_name = "format.check"):
...This sets up:
format.fix— a multi-run rule that applies formatting toolsformat.check— a test rule that checks formatting
Declares this module and includes required dependencies:
module(name = "score_format_checker", version = "0.1.1")
bazel_dep(name = "aspect_rules_lint", version = "1.0.3")
bazel_dep(name = "buildifier_prebuilt", version = "7.3.1")
bazel_dep(name = "score_rust_policies", version = "0.0.2")bazel_dep(name = "score_format_checker", version = "0.1.1")
# If using local source:
local_path_override(
module_name = "score_format_checker",
path = "../tooling/format",
)
# Explicit dependencies required by the macro
bazel_dep(name = "aspect_rules_lint", version = "1.0.3")
bazel_dep(name = "buildifier_prebuilt", version = "7.3.1")
bazel_dep(name = "score_rust_policies", version = "0.0.2")load("@score_format_checker//:macros.bzl", "use_format_targets")
use_format_targets()This will register two Bazel targets:
bazel run //:format.fix— fixes format issuesbazel test //:format.check— fails on unformatted files
Add the following entry to .vscode/settings.json:
"rust-analyzer.rustfmt.overrideCommand": [
"${workspaceFolder}/.vscode/rustfmt.sh"
]Add .vscode/rustfmt.sh file with +x permissions:
#!/usr/bin/env bash
bazel run @score_tooling//format_checker:rustfmt_with_policies- Default formatter label:
@score_tooling//format_checker:rustfmt_with_policies, which wraps the upstreamrustfmtbinary with the sharedrustfmt.tomlpolicies fromscore_rust_policies.
✅ Centralized formatting config with local file scope ✅ Consistent developer experience across repositories ✅ Easily pluggable in CI pipelines or Git pre-commit hooks