fix
The fix command runs Gazelle in fix mode, which may make breaking changes such as deleting obsolete rules or renaming targets.
Usage
bazelle fix [flags] [path...]Flags
| Flag | Description |
|---|---|
--check | Check if BUILD files need fixing (exit 1 if changes needed) |
--dry-run | Show what would change without applying |
--verbose | Show detailed output |
Examples
Basic Fix
Fix all BUILD files in the workspace:
bazelle fixFix a specific directory:
bazelle fix ./src/mypackagePreview Changes
See what would change without applying:
bazelle fix --dry-runExample output:
--- src/old/BUILD.bazel+++ src/old/BUILD.bazel@@ -1,10 +1,3 @@ load("@rules_go//go:def.bzl", "go_library")
-go_library(- name = "deleted_package",- srcs = ["deleted.go"],- importpath = "github.com/org/repo/src/old",- visibility = ["//visibility:public"],-)- go_library( name = "old",CI Integration
Check if BUILD files need fixing:
bazelle fix --checkVerbose Mode
Show detailed information about changes:
bazelle fix --verboseWhen to Use fix vs update
| Scenario | Command |
|---|---|
| Added new source files | update |
| Modified existing files | update |
| Renamed source files | fix |
| Deleted source files | fix |
| Changed package structure | fix |
| Migrating rule types | fix |
What fix Does
The fix command may:
- Delete obsolete rules: Removes targets for deleted source files
- Rename targets: Updates target names to match new file names
- Update load statements: Removes unused loads, adds missing ones
- Reorganize rules: Consolidates split rules when appropriate
Passthrough Flags
Like update, unrecognized flags are passed to Gazelle:
bazelle fix -go_prefix=github.com/org/repoExit Codes
| Code | Mode | Meaning |
|---|---|---|
| 0 | Normal | Fix completed successfully |
| 0 | --check | BUILD files are up to date |
| 1 | --check | BUILD files need fixing |
| 1 | Any | Error occurred |
Safe Workflow
When making significant changes to your codebase:
# 1. Preview what fix would dobazelle fix --dry-run
# 2. Review the changes# 3. Apply if they look correctbazelle fix
# 4. Build to verifybazel build //...
# 5. Run testsbazel test //...