Skip to content

fix: array-callback-return omits invalid wrapBraces suggestion - #21547

Open
synthex-byte wants to merge 1 commit into
eslint:mainfrom
synthex-byte:invalid-syntax-in-array-callback-return
Open

synthex-byte wants to merge 1 commit into
eslint:mainfrom
synthex-byte:invalid-syntax-in-array-callback-return

Conversation

@synthex-byte

@synthex-byte synthex-byte commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Prerequisites checklist

AI acknowledgment

Check all that apply.

  • I did not use AI to generate this PR
  • I used AI to write or edit the description of this PR (including translation)
  • I used AI to understand the codebase
  • I used AI to write or edit the files in this PR and I reviewed the files

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:

fixes #21468

What changes did you make? (Give an overview)

Fixed array-callback-return so it doesn't offer the wrapBraces suggestion for unnamed function or class expressions

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

I also cleaned up the duplicated allowVoid/non-allowVoid branches into a single flow while I was at it

Summary by CodeRabbit

  • Bug Fixes
    • Improved lint feedback for forEach callbacks that use concise arrow-function bodies. The rule now more accurately flags returned values and offers applicable suggestions to rewrite the callback or explicitly discard the value, depending on configuration. Suggestions are withheld when the expression cannot be safely rewritten.

@synthex-byte
synthex-byte requested a review from a team as a code owner November 13, 2026 10:54
@eslint-github-bot eslint-github-bot Bot added the bug ESLint is working incorrectly label Nov 13, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Nov 13, 2026
@netlify

netlify Bot commented Nov 13, 2026

Copy link
Copy Markdown

👷 Deploy request for docs-eslint pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit ce812ff

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The array-callback-return rule changes how it reports expression-bodied forEach callbacks that return function or class expressions. It avoids an invalid brace-wrapping suggestion for unparenthesized anonymous expressions and tests suggestion behavior with and without allowVoid.

Changes: forEach return suggestions

Layer / File(s) Summary
Return diagnostics and suggestions
lib/rules/array-callback-return.js, tests/lib/rules/array-callback-return.js
The rule reports expectedNoReturnValue for expression-bodied forEach callbacks unless allowVoid is enabled and the body is already a void expression. It omits wrapBraces for unparenthesized anonymous function and class expressions, and offers prependVoid when allowVoid is enabled. Tests cover these cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: fasttime, joshuakgoldberg

Merge Risk: Minimal · up to ce812

The rule keeps reporting callbacks that return unnamed function or class expressions, and no longer offers a brace-wrapping suggestion that would produce invalid syntax. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the rule (array-callback-return) and the specific defect fixed (an invalid wrapBraces suggestion being offered). The raw summary confirms the rule file changed the suggestion logic…
Linked Issues check Passed Issue #21468 requires that array-callback-return keep reporting forEach expression-bodied callbacks that return unnamed function or class expressions, but not offer a wrapBraces suggestion for t…
Out of Scope Changes check Passed All changes are in lib/rules/array-callback-return.js and its test file. The rule fix adds the canWrapInBraces guard, which implements #21468. The checkLastSegment branches for allowVoid and non…
Full details: Title check

Explanation

The title names the rule (array-callback-return) and the specific defect fixed (an invalid wrapBraces suggestion being offered). The raw summary confirms the rule file changed the suggestion logic for expression-bodied forEach callbacks, and the tests cover that behavior. The title is short, specific, and does not describe anything absent from the changeset. The fix: prefix is a conventional-commit style marker and does not affect relevance.

Full details: Linked Issues check

Explanation

Issue #21468 requires that array-callback-return keep reporting forEach expression-bodied callbacks that return unnamed function or class expressions, but not offer a wrapBraces suggestion for them. At the reviewed head, checkLastSegment in lib/rules/array-callback-return.js computes canWrapInBraces. It is false when the body is a FunctionExpression or ClassExpression with no id and the body is not parenthesised. The wrapBraces suggestion is pushed only when canWrapInBraces is true. The report itself is still emitted with expectedNoReturnValue, so the rule keeps reporting. The tests added in tests/lib/rules/array-callback-return.js, per the change summary, cover the unparenthesised function and class cases with no suggestions. Parenthesised cases keep the brace suggestion, which is valid there. The allowVoid path still offers prependVoid for these cases, as the summary describes. Scope note: the check inspects only the body node type. A body whose leftmost token is function or class, such as x => function(){}.call(), is not covered by this check. The issue examples do not include that form, so this does not fail the requirement.

Full details: Out of Scope Changes check

Explanation

All changes are in lib/rules/array-callback-return.js and its test file. The rule fix adds the canWrapInBraces guard, which implements #21468. The checkLastSegment branches for allowVoid and non-allowVoid are merged into one flow. The PR description states this cleanup, so it is in scope. The added tests exercise the fixed behavior. No unrelated rule or file changes appear in the reviewed summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fd083711-e6ad-447f-8bc5-1f037d1251ee
Commits

Reviewing files that changed from the base of the PR and between 899065e and ce812ff.

Files selected for processing: 2

  • lib/rules/array-callback-return.js
  • tests/lib/rules/array-callback-return.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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: Needs Triage

Development

Successfully merging this pull request may close these issues.

Bug: array-callback-return wrapBraces suggestion creates invalid syntax for anonymous function or class expressions

1 participant