---
title: "ESLint Plugin"
description: "The `eslint-plugin-drizzle` package is a specialized linting utility designed to enforce safety patterns within Drizzle ORM query construction. Its primary purpose is to prevent common, high-risk d..."
last_updated: "2026-07-02T09:35:18.894792+00:00"
canonical_url: "https://www.doc0.app/docs/e1b68fed-3c4e-4c95-b2ba-ebf050f78025/technical/utilities-testing/eslint-plugin"
---

<details>
<summary>Relevant source files</summary>

The following files were used as context for generating this wiki page:

- [drizzle-orm/src/gel-core/dialect.ts](https://github.com/blade47/drizzle-orm/blob/main/drizzle-orm/src/gel-core/dialect.ts)
- [drizzle-orm/src/pg-core/dialect.ts](https://github.com/blade47/drizzle-orm/blob/main/drizzle-orm/src/pg-core/dialect.ts)
- [.eslintrc.yaml](https://github.com/blade47/drizzle-orm/blob/main/.eslintrc.yaml)
- [drizzle-orm/src/sqlite-core/query-builders/delete.ts](https://github.com/blade47/drizzle-orm/blob/main/drizzle-orm/src/sqlite-core/query-builders/delete.ts)
- [eslint-plugin-drizzle/src/configs/all.ts](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/configs/all.ts)
- [drizzle-orm/type-tests/mysql/select.ts](https://github.com/blade47/drizzle-orm/blob/main/drizzle-orm/type-tests/mysql/select.ts)
- [eslint-plugin-drizzle/src/configs/recommended.ts](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/configs/recommended.ts)
- [eslint-plugin-drizzle/src/enforce-update-with-where.ts](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/enforce-update-with-where.ts)
- [eslint-plugin-drizzle/src/enforce-delete-with-where.ts](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/enforce-delete-with-where.ts)
- [drizzle-orm/src/pg-core/query-builders/update.ts](https://github.com/blade47/drizzle-orm/blob/main/drizzle-orm/src/pg-core/query-builders/update.ts)
- [eslint-plugin-drizzle/src/index.ts](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/index.ts)
- [drizzle-orm/src/singlestore-core/query-builders/delete.ts](https://github.com/blade47/drizzle-orm/blob/main/drizzle-orm/src/singlestore-core/query-builders/delete.ts)
- [drizzle-orm/src/mysql-core/query-builders/delete.ts](https://github.com/blade47/drizzle-orm/blob/main/drizzle-orm/src/mysql-core/query-builders/delete.ts)
</details>

The `eslint-plugin-drizzle` package is a specialized linting utility designed to enforce safety patterns within Drizzle ORM query construction. Its primary purpose is to prevent common, high-risk development mistakes, specifically those involving destructive database operations that lack necessary filtering criteria.

At its architectural core, the plugin functions as a structural validator of the Drizzle fluent API surface. By inspecting the Abstract Syntax Tree (AST) of Drizzle queries, it identifies instances where `delete()` or `update()` methods are invoked without a subsequent `.where()` clause. Executing these operations on entire tables is a frequent source of data loss or corruption, and this plugin serves as a compile-time (or development-time) guard to catch these patterns before they reach a production environment.

The plugin provides curated configuration presets that teams can adopt to ensure a baseline level of query safety. By integrating these rules into standard ESLint workflows, it ensures that developers follow the prescribed, safer patterns—such as chaining the `.where()` clause to every destructive statement—without requiring manual review for every query implementation.

## Core Rules
The plugin centers on two exported rule modules: the default export from `enforce-delete-with-where.ts` and the default export from `enforce-update-with-where.ts`. These rules operate by monitoring the structure of `MemberExpression` nodes within the AST.

For deletions, the rule verifies that the `.delete()` method call is associated with a structure that includes a `.where()` clause. If the call chain is incomplete, it reports an error indicating that all rows in a table are at risk of deletion. The update rule follows a similar logic, specifically focusing on the `.set()` method following an `.update()` call, ensuring that the final chain logically includes a `.where()` operation.

Sources: [eslint-plugin-drizzle/src/enforce-delete-with-where.ts:11-53](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/enforce-delete-with-where.ts#L11-L53), [eslint-plugin-drizzle/src/enforce-update-with-where.ts:10-58](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/enforce-update-with-where.ts#L10-L58)

## Configuration Presets
The plugin exposes configurations through an `index.ts` file that aggregates rules and settings, allowing for modular adoption:

| Config | Scope |
| :--- | :--- |
| `all` | Includes the provided rules as errors. |
| `recommended` | Equivalent to `all`, providing the baseline safety rules. |

Sources: [eslint-plugin-drizzle/src/index.ts:9-14](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/index.ts#L9-L14), [eslint-plugin-drizzle/src/configs/all.ts:1-14](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/configs/all.ts#L1-L14), [eslint-plugin-drizzle/src/configs/recommended.ts:1-14](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/configs/recommended.ts#L1-L14)

## AST Monitoring Mechanism
The plugin utilizes the `@typescript-eslint/utils` RuleCreator to hook into the `MemberExpression` visitor. The implementation tracks the sequence of property names across the AST traversal to validate the presence of the required filtering methods.

```mermaid
flowchart TD
    A["Visit MemberExpression"] --> B{Identify .delete or .set}
    B --> C{"Check for .where() method presence in chain"}
    C -->|Missing| D["Report error"]
    C -->|Present| E["Valid (skip)"]
```
Sources: [eslint-plugin-drizzle/src/enforce-delete-with-where.ts:36-50](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/enforce-delete-with-where.ts#L36-L50)

> [!NOTE]
> The rules rely on internal state tracking during the AST traversal process to determine if a `.where()` method has been successfully called within the current query chain.

## Usage Example
To integrate the plugin, ensure it is configured in your ESLint settings and use the recommended plugin exports.

```typescript
// .eslintrc.yaml
plugins:
  - drizzle
rules:
  'drizzle/enforce-delete-with-where': 'error'
  'drizzle/enforce-update-with-where': 'error'

// Your code usage
// This will trigger an error:
db.delete(users);

// This is correct:
db.delete(users).where(eq(users.id, 1));
```
Sources: [eslint-plugin-drizzle/src/index.ts:9-12](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/index.ts#L9-L12), [drizzle-orm/src/sqlite-core/query-builders/delete.ts:160-191](https://github.com/blade47/drizzle-orm/blob/main/drizzle-orm/src/sqlite-core/query-builders/delete.ts#L160-L191)

## Design Trade-offs
The design prioritizes preventing data-destructive API calls through static analysis.

| Design Choice | Benefit | Cost |
| :--- | :--- | :--- |
| AST-based inspection | Catches errors before execution. | Requires complex AST traversal logic. |
| Fluent API assumption | Matches Drizzle's primary interaction style. | Does not cover non-fluent/variable-bound builds. |

Sources: [eslint-plugin-drizzle/src/enforce-delete-with-where.ts:9-53](https://github.com/blade47/drizzle-orm/blob/main/eslint-plugin-drizzle/src/enforce-delete-with-where.ts#L9-L53)

> [!IMPORTANT]
> The plugin identifies the Drizzle object based on the naming configuration provided in `options`. If you use custom object names for your Drizzle database instance, ensure they are registered in the rule options to trigger accurate detection.

## Related

- [Data Mutations](https://www.doc0.app/docs/e1b68fed-3c4e-4c95-b2ba-ebf050f78025/technical/query-engine/data-mutations)


## Sitemap

See the full [sitemap](https://www.doc0.app/docs/e1b68fed-3c4e-4c95-b2ba-ebf050f78025/llms.txt) for all pages in this wiki.
