Skip to content

Bug: no-useless-assignment false positive in generator functions #20583

Description

@yume-chan

Environment

Node version: v22.14.0
npm version: v10.9.2
Local ESLint version: v10.0.2 (Currently used)
Global ESLint version: Not found
Operating System: win32 10.0.26200

What parser are you using?

Default (Espree)

What did you do?

Configuration
import js from "@eslint/js";
import globals from "globals";
import { defineConfig } from "eslint/config";

export default defineConfig([
  { files: ["**/*.{js,mjs,cjs}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.browser } },
]);
function* generator() {
  let done = false;
  try {
    yield 1;
    done = true;
  } catch {
    done = true;
  } finally {
    if (!done) {
      console.log('done is false')
    }
  }
}

const iterator = generator()[Symbol.iterator]();
iterator.next();
iterator.return();

What did you expect to happen?

No error, since the yield can jump to finally directly

What actually happened?

> pnpm eslint

C:\dev\sandbox\eslint-repro\no-useless-assignment.js
  2:7  error  This assigned value is not used in subsequent statements  no-useless-assignment

✖ 1 problem (1 error, 0 warnings)

Running the script prints

> node .\no-useless-assignment.js
done is false

Showing the initial value is being used.

Link to Minimal Reproducible Example

https://github.com/yume-chan/eslint-repro

Participation

  • I am willing to submit a pull request for this issue.

AI acknowledgment

  • I did not use AI to generate this issue report.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

Additional comments

No response

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionbugESLint is working incorrectlyrepro:yesIssues with a reproducible example

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions