You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
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
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugESLint is working incorrectlyruleRelates to ESLint's core rules
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites checklist
AI acknowledgment
Check all that apply.
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-returnso it doesn't offer thewrapBracessuggestion for unnamed function or class expressionsIs 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
forEachcallbacks 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.