-
-
Notifications
You must be signed in to change notification settings - Fork 66
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 all 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,54 @@ | ||
| 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) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| 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 }}" | ||
|
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.
Adding
check_diffallowshkto usegit applyfor applying formatting changes. This is generally more efficient and safer than running the fullfixcommand when only formatting changes are needed.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 investigate and update.