Skip to content

skyfmt

A Starlark code formatter that wraps buildtools formatting with a modern CLI interface. Supports multiple Bazel/Starlark file types and provides check mode for CI integration.

Terminal window
go install github.com/albertocavalcante/sky/cmd/skyfmt@latest
Terminal window
# Format a single file (output to stdout)
skyfmt BUILD.bazel
# Format and write changes back to files
skyfmt -w .
# Check if files need formatting (for CI)
skyfmt --check .
# Preview changes as diff
skyfmt -d lib.bzl
# Format with explicit file type
skyfmt -type=bzl script.star
# Format from stdin
cat BUILD.bazel | skyfmt
FlagDescription
-wWrite result to file instead of stdout
-dDisplay diff instead of formatted output
--checkExit with non-zero status if files need formatting
-typeExplicit file type: build, bzl, workspace, module, default
-versionPrint version and exit

skyfmt automatically detects file types based on filename, but you can override this with the -type flag:

TypeFiles
buildBUILD, BUILD.bazel
bzl.bzl extension files
workspaceWORKSPACE, WORKSPACE.bazel
moduleMODULE.bazel
defaultGeneric Starlark files (.star, etc.)

skyfmt recognizes and formats a wide variety of Starlark files:

ExtensionDescription
.bzlBazel/Buck2 extensions
.bxlBuck2 BXL files
.starGeneric Starlark
.starlarkGeneric Starlark
.skySkycfg, Copybara
.skyiType stub files
.axlStarlark config
.ipdIsopod (Kubernetes)
.plzPlease Build
.pconf, .pinc, .mpconfProtoconf

Special files (no extension): BUILD, BUILD.bazel, WORKSPACE, WORKSPACE.bazel, MODULE.bazel, BUCK, Tiltfile

When given a directory, skyfmt recursively finds and formats all Starlark files:

Terminal window
# Format entire project
skyfmt -w .
# Check specific directory
skyfmt --check ./internal/rules/

Hidden directories (starting with .) are automatically skipped.

- name: Check Starlark formatting
run: |
go install github.com/albertocavalcante/sky/cmd/skyfmt@latest
skyfmt --check .
repos:
- repo: local
hooks:
- id: skyfmt
name: skyfmt
entry: skyfmt --check
language: system
files: \.(bzl|bazel|star)$
pass_filenames: true
.PHONY: format format-check
format:
skyfmt -w .
format-check:
skyfmt --check .
CodeMeaning
0Success (no issues or all files already formatted)
1Files need formatting (with --check flag)
2Error occurred (parse error, file not found, etc.)
Terminal window
$ skyfmt -d BUILD.bazel
--- BUILD.bazel
+++ BUILD.bazel
@@ -1 +1 @@
-load("@rules_go//go:def.bzl","go_library")
+load("@rules_go//go:def.bzl", "go_library")
Terminal window
$ skyfmt --check .
lib/utils.bzl
rules/defs.bzl
$ echo $?
1
Terminal window
# Format and redirect
cat BUILD.bazel | skyfmt > BUILD.bazel.formatted
# Use with explicit type for stdin
cat script.star | skyfmt -type=default