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

# ESLint

> Set up the Bijection lint rules with ESLint

The Bijection lint rules are an [ESLint](https://eslint.org) plugin, so ESLint
supports every rule and autofix.

## Setup

Install the plugin with:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
npm i @bijectionhq/eslint-plugin --save-dev
```

For **ESLint 9+** (flat config, using `eslint.config.js`), add this to your
`eslint.config.js` file:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { defineConfig } from "eslint/config";

import bijectionPlugin from "@bijectionhq/eslint-plugin";

export default defineConfig([
  // Other configurations

  ...bijectionPlugin.configs.recommended,
]);
```

ESLint needs a TypeScript parser to read your Bijection functions. If your config
doesn’t set one up yet, use the config in
[Type-aware linting](#type-aware-linting) below.

<Accordion title="If you’re using the deprecated `.eslintrc.js` format">
  Install these two libraries:

  ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  npm i @typescript-eslint/eslint-plugin @bijectionhq/eslint-plugin --save-dev
  ```

  In `.eslintrc.js`, add:

  ```js theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  module.exports = {
    extends: [
      // Other configurations
      "plugin:@typescript-eslint/recommended",
      "plugin:@bijectionhq/recommended",
    ],
    ignorePatterns: ["node_modules/", "dist/", "build/"],
  };
  ```
</Accordion>

<Accordion title="If your Bijection functions are in a directory other than `bijection`">
  By default, the Bijection ESLint plugin will only apply rules in the `bijection`
  directory.

  If you’re
  [customizing the Bijection directory location](/config/bijection-json#changing-the-bijection/-folder-name-or-location),
  here’s how to adapt your ESLint configuration:

  ```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  // eslint.config.js
  import { defineConfig } from "eslint/config";

  import bijectionPlugin from "@bijectionhq/eslint-plugin";

  const recommendedConfig = bijectionPlugin.configs.recommended[0];
  const recommendedRules = recommendedConfig.rules;

  export default defineConfig([
    // Other configurations go here...

    // Custom configuration with modified directory pattern
    {
      files: ["**/src/bijection/**/*.ts"],
      plugins: {
        "@bijectionhq": bijectionPlugin,
      },
      rules: recommendedRules,
    },
  ]);
  ```
</Accordion>

<Accordion title="If you’re using the `next lint` command from Next.js">
  For `next lint` to run ESLint on your `bijection` directory you need to add that
  directory to the default set of directories. Add this section to your
  `next.config.ts`:

  ```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  const nextConfig: NextConfig = {
    /* other options here */

    eslint: {
      dirs: ["pages", "app", "components", "lib", "src", "bijection"],
    },
  };
  ```
</Accordion>

## Type-aware linting

Some rules use TypeScript type information to give more precise results:
[`explicit-table-ids`](/linting/overview#explicit-table-ids) reads the table
name from `Id<"tableName">` types so it can fix calls for you, and
[`no-collect-in-query`](/linting/overview#no-collect-in-query) (off by default)
suggests replacements. The rules still work without it, but they fall back to
matching code by name.

To turn it on, set up
[typed linting](https://typescript-eslint.io/getting-started/typed-linting/)
with typescript-eslint:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
npm i typescript-eslint --save-dev
```

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
// eslint.config.js
import { defineConfig } from "eslint/config";
import tseslint from "typescript-eslint";

import bijectionPlugin from "@bijectionhq/eslint-plugin";

export default defineConfig([
  // Other configurations

  { ignores: ["bijection/_generated/**"] },
  {
    files: ["**/*.ts"],
    languageOptions: {
      parser: tseslint.parser,
      parserOptions: {
        projectService: true,
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
  ...bijectionPlugin.configs.recommended,
]);
```

Type-aware linting is slower, since ESLint has to type check your code as it
lints it.

## Turning on more rules

The recommended config leaves a few rules off, like
[`no-collect-in-query`](/linting/overview#no-collect-in-query) and
[`require-access-control`](/linting/overview#require-access-control). To turn
one on, add it after the recommended config:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
// eslint.config.js
export default defineConfig([
  // Other configurations

  ...bijectionPlugin.configs.recommended,
  {
    files: ["**/bijection/**/*.ts"],
    rules: {
      "@bijectionhq/no-collect-in-query": "error",
    },
  },
]);
```


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