Skip to main content
Version: 5.10.x

Formatting and Linting

Workflows recommends using rules_lint to setup linting and formatting rules. Follow the instructions in that repository to install it.

Formatting

The simplest configuration for a format check looks like this:

.aspect/workflows/config.yaml
tasks:
- format:

Workflows will run bazel run //:format and verify that no changes are made to any source files. If changes are made, the task will fail, and will recommend that the developer remediate it by running bazel run //:format.

note

Support for linting is coming in a future Workflows release.

Warning vs Error

Getting a red CI for formatting nits can be frustrating for developers, as there is nothing wrong with the code. Formatting is fast enough to be performed as a pre-commit hook, which ensures files are formatted before the CI system sees them. See Install as a pre-commit hook for information on setting this up.

If you have a pre-commit hook then we recommend setting this to be a warning instead, using soft_fail:

.aspect/workflows/config.yaml
tasks:
- format:
soft_fail: true

Specify targets

The two format targets may be customized in the configuration:

.aspect/workflows/config.yaml
tasks:
- format:
# Workflows will 'bazel run' this target to format the files
target: //path/to:format-check
# Developers will be asked to 'bazel run' this target to format their files
fix_target: //path/to:formater

Linting

coming soon

A lint task will be included in the next release of Aspect Workflows.

Buildifier

Buildifier is a formatter and linter for Bazel code (BUILD and *.bzl files).

Buildifier is a special case, because rules_lint only runs linters over *_library targets, while BUILD files are not included in any such target.

The simplest configuration looks like this:

.aspect/workflows/config.yaml
tasks:
- buildifier:

Workflows will bazel run //:buildifier.check, and it exits non-zero, then the task will fail. It will print the suggested changes that the developer should apply to fix it, by running bazel run //:buildifier.

Specify targets

You can choose specific targets to use for running Buildifier:

.aspect/workflows/config.yaml
tasks:
- buildifier:
# Workflows will 'bazel run' this target to verify that buildifier is "happy"
target: //path/to:buildifier_check
# Developers will be asked to 'bazel run' this target to apply Buildifier suggestions
fix_target: //path/to:buildifier

Per the Buildifier documentation, the "check" target should use mode = diff and lint_mode = warn while the "fix" target should use mode = fix and lint_mode = fix.