I am using Bazel rules in NodeJS in my application. The aim is to simply lint a set of files and fail the build if linting fails. What I'm currently experiencing is that the build is successful despite lint errors.
Here's a part of my BUILD
file:
load("@npm//htmlhint:index.bzl", "htmlhint")
filegroup(
name = "htmldata",
srcs = glob(["**/*.html"]),
)
htmlhint(
name = "compile",
data = [
"htmlhint.conf",
"//:htmldata"
],
args = [
"--config",
"htmlhint.conf",
"$(locations //:htmldata)"
]
)
I first load the hinting library, then I define a filegroup for all the HTML files that I want to lint. Afterward, I use the rule with its data and arguments.
To run the build, I use the default option via npm script: bazel build //...
Your build file is working as expected. Unfortunately it doesn't do what you want, because when you load the macro from
@npm//htmlhint:index.bzl
it sets up the nodejs binary which is a runnable target, which means that it will only create runfiles + executable when building. In this case, the build will not run the library.There are several options to do what you want:
htmlhint_test
macro to create a test target.However, I suggest using the first approach, because if
htmlhint
is a linting tool, it won't produce any meaningful outputs and is best to keep it as part of the test suite.Here's what you need to do to set up the
compile
target as a test targetThen you can check it with
bazel test //...
.If you want to see the output just run your
compile
target withbazel run //path/to:compile