Starlark linter: Buildifier
Blog post from Aspect Build
Bazel employs a configuration language called Starlark, a Python dialect optimized for parallel evaluation to speed up builds, and necessitates linting and formatting like any programming language. Buildifier is a tool designed to format Bazel BUILD and .bzl files according to standard conventions, easing the process of maintaining code consistency and eliminating discussions around code formatting. Developers can install Buildifier in various ways, with pre-built binaries being a recommended option for convenience. To integrate Buildifier into development workflows, developers can use tools like direnv and bazel_env.bzl to manage the PATH, and configure editors like VSCode to run Buildifier automatically on file save. Additionally, setting up Aspect's rules_lint allows for a unified formatting setup across different languages, while pre-commit hooks ensure code is formatted before committing. Enforcing formatting consistency helps avoid unnecessary changes in pull requests. Buildifier's linting feature offers around 100 checks for Starlark files, primarily focused on Bazel's standard library, and it's recommended to implement these checks incrementally following the "Ratchet principle" to manage disruptions in the development process. The Aspect Workflows platform simplifies integrating Buildifier into CI systems by offering it as a task type, allowing for smoother setup and adherence to best practices.