diff --git a/BUILD.bazel b/BUILD.bazel index 85a07407bad650e384378b2db8cfe0c48c302705..52311e24fa6c8c148dfdc1dfea35489b3ac36979 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -24,6 +24,7 @@ pre_commit_hooks( srcs = [ "//buildifier", "//ruff", + "//shellcheck", "//shfmt", ], visibility = ["//visibility:public"], diff --git a/MODULE.bazel b/MODULE.bazel index 2c47e6a96ab81bff563a3b735d1426f5bea740fe..e8c8cf1c2d1e886287ce4c8bdadef20ee798ecef 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,6 +7,7 @@ bazel_dep(name = "pre-commit", version = "1.0.1") bazel_dep(name = "buildifier_prebuilt", version = "8.0.0") bazel_dep(name = "download_utils", version = "1.0.1") bazel_dep(name = "toolchain_utils", version = "1.2.0") +bazel_dep(name = "rules_shellcheck", version = "0.3.3") bazel_dep(name = "rules_python", version = "1.0.0", dev_dependency = True) bazel_dep(name = "hermetic_cc_toolchain", version = "3.1.0", dev_dependency = True) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 79a3c1b13431120a728fee41e43d6963527546d0..5bf5e322b05a291de08ed5a7724a9ac3a24ab4c2 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -137,6 +137,8 @@ "https://bcr.bazel.build/modules/rules_python/1.0.0/source.json": "b0162a65c6312e45e7912e39abd1a7f8856c2c7e41ecc9b6dc688a6f6400a917", "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", "https://bcr.bazel.build/modules/rules_shell/0.2.0/source.json": "7f27af3c28037d9701487c4744b5448d26537cc66cdef0d8df7ae85411f8de95", + "https://bcr.bazel.build/modules/rules_shellcheck/0.3.3/MODULE.bazel": "c1bf29938855c84c5f7ebaf7fa9b41bae42df25bda10c10eda9db36e1611d819", + "https://bcr.bazel.build/modules/rules_shellcheck/0.3.3/source.json": "eeb41efe82a0c27ddbac79cb68c98be1d39241481046485783cfa7d7be385b91", "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", "https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c", "https://bcr.bazel.build/modules/stardoc/0.5.6/MODULE.bazel": "c43dabc564990eeab55e25ed61c07a1aadafe9ece96a4efabb3f8bf9063b71ef", @@ -4180,6 +4182,95 @@ ] ] } + }, + "@@rules_shellcheck+//internal:extensions.bzl%shellcheck_dependencies": { + "general": { + "bzlTransitiveDigest": "l1LMECmx4plQ9lFhLWL56vMXzWyiMP0X7m8FSnSbprs=", + "usagesDigest": "dB1tqxp4QomnAlt2Na7AnDC2qZdvV3Sjc3OCSEyzwdQ=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "shellcheck_darwin_aarch64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "a75b912015aaa5b2a48698b63f3619783d90abda4d32a31362209315e6c1cdf6", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.darwin.aarch64.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.darwin.aarch64.tar.gz" + ] + } + }, + "shellcheck_darwin_x86_64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "d1244da2aa5d0c2874f3a4a680c6ac79a488ff6dbf9928e12dc80ff3fdc294db", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.darwin.x86_64.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.darwin.x86_64.tar.gz" + ] + } + }, + "shellcheck_linux_aarch64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "b5633bd195cfe61a310bd8dcff2514855afefea908942a0fd4d01fa6451cb4e6", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.aarch64.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.aarch64.tar.gz" + ] + } + }, + "shellcheck_linux_armv6hf": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "4791d36d84a626c4366746d14ad68daf2c07f502da09319c45fa6c5c0a847aa9", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.armv6hf.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.armv6hf.tar.gz" + ] + } + }, + "shellcheck_linux_x86_64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "0ab5711861e6fcafad5aa21587ee75bbd2b16505d56f41c9ba1191a83d314074", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.x86_64.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.x86_64.tar.gz" + ] + } + }, + "shellcheck_windows_x86_64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "a0f021057b6d6a69a22f6b0db0187bcaca3f5195385e92a7555ad63a6e39ee15", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.windows.x86_64.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.windows.x86_64.tar.gz" + ] + } + } + }, + "recordedRepoMappingEntries": [ + [ + "rules_shellcheck+", + "bazel_tools", + "bazel_tools" + ], + [ + "rules_shellcheck+", + "rules_shellcheck", + "rules_shellcheck+" + ] + ] + } } } } diff --git a/e2e/MODULE.bazel.lock b/e2e/MODULE.bazel.lock index 7166e79c4d606b4cf0ce742dd237f6ccdd2067c1..2e5f7eee87228b1bec4d9601dbe6f93f487d0d0d 100644 --- a/e2e/MODULE.bazel.lock +++ b/e2e/MODULE.bazel.lock @@ -137,6 +137,8 @@ "https://bcr.bazel.build/modules/rules_python/1.0.0/source.json": "b0162a65c6312e45e7912e39abd1a7f8856c2c7e41ecc9b6dc688a6f6400a917", "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", "https://bcr.bazel.build/modules/rules_shell/0.2.0/source.json": "7f27af3c28037d9701487c4744b5448d26537cc66cdef0d8df7ae85411f8de95", + "https://bcr.bazel.build/modules/rules_shellcheck/0.3.3/MODULE.bazel": "c1bf29938855c84c5f7ebaf7fa9b41bae42df25bda10c10eda9db36e1611d819", + "https://bcr.bazel.build/modules/rules_shellcheck/0.3.3/source.json": "eeb41efe82a0c27ddbac79cb68c98be1d39241481046485783cfa7d7be385b91", "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", "https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c", "https://bcr.bazel.build/modules/stardoc/0.5.6/MODULE.bazel": "c43dabc564990eeab55e25ed61c07a1aadafe9ece96a4efabb3f8bf9063b71ef", @@ -446,6 +448,95 @@ ] ] } + }, + "@@rules_shellcheck+//internal:extensions.bzl%shellcheck_dependencies": { + "general": { + "bzlTransitiveDigest": "l1LMECmx4plQ9lFhLWL56vMXzWyiMP0X7m8FSnSbprs=", + "usagesDigest": "dB1tqxp4QomnAlt2Na7AnDC2qZdvV3Sjc3OCSEyzwdQ=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "shellcheck_darwin_aarch64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "a75b912015aaa5b2a48698b63f3619783d90abda4d32a31362209315e6c1cdf6", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.darwin.aarch64.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.darwin.aarch64.tar.gz" + ] + } + }, + "shellcheck_darwin_x86_64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "d1244da2aa5d0c2874f3a4a680c6ac79a488ff6dbf9928e12dc80ff3fdc294db", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.darwin.x86_64.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.darwin.x86_64.tar.gz" + ] + } + }, + "shellcheck_linux_aarch64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "b5633bd195cfe61a310bd8dcff2514855afefea908942a0fd4d01fa6451cb4e6", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.aarch64.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.aarch64.tar.gz" + ] + } + }, + "shellcheck_linux_armv6hf": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "4791d36d84a626c4366746d14ad68daf2c07f502da09319c45fa6c5c0a847aa9", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.armv6hf.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.armv6hf.tar.gz" + ] + } + }, + "shellcheck_linux_x86_64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "0ab5711861e6fcafad5aa21587ee75bbd2b16505d56f41c9ba1191a83d314074", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.x86_64.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.linux.x86_64.tar.gz" + ] + } + }, + "shellcheck_windows_x86_64": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "build_file_content": "exports_files([\"shellcheck\"])\n", + "sha256": "a0f021057b6d6a69a22f6b0db0187bcaca3f5195385e92a7555ad63a6e39ee15", + "urls": [ + "https://mirror.bazel.build/github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.windows.x86_64.tar.gz", + "https://github.com/vscode-shellcheck/shellcheck-binaries/releases/download/v0.9.0/shellcheck-v0.9.0.windows.x86_64.tar.gz" + ] + } + } + }, + "recordedRepoMappingEntries": [ + [ + "rules_shellcheck+", + "bazel_tools", + "bazel_tools" + ], + [ + "rules_shellcheck+", + "rules_shellcheck", + "rules_shellcheck+" + ] + ] + } } } } diff --git a/e2e/shellcheck/BUILD.bazel b/e2e/shellcheck/BUILD.bazel new file mode 100644 index 0000000000000000000000000000000000000000..992754b0414adbae771f1c56e0942d5c44f3c030 --- /dev/null +++ b/e2e/shellcheck/BUILD.bazel @@ -0,0 +1,9 @@ +load("@bazel_skylib//rules:build_test.bzl", "build_test") + +build_test( + name = "shellcheck", + size = "small", + targets = [ + "@pre-commit-hooks//shellcheck", + ], +) diff --git a/hooks/.pre-commit-config.yaml b/hooks/.pre-commit-config.yaml index 3d3f8818c9a283196298d1e239eec326314cde1e..9e314e276cffd13fb438f856e63549219fefc3e4 100644 --- a/hooks/.pre-commit-config.yaml +++ b/hooks/.pre-commit-config.yaml @@ -49,6 +49,16 @@ repos: entry: bazel run --config=pre-commit -- //ruff:format types: - python + - id: //shellcheck + name: Lint Shell files with `shellcheck` + description: Performs linting with `shellcheck` against Shell files. + language: system + require_serial: true + stages: + - pre-commit + entry: bazel run --config=pre-commit -- //shellcheck + types: + - shell - id: //shfmt name: Format Shell files with `shfmt` description: Performs formatting with `shfmt` against Shell files. diff --git a/shellcheck/BUILD.bazel b/shellcheck/BUILD.bazel new file mode 100644 index 0000000000000000000000000000000000000000..a46f12117a3347d3487285852b5a4e2d676e1e2f --- /dev/null +++ b/shellcheck/BUILD.bazel @@ -0,0 +1,21 @@ +load("@pre-commit//pre-commit/hook:defs.bzl", "pre_commit_hook") +load("@toolchain_utils//toolchain/symlink/target:defs.bzl", "toolchain_symlink_target") + +toolchain_symlink_target( + name = "cli", + target = "@rules_shellcheck//:shellcheck", +) + +pre_commit_hook( + name = "shellcheck", + src = ":cli", + args = [ + "-o", + "all", + ], + description = "Performs linting with `shellcheck` against Shell files.", + stages = ["@pre-commit//pre-commit/stage:pre-commit"], + summary = "Lint Shell files with `shellcheck`", + types = ["@pre-commit//pre-commit/tag:shell"], + visibility = ["//visibility:public"], +)