Skip to content

Commit

Permalink
feat(toolchains): enable exclude in typos test
Browse files Browse the repository at this point in the history
  • Loading branch information
mgred committed Jun 4, 2024
1 parent 1b266db commit 51c5d4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ load("//lib:typos.bzl", "typos_test")

exports_files(glob(["*"]))

typos_test(name = "typos")
typos_test(
name = "typos",
exclude = [
"**/assets.bzl",
],
)

topiary(
name = "topiary",
Expand Down
7 changes: 6 additions & 1 deletion lib/typos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
def _typos_impl(ctx):
output = ctx.actions.declare_file("%s.bash" % ctx.attr.name)
typos = ctx.toolchains["@bzlparty_tools//toolchains:typos_toolchain_type"].binary_info.binary
args = []
if len(ctx.attr.exclude) > 0:
args.extend(["--exclude=\"%s\"" % path for path in ctx.attr.exclude])
ctx.actions.write(
output = output,
content = """\
Expand All @@ -12,9 +15,10 @@ set -o pipefail -o errexit
typos_bin=$(realpath "{path}");
workspace=$(dirname "$(realpath "{workspace}")")
eval "$typos_bin $workspace"
eval "$typos_bin $workspace {args}"
""".format(
path = typos.path,
args = " ".join(args),
workspace = ctx.file.workspace.path,
),
is_executable = True,
Expand All @@ -32,6 +36,7 @@ _typos_test = rule(
_typos_impl,
attrs = {
"workspace": attr.label(allow_single_file = True, default = Label("//:MODULE.bazel")),
"exclude": attr.string_list(default = []),
},
toolchains = ["@bzlparty_tools//toolchains:typos_toolchain_type"],
test = True,
Expand Down

0 comments on commit 51c5d4f

Please sign in to comment.