Skip to content

[Eslint Plugin] Fix enforce-update-with-where false positive when .from() precedes .where()#5786

Open
LeSingh1 wants to merge 1 commit into
drizzle-team:mainfrom
LeSingh1:fix/eslint-update-where-after-from
Open

[Eslint Plugin] Fix enforce-update-with-where false positive when .from() precedes .where()#5786
LeSingh1 wants to merge 1 commit into
drizzle-team:mainfrom
LeSingh1:fix/eslint-update-where-after-from

Conversation

@LeSingh1
Copy link
Copy Markdown

Closes #5612.

The enforce-update-with-where rule reports an update without where when .from() appears before .where() in the chain, for example:

await tx
  .update(table)
  .set({ ... })
  .from(sql`(VALUES ...) AS v(...)`)
  .where(eq(table.id, v.id));

The rule decides whether to report on the .set() MemberExpression by checking a module-level lastNodeName variable that is updated each time a MemberExpression is visited. ESLint visits MemberExpression nodes from the outermost call inward, so for the chain above the visit order is .where, then .from, then .set, then .update. By the time .set is visited, lastNodeName is "from" rather than "where", so the rule fires even though .where is present in the same chain.

The fix replaces the visit-order heuristic with a small AST walk that follows the surrounding CallExpression and MemberExpression nodes upward from the .set() MemberExpression, and reports only when no later chained call uses the name where. Behavior for chains without a trailing .from() is unchanged.

Tests:

Added two valid cases to tests/update.test.ts covering .from() before .where(), with and without a trailing .returning(). Both fail on main and pass with the fix. All 113 existing rule tests still pass.

…om() precedes .where()

The enforce-update-with-where rule tracked the previously visited
MemberExpression to decide whether .set() was followed by .where().
ESLint visits MemberExpression nodes from the outermost call inward,
so for db.update().set().from(...).where(...) the .from MemberExpression
was the most recently visited node by the time the rule reached .set,
causing a false positive.

The rule now walks up the AST from the .set() MemberExpression along
the surrounding chain of CallExpression/MemberExpression nodes and
reports only when .where is not present anywhere later in that chain.

Closes drizzle-team#5612
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: enforce-update-with-where false positive when .from() precedes .where() in chain

1 participant