Skip to content

Latest commit

 

History

History
135 lines (91 loc) · 5.34 KB

eslint.md

File metadata and controls

135 lines (91 loc) · 5.34 KB

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

eslint_action

load("@aspect_rules_lint//lint:eslint.bzl", "eslint_action")

eslint_action(ctx, executable, srcs, stdout, exit_code, format, env)

Create a Bazel Action that spawns an eslint process.

Adapter for wrapping Bazel around https://eslint.org/docs/latest/use/command-line-interface

PARAMETERS

Name Description Default Value
ctx an action context OR aspect context none
executable struct with an eslint field none
srcs list of file objects to lint none
stdout output file containing the stdout or --output-file of eslint none
exit_code output file containing the exit code of eslint. If None, then fail the build when eslint exits non-zero. None
format value for eslint --format CLI flag "stylish"
env environment variables for eslint {}

eslint_fix

load("@aspect_rules_lint//lint:eslint.bzl", "eslint_fix")

eslint_fix(ctx, executable, srcs, patch, stdout, exit_code, format, env)

Create a Bazel Action that spawns eslint with --fix.

PARAMETERS

Name Description Default Value
ctx an action context OR aspect context none
executable struct with an eslint field none
srcs list of file objects to lint none
patch output file containing the applied fixes that can be applied with the patch(1) command. none
stdout output file containing the stdout or --output-file of eslint none
exit_code output file containing the exit code of eslint none
format value for eslint --format CLI flag "stylish"
env environment variaables for eslint {}

lint_eslint_aspect

load("@aspect_rules_lint//lint:eslint.bzl", "lint_eslint_aspect")

lint_eslint_aspect(binary, configs, rule_kinds)

A factory function to create a linter aspect.

PARAMETERS

Name Description Default Value
binary the eslint binary, typically a rule like

load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
eslint_bin.eslint_binary(name = "eslint")
none
configs label(s) of the eslint config file(s) none
rule_kinds which kinds of rules should be visited by the aspect ["js_library", "ts_project", "ts_project_rule"]