-
-
Notifications
You must be signed in to change notification settings - Fork 79
feat(builtins): add buildifier format and lint built-ins
#896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 }}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the other similar comment are a good idea—will investigate and update. |
||
| 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) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The glob list should be expanded to include all relevant Bazel and Starlark files, matching the improvements suggested for the formatter builtin. |
||
| check = "buildifier -mode=check -lint=warn {{ files }}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| fix = "buildifier -lint=fix {{ files }}" | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
| 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"], | ||
| ) | ||
|
|
||
| """ | ||
|
Comment on lines
+31
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case expects Consider using a fixable lint issue such as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's actually going on here is that:
Or, tl;dr: this test example looks like a (nonexistant) generic automatic-import-finder thing, but is just a narrow-purpose rule targeting a list of known rules. |
||
| ["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) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/usr/bin/env -S mise tool-stub | ||
|
|
||
| version = "8.5.1" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect this is an LLM hallucination because I can literally verify that there's an 8.5.1 version of buildifier available here. |
||
| tool = "buildifier" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The glob list is missing some common Bazel/Starlark file patterns and some entries are restricted to the root directory. It is better to include
**/WORKSPACE,**/MODULE.bazel,**/REPO.bazel, and**/*.BUILDto ensure all relevant files are covered regardless of their location in the repository.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the other similar comment are a good idea—will expand the list.