From f5ceb37b1b76eaa496208938ca01c7645f09e840 Mon Sep 17 00:00:00 2001 From: Paul Berman Date: Thu, 26 Mar 2026 10:50:31 -0500 Subject: [PATCH 1/2] feat(builtins): add buildifier format and lint Add buildifier as two built-in linters for Bazel/Starlark files: - buildifier_format: formatting check/fix using -mode=check - buildifier_lint: lint warnings + formatting using -lint=warn/-lint=fix Covers BUILD, BUILD.bazel, WORKSPACE, WORKSPACE.bazel, MODULE.bazel, *.bzl, *.star, and *.sky files. --- pkl/builtins/buildifier_format.pkl | 53 ++++++++++++++++++++++++++++++ pkl/builtins/buildifier_lint.pkl | 53 ++++++++++++++++++++++++++++++ test/builtin_tool_stubs/buildifier | 4 +++ 3 files changed, 110 insertions(+) create mode 100644 pkl/builtins/buildifier_format.pkl create mode 100644 pkl/builtins/buildifier_lint.pkl create mode 100755 test/builtin_tool_stubs/buildifier diff --git a/pkl/builtins/buildifier_format.pkl b/pkl/builtins/buildifier_format.pkl new file mode 100644 index 000000000..30cbeebde --- /dev/null +++ b/pkl/builtins/buildifier_format.pkl @@ -0,0 +1,53 @@ +import "../Builtins.pkl" +import "../Config.pkl" +import "./test/helpers.pkl" + +@Builtins.meta { + category = "Build Systems" + description = "Formatter for Bazel BUILD, WORKSPACE, and Starlark files" + project_indicators { + new { file = "WORKSPACE" } + new { file = "WORKSPACE.bazel" } + new { file = "MODULE.bazel" } + new { glob = "**/BUILD.bazel" } + } +} +buildifier_format = new Config.Step { + glob = List( + "**/BUILD", + "**/BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + "MODULE.bazel", + "**/*.bzl", + "**/*.star", + "**/*.sky" + ) + check = "buildifier -mode=check {{ files }}" + fix = "buildifier {{ files }}" + tests { + local const testMaker = new helpers.TestMaker { filename = "BUILD.bazel" } + local const before = + """ + load("@rules_cc//cc:cc_library.bzl", "cc_library") + + cc_library( name="foo", + srcs=["Foo.cc"],) + + """ + local const after = + """ + load("@rules_cc//cc:cc_library.bzl", "cc_library") + + cc_library( + name = "foo", + srcs = ["Foo.cc"], + ) + + """ + ["check bad file"] = testMaker.checkFail(before, 4) + ["check good file"] = testMaker.checkPass(after) + ["fix bad file"] = testMaker.fixPass(before, after) + ["fix good file"] = testMaker.fixPass(after, after) + } +} diff --git a/pkl/builtins/buildifier_lint.pkl b/pkl/builtins/buildifier_lint.pkl new file mode 100644 index 000000000..ca4293a73 --- /dev/null +++ b/pkl/builtins/buildifier_lint.pkl @@ -0,0 +1,53 @@ +import "../Builtins.pkl" +import "../Config.pkl" +import "./test/helpers.pkl" + +@Builtins.meta { + category = "Build Systems" + description = "Linter for Bazel BUILD, WORKSPACE, and Starlark files" + project_indicators { + new { file = "WORKSPACE" } + new { file = "WORKSPACE.bazel" } + new { file = "MODULE.bazel" } + new { glob = "**/BUILD.bazel" } + } +} +buildifier_lint = new Config.Step { + glob = List( + "**/BUILD", + "**/BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + "MODULE.bazel", + "**/*.bzl", + "**/*.star", + "**/*.sky" + ) + check = "buildifier -mode=check -lint=warn {{ files }}" + fix = "buildifier -lint=fix {{ files }}" + tests { + local const testMaker = new helpers.TestMaker { filename = "BUILD.bazel" } + local const before = + """ + cc_library( + name = "foo", + srcs = ["Foo.cc"], + ) + + """ + local const after = + """ + load("@rules_cc//cc:cc_library.bzl", "cc_library") + + cc_library( + name = "foo", + srcs = ["Foo.cc"], + ) + + """ + ["check bad file"] = testMaker.checkFail(before, 4) + ["check good file"] = testMaker.checkPass(after) + ["fix bad file"] = testMaker.fixPass(before, after) + ["fix good file"] = testMaker.fixPass(after, after) + } +} diff --git a/test/builtin_tool_stubs/buildifier b/test/builtin_tool_stubs/buildifier new file mode 100755 index 000000000..124da7c66 --- /dev/null +++ b/test/builtin_tool_stubs/buildifier @@ -0,0 +1,4 @@ +#!/usr/bin/env -S mise tool-stub + +version = "8.5.1" +tool = "buildifier" From 12dba935844bc62d672bf62b573f090dcba36af5 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 30 Apr 2026 21:19:45 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- pkl/builtins/buildifier_format.pkl | 21 +++++++++++---------- pkl/builtins/buildifier_lint.pkl | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/pkl/builtins/buildifier_format.pkl b/pkl/builtins/buildifier_format.pkl index 30cbeebde..8874fe5af 100644 --- a/pkl/builtins/buildifier_format.pkl +++ b/pkl/builtins/buildifier_format.pkl @@ -13,16 +13,17 @@ import "./test/helpers.pkl" } } buildifier_format = new Config.Step { - glob = List( - "**/BUILD", - "**/BUILD.bazel", - "WORKSPACE", - "WORKSPACE.bazel", - "MODULE.bazel", - "**/*.bzl", - "**/*.star", - "**/*.sky" - ) + glob = + List( + "**/BUILD", + "**/BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + "MODULE.bazel", + "**/*.bzl", + "**/*.star", + "**/*.sky", + ) check = "buildifier -mode=check {{ files }}" fix = "buildifier {{ files }}" tests { diff --git a/pkl/builtins/buildifier_lint.pkl b/pkl/builtins/buildifier_lint.pkl index ca4293a73..62ec9634b 100644 --- a/pkl/builtins/buildifier_lint.pkl +++ b/pkl/builtins/buildifier_lint.pkl @@ -13,16 +13,17 @@ import "./test/helpers.pkl" } } buildifier_lint = new Config.Step { - glob = List( - "**/BUILD", - "**/BUILD.bazel", - "WORKSPACE", - "WORKSPACE.bazel", - "MODULE.bazel", - "**/*.bzl", - "**/*.star", - "**/*.sky" - ) + glob = + List( + "**/BUILD", + "**/BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + "MODULE.bazel", + "**/*.bzl", + "**/*.star", + "**/*.sky", + ) check = "buildifier -mode=check -lint=warn {{ files }}" fix = "buildifier -lint=fix {{ files }}" tests {