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", "lint_eslint_aspect")
eslint = lint_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 file containing the stdout or --output-file of eslint
stdout = None,
)
ctx
Required.
an action context OR aspect context
executable
Required.
struct with an eslint field
srcs
Required.
list of file objects to lint
stdout
Required.
output file containing the stdout or --output-file of eslint
exit_code
Optional. Default: None
output file containing the exit code of eslint. If None, then fail the build when eslint exits non-zero.
format
Optional. Default: "stylish"
value for eslint --format
CLI flag
env
Optional. Default: {}
environment variables for eslint
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,
# output file containing the stdout or --output-file of eslint
stdout = None,
# output file containing the exit code of eslint
exit_code = 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.
stdout
Required.
output file containing the stdout or --output-file of eslint
exit_code
Required.
output file containing the exit code of eslint
format
Optional. Default: "stylish"
value for eslint --format
CLI flag
env
Optional. Default: {}
environment variaables for eslint
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)
rule_kinds
Optional. Default: ["js_library", "ts_project", "ts_project_rule"]
which kinds of rules should be visited by the aspect