diff --git a/BUILD.bazel b/BUILD.bazel index 60e02eef361690305ab6ffad371086717455e17f..5217c94003e51ab1c1690749b2434c3496aedf1f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,6 +1,6 @@ +load("@pre-commit//pre-commit/hooks:defs.bzl", "pre_commit_hooks") load("@rules_license//rules:license.bzl", "license") load("@rules_license//rules:package_info.bzl", "package_info") -load("@pre-commit//pre-commit/hooks:defs.bzl", "pre_commit_hooks") licenses(["notice"]) @@ -22,6 +22,7 @@ package_info( pre_commit_hooks( name = "pre-commit-hooks", srcs = [ + "//buildifier", "//ruff", ], visibility = ["//visibility:public"], diff --git a/buildifier/BUILD.bazel b/buildifier/BUILD.bazel new file mode 100644 index 0000000000000000000000000000000000000000..be3b1a5208aefe2697d9011e0d45e36a15fafaec --- /dev/null +++ b/buildifier/BUILD.bazel @@ -0,0 +1,35 @@ +load("@pre-commit//pre-commit/hook:defs.bzl", "pre_commit_hook") +load("@pre-commit//pre-commit/hooks:defs.bzl", "pre_commit_hooks") + +pre_commit_hook( + name = "format", + src = "@buildifier_prebuilt//:buildifier", + description = "Will load a `.buildifier.json` at the root of the workspace for extra configuration.", + stages = ["@pre-commit//pre-commit/stage:pre-commit"], + summary = "Format Bazel files", + types_or = ["@pre-commit//pre-commit/tag:bazel"], + visibility = ["//visibility:public"], +) + +pre_commit_hook( + name = "lint", + src = "@buildifier_prebuilt//:buildifier", + args = [ + "-lint", + "fix", + ], + description = "Will load a `.buildifier.json` at the root of the workspace for extra configuration.", + stages = ["@pre-commit//pre-commit/stage:pre-commit"], + summary = "Lint Bazel files", + types_or = ["@pre-commit//pre-commit/tag:bazel"], + visibility = ["//visibility:public"], +) + +pre_commit_hooks( + name = "buildifier", + srcs = [ + ":format", + ":lint", + ], + visibility = ["//visibility:public"], +) diff --git a/hooks/.pre-commit-config.yaml b/hooks/.pre-commit-config.yaml index 4cb7e9a0c7b64685a643cfae82e25bb23fdb7a3e..733365fe0189d5c604cf2e8b0be3553f33a3e75f 100644 --- a/hooks/.pre-commit-config.yaml +++ b/hooks/.pre-commit-config.yaml @@ -5,6 +5,28 @@ default_install_hook_types: repos: - repo: local hooks: + - id: //buildifier:format + name: Format Bazel files + description: Will load a `.buildifier.json` at the root of the workspace for extra + configuration. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //buildifier:format + types_or: + - bazel + - id: //buildifier:lint + name: Lint Bazel files + description: Will load a `.buildifier.json` at the root of the workspace for extra + configuration. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //buildifier:lint + types_or: + - bazel - id: //ruff name: Check Python files with `ruff` description: Performs checks with `ruff` against Python files. Will read a `ruff.toml`