Now you do not need to depend on the system shellcheck version in your bazel-managed (mono)repos.
Choose your release from the GH Releases and follow setup instructions there.
Then shellcheck can be accessed by running:
bazel run @rules_shellcheck//:shellcheck -- <parameters>And you can define a lint target:
load("@rules_shellcheck//:def.bzl", "shellcheck", "shellcheck_test")
shellcheck_test(
name = "shellcheck_test",
data = glob(["*.sh"]),
tags = ["lint"],
format = "gcc",
severity = "warning",
)shellcheck_aspect runs shellcheck against any target that provides ShInfo or ShBinaryInfo (e.g. sh_binary and sh_library from rules_shell) as part of a normal bazel build. Enable it by adding the following to your .bazelrc:
build --aspects=@rules_shellcheck//shellcheck:shellcheck_aspect.bzl%shellcheck_aspect
build --output_groups=+shellcheck_checks
With those flags in place, any build that includes shell targets will also run shellcheck on their sources; the lint results are exposed via the shellcheck_checks output group.
The aspect reads two string_flag build settings. Override them on the command line or via .bazelrc:
build --@rules_shellcheck//shellcheck/settings:format=gcc
build --@rules_shellcheck//shellcheck/settings:severity=warning
//shellcheck/settings:formatacceptscheckstyle,diff,gcc,json,json1,quiet, ortty(default:shellcheck's built-in default).//shellcheck/settings:severityacceptserror,warning,info, orstyle(default:shellcheck's built-in default).
Because these are standard string_flags, you can also flip them per-command with --config groups or with transitions if you want a specific target to lint under different settings.
Add any of the following tags to a target to opt it out of shellcheck_aspect:
no_shellchecknoshellcheckno_lintnolint
Targets under external repositories (workspace_root starting with external) are always skipped.
Note: this is a simple project that allows me to learn about various bazel concepts. Feel free to create PRs contributing to the project or consider using rules_lint.