drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: eslint-plugin-drizzle incorrect warning

Open jzohdi opened this issue 1 year ago • 3 comments

What version of drizzle-orm are you using?

0.29.4

What version of drizzle-kit are you using?

0.20.14

Describe the Bug

Hi Drizzle team, I am working on a project based on nextjs using the t3 stack and I am getting eslint(drizzle/enforce-delete-with-where) message while using a simple javascript Map (typescript).

I also tried to restart esllint/vscode but the warning persists. Let me know if there's anything other useful information I can provide.

image

.eslintrc.cjs

/** @type {import("eslint").Linter.Config} */
const config = {
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": true
  },
  "plugins": [
    "@typescript-eslint",
    "drizzle"
  ],
  "extends": [
    "next/core-web-vitals",
    "plugin:@typescript-eslint/recommended-type-checked",
    "plugin:@typescript-eslint/stylistic-type-checked"
  ],
  "rules": {
    "@typescript-eslint/array-type": "off",
    "@typescript-eslint/consistent-type-definitions": "off",
    "@typescript-eslint/consistent-type-imports": [
      "warn",
      {
        "prefer": "type-imports",
        "fixStyle": "inline-type-imports"
      }
    ],
    "@typescript-eslint/no-unused-vars": [
      "warn",
      {
        "argsIgnorePattern": "^_"
      }
    ],
    "@typescript-eslint/require-await": "off",
    "@typescript-eslint/no-misused-promises": [
      "error",
      {
        "checksVoidReturn": {
          "attributes": false
        }
      }
    ],
    "drizzle/enforce-delete-with-where": "error",
    "drizzle/enforce-update-with-where": "error"
  }
}
module.exports = config;

Expected behavior

Do not show warning when not related to drizzle orm.

Environment & setup

Windows 11

package.json

{
 "dependencies": {
    "@auth/drizzle-adapter": "^0.7.0",
    "@ducanh2912/next-pwa": "^10.2.5",
    "@radix-ui/react-avatar": "^1.0.4",
    "@radix-ui/react-scroll-area": "^1.0.5",
    "@radix-ui/react-slot": "^1.0.2",
    "@t3-oss/env-nextjs": "^0.9.2",
    "@tanstack/react-query": "^5.25.0",
    "@trpc/client": "next",
    "@trpc/next": "next",
    "@trpc/react-query": "next",
    "@trpc/server": "next",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.0",
    "drizzle-orm": "^0.29.4",
    "lucide-react": "^0.364.0",
    "next": "^14.1.3",
    "next-auth": "^4.24.6",
    "postgres": "^3.4.3",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-icons": "^5.0.1",
    "superjson": "^2.2.1",
    "tailwind-merge": "^2.2.2",
    "tailwindcss-animate": "^1.0.7",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@types/eslint": "^8.56.2",
    "@types/node": "^20.11.20",
    "@types/react": "^18.2.57",
    "@types/react-dom": "^18.2.19",
    "@typescript-eslint/eslint-plugin": "^7.1.1",
    "@typescript-eslint/parser": "^7.1.1",
    "drizzle-kit": "^0.20.14",
    "eslint": "^8.57.0",
    "eslint-config-next": "^14.1.3",
    "eslint-plugin-drizzle": "^0.2.3",
    "pg": "^8.11.3",
    "postcss": "^8.4.34",
    "prettier": "^3.2.5",
    "prettier-plugin-tailwindcss": "^0.5.11",
    "tailwindcss": "^3.4.1",
    "typescript": "^5.4.2"
  },
  "ct3aMetadata": {
    "initVersion": "7.30.0"
  },
  "packageManager": "[email protected]"
}

jzohdi avatar Apr 03 '24 22:04 jzohdi

Getting this issue too but with when using a tRPC procedure. Looks like it looks for a method called "delete" and ensures that the subsequently chained method is called "where" image

LightBounded avatar Apr 08 '24 02:04 LightBounded

Bumping because I get the same issue as OP, also when using a vanilla JS Map instance.

[email protected] [email protected] [email protected]

mrfigg avatar Apr 16 '24 05:04 mrfigg

The same. With Express.js:

import express from 'express'
const adminRouter = express.Router()
adminRouter.delete('/channel', channelDelete) // drizzle/enforce-delete-with-where

With @elastic/elasticsearch:

async function deleteIndex(indexName) {
  await (await client).indices.delete({ index: indexName }) // drizzle/enforce-delete-with-where
}

"drizzle-orm": "^0.30.1" "drizzle-kit": "^0.20.14" "eslint-plugin-drizzle": "^0.2.3"

Vishtar avatar May 03 '24 12:05 Vishtar

Optionally, you can define a drizzleObjectName in the plugin options that accept a string or string[]. This is useful when you have objects or classes with a delete method that’s not from Drizzle. Such a delete method will trigger the ESLint rule. To avoid that, you can define the name of the Drizzle object that you use in your codebase (like db) so that the rule would only trigger if the delete method comes from this object

https://orm.drizzle.team/docs/eslint-plugin#enforce-delete-with-where

arjunyel avatar Jun 04 '24 21:06 arjunyel