eslint
API for calling declaring an ESLint lint aspect.
Typical usage:
First, install eslint using your typical npm package.json and rules_js rules.
Next, declare a binary target for it, typically in tools/lint/BUILD.bazel
:
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
eslint_bin.eslint_binary(name = "eslint")
Finally, create the linter aspect, typically in tools/lint/linters.bzl
:
load("@aspect_rules_lint//lint:eslint.bzl", "eslint_aspect")
eslint = eslint_aspect(
binary = "@@//tools/lint:eslint",
# We trust that eslint will locate the correct configuration file for a given source file.
# See https://eslint.org/docs/latest/use/configure/configuration-files#cascading-and-hierarchy
configs = [
"@@//:eslintrc",
...
],
)
With ts_project
Note, when used with ts_project
and a custom transpiler
,
the macro expands to several targets,
see https://github.com/aspect-build/rules_ts/blob/main/docs/transpiler.md#macro-expansion.
Since you want to lint the original TypeScript source files, the ts_project
rule produced
by the macro is the one you want to lint, so when used with an eslint_test
you should use
the [name]_typings
label:
ts_project(
name = "my_ts",
transpiler = swc,
...
)
eslint_test(
name = "lint_my_ts",
srcs = [":my_ts_typings"],
)
See the react example
Macros and Functions
eslint_action
Create a Bazel Action that spawns an eslint process.
Adapter for wrapping Bazel around https://eslint.org/docs/latest/use/command-line-interface
Example usage (generated):
load("@aspect_rules_lint//lint:eslint.bzl", "eslint_action")
eslint_action(
# an action context OR aspect context
ctx = None,
# struct with an eslint field
executable = None,
# list of file objects to lint
srcs = [],
# output: the stdout of eslint containing any violations found
report = None,
)
ctx
Required.
an action context OR aspect context
executable
Required.
struct with an eslint field
srcs
Required.
list of file objects to lint
report
Required.
output: the stdout of eslint containing any violations found
use_exit_code
Optional. Default: False
whether an eslint process exiting non-zero will be a build failure
eslint_fix
Create a Bazel Action that spawns eslint with --fix.
Example usage (generated):
load("@aspect_rules_lint//lint:eslint.bzl", "eslint_fix")
eslint_fix(
# an action context OR aspect context
ctx = None,
# struct with an eslint field
executable = None,
# list of file objects to lint
srcs = [],
# output file containing the applied fixes that can be applied with the patch(1) command.
patch = None,
)
ctx
Required.
an action context OR aspect context
executable
Required.
struct with an eslint field
srcs
Required.
list of file objects to lint
patch
Required.
output file containing the applied fixes that can be applied with the patch(1) command.
lint_eslint_aspect
A factory function to create a linter aspect.
Example usage (generated):
load("@aspect_rules_lint//lint:eslint.bzl", "lint_eslint_aspect")
lint_eslint_aspect(
# the eslint binary, typically a rule like
binary = None,
# label(s) of the eslint config file(s)
configs = None,
)
binary
Required.
the eslint binary, typically a rule like
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
eslint_bin.eslint_binary(name = "eslint")
configs
Required.
label(s) of the eslint config file(s)