Skip to content

fix: rule suggestions cause continuation in class body#20787

Merged
DMartens merged 3 commits into
mainfrom
nouselessconstructor-generators
Apr 28, 2026
Merged

fix: rule suggestions cause continuation in class body#20787
DMartens merged 3 commits into
mainfrom
nouselessconstructor-generators

Conversation

@mdjermanovic

@mdjermanovic mdjermanovic commented Apr 22, 2026

Copy link
Copy Markdown
Member

Prerequisites checklist

AI acknowledgment

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

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Tell us about your environment (npx eslint --env-info):

  • Node version: 22.14.0
  • npm version: 10.9.2
  • Local ESLint version: 10.2.1
  • Global ESLint version: no
  • Operating System: windows

What parser are you using (place an "X" next to just one item)?

[x] Default (Espree)
[ ] @typescript-eslint/parser
[ ] @babel/eslint-parser
[ ] vue-eslint-parser
[ ] @angular-eslint/template-parser
[ ] Other

Please show your full configuration:

Configuration
export default [{}];

What did you do? Please include the actual source code causing the issue.

/* eslint no-useless-constructor: 2 */

class A {
    foo = 'bar'
    constructor() {}
    *baz() {}
}

What did you expect to happen?

The no-useless-constructor rule to report the constructor as useless and provide a valid suggestion to remove it.

What actually happened? Please include the actual, raw output from ESLint.

The no-useless-constructor rule reports the constructor as useless and provides suggestion to remove it. However, applying the suggestion causes a parsing error:

/*eslint no-useless-constructor: 2 */

class A {
    foo = 'bar'
    
    *baz() {}
}
Parsing error: Unexpected token {

Playground link

The suggestion should insert a semicolon to prevent continuation.

What changes did you make? (Give an overview)

  • Updated the no-useless-constructor rule to use a new helper astUtils.canContinueExpressionInClassBody(token) that checks for the following tokens that can cause continuation: [, *, in, instanceof.
  • Updated the require-await rule in the same way.
  • Also updated astUtils.needsPrecedingSemicolon to avoid unnecessary semicolons in case of uninitialized class fields.

Is there anything you'd like reviewers to focus on?

@mdjermanovic
mdjermanovic requested a review from a team as a code owner April 22, 2026 14:26
@eslint-github-bot eslint-github-bot Bot added the bug ESLint is working incorrectly label Apr 22, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Apr 22, 2026
@netlify

netlify Bot commented Apr 22, 2026

Copy link
Copy Markdown

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit d4d3cb1
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/69f10d93e2d80d00086a380a

@github-actions github-actions Bot added the rule Relates to ESLint's core rules label Apr 22, 2026
@DMartens DMartens moved this from Needs Triage to Implementing in Triage Apr 23, 2026
Comment thread lib/rules/utils/ast-utils.js
Comment thread lib/rules/require-await.js
@DMartens

Copy link
Copy Markdown
Contributor

Sorry for the delay.
Should this PR also replace the semicolon logic for the now landed no-unused-private-class-members?

@mdjermanovic
mdjermanovic force-pushed the nouselessconstructor-generators branch from c522ef9 to 6e7c478 Compare April 28, 2026 18:40
@mdjermanovic

Copy link
Copy Markdown
Member Author

Should this PR also replace the semicolon logic for the now landed no-unused-private-class-members?

Updated in d4d3cb1.

@DMartens DMartens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM, thanks.

@DMartens
DMartens merged commit 6fb3685 into main Apr 28, 2026
61 of 69 checks passed
@DMartens
DMartens deleted the nouselessconstructor-generators branch April 28, 2026 21:03
@github-project-automation github-project-automation Bot moved this from Implementing to Complete in Triage Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ESLint is working incorrectly rule Relates to ESLint's core rules

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

2 participants