skyfmt
skyfmt
Section titled “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.
Installation
Section titled “Installation”go install github.com/albertocavalcante/sky/cmd/skyfmt@latest# Format a single file (output to stdout)skyfmt BUILD.bazel
# Format and write changes back to filesskyfmt -w .
# Check if files need formatting (for CI)skyfmt --check .
# Preview changes as diffskyfmt -d lib.bzl
# Format with explicit file typeskyfmt -type=bzl script.star
# Format from stdincat BUILD.bazel | skyfmt| Flag | Description |
|---|---|
-w | Write result to file instead of stdout |
-d | Display diff instead of formatted output |
--check | Exit with non-zero status if files need formatting |
-type | Explicit file type: build, bzl, workspace, module, default |
-version | Print version and exit |
File Types
Section titled “File Types”skyfmt automatically detects file types based on filename, but you can override this with the -type flag:
| Type | Files |
|---|---|
build | BUILD, BUILD.bazel |
bzl | .bzl extension files |
workspace | WORKSPACE, WORKSPACE.bazel |
module | MODULE.bazel |
default | Generic Starlark files (.star, etc.) |
Supported File Extensions
Section titled “Supported File Extensions”skyfmt recognizes and formats a wide variety of Starlark files:
| Extension | Description |
|---|---|
.bzl | Bazel/Buck2 extensions |
.bxl | Buck2 BXL files |
.star | Generic Starlark |
.starlark | Generic Starlark |
.sky | Skycfg, Copybara |
.skyi | Type stub files |
.axl | Starlark config |
.ipd | Isopod (Kubernetes) |
.plz | Please Build |
.pconf, .pinc, .mpconf | Protoconf |
Special files (no extension): BUILD, BUILD.bazel, WORKSPACE, WORKSPACE.bazel, MODULE.bazel, BUCK, Tiltfile
Directory Handling
Section titled “Directory Handling”When given a directory, skyfmt recursively finds and formats all Starlark files:
# Format entire projectskyfmt -w .
# Check specific directoryskyfmt --check ./internal/rules/Hidden directories (starting with .) are automatically skipped.
CI Integration
Section titled “CI Integration”GitHub Actions
Section titled “GitHub Actions”- name: Check Starlark formatting run: | go install github.com/albertocavalcante/sky/cmd/skyfmt@latest skyfmt --check .Pre-commit
Section titled “Pre-commit”repos: - repo: local hooks: - id: skyfmt name: skyfmt entry: skyfmt --check language: system files: \.(bzl|bazel|star)$ pass_filenames: trueMakefile
Section titled “Makefile”.PHONY: format format-check
format: skyfmt -w .
format-check: skyfmt --check .Exit Codes
Section titled “Exit Codes”| Code | Meaning |
|---|---|
| 0 | Success (no issues or all files already formatted) |
| 1 | Files need formatting (with --check flag) |
| 2 | Error occurred (parse error, file not found, etc.) |
Examples
Section titled “Examples”Format and see diff
Section titled “Format and see diff”$ 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")Check mode in CI
Section titled “Check mode in CI”$ skyfmt --check .lib/utils.bzlrules/defs.bzl$ echo $?1Stdin/stdout pipeline
Section titled “Stdin/stdout pipeline”# Format and redirectcat BUILD.bazel | skyfmt > BUILD.bazel.formatted
# Use with explicit type for stdincat script.star | skyfmt -type=default