> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# @aspect_rules_lint//lint:eslint.bzl

> Bazel rules_lint ESLint integration: lint_eslint_aspect for running ESLint as a Bazel aspect over JavaScript and TypeScript rules_js targets.

<Callout icon="book">
  Documentation for [@aspect\_rules\_lint@v2.1.0](https://registry.bazel.build/modules/aspect_rules_lint/2.1.0) -- <Icon icon="github" iconType="brands" /> [View source](https://github.com/aspect-build/rules_lint/blob/v2.1.0/lint/eslint.bzl)
</Callout>

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

```python theme={null}
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`:

```python theme={null}
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](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](https://github.com/bazelbuild/examples/blob/b498bb106b2028b531ceffbd10cc89530814a177/frontend/react/src/BUILD.bazel#L86-L92)

## 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](https://eslint.org/docs/latest/use/command-line-interface)

### Parameters

<ParamField body="ctx" type="unknown" required>
  an action context OR aspect context
</ParamField>

<ParamField body="executable" type="unknown" required>
  struct with an eslint field
</ParamField>

<ParamField body="srcs" type="unknown" required>
  list of file objects to lint
</ParamField>

<ParamField body="stdout" type="unknown" required>
  output file containing the stdout or --output-file of eslint
</ParamField>

<ParamField body="exit_code" type="unknown" default={`None`}>
  output file containing the exit code of eslint.
  If None, then fail the build when eslint exits non-zero.
</ParamField>

<ParamField body="format" type="unknown" default={`stylish`}>
  value for eslint `--format` CLI flag
</ParamField>

<ParamField body="env" type="unknown" default={`{}`}>
  environment variables for eslint
</ParamField>

<ParamField body="patch" type="unknown" default={`None`}>
  output file for patch (optional). If provided, uses run\_patcher instead of run/run\_shell.
</ParamField>

## Function: `lint_eslint_aspect`

A factory function to create a linter aspect.

### Parameters

<ParamField body="binary" type="unknown" required>
  the eslint binary, typically a rule like

  ```
  load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
  eslint_bin.eslint_binary(name = "eslint")
  ```
</ParamField>

<ParamField body="configs" type="unknown" required>
  label(s) of the eslint config file(s)
</ParamField>

<ParamField body="rule_kinds" type="unknown" default={`["js_library", "ts_project", "ts_project_rule"]`}>
  which [kinds](https://bazel.build/query/language#kind) of rules should be visited by the aspect
</ParamField>
