> ## Documentation Index
> Fetch the complete documentation index at: https://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.

Documentation for [@aspect\_rules\_lint@v2.1.0](https://registry.bazel.build/modules/aspect_rules_lint/2.1.0) --  [View source](https://github.com/aspect-build/rules_lint/blob/v2.1.0/lint/eslint.bzl)

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

**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` (default: \["js\_library", "ts\_project", "ts\_project\_rule"])

which [kinds](https://bazel.build/query/language#kind) of rules should be visited by the aspect


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.