Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.aspect.build/llms.txt

Use this file to discover all available pages before exploring further.

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 = Label("//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 = [
        Label("//:eslintrc"),
        ...
    ],
)

With ts_project prior to version 3.2.0

Prior to [commit 5e25e91]https://github.com/aspect-build/rules_ts/commit/5e25e91420947e3a81938d8eb076803e5cf51fe2) the rule produced by the ts_project macro and a custom transpiler expanded the macro to multiple targets, including changing the default target to js_library. 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

Function: 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

Parameters

ctx
unknown
required
an action context OR aspect context
executable
unknown
required
struct with an eslint field
srcs
unknown
required
list of file objects to lint
stdout
unknown
required
output file containing the stdout or —output-file of eslint
exit_code
unknown
default:"None"
output file containing the exit code of eslint. If None, then fail the build when eslint exits non-zero.
format
unknown
default:"stylish"
value for eslint --format CLI flag
env
unknown
default:"{}"
environment variables for eslint
patch
unknown
default:"None"
output file for patch (optional). If provided, uses run_patcher instead of run/run_shell.

Function: lint_eslint_aspect

A factory function to create a linter aspect.

Parameters

binary
unknown
required
the eslint binary, typically a rule like
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
eslint_bin.eslint_binary(name = "eslint")
configs
unknown
required
label(s) of the eslint config file(s)
rule_kinds
unknown
which kinds of rules should be visited by the aspect