no-return-assign
Assignment in return statements can be confusing - it’s often unclear whether the developer meant to return the assignment or use a comparison operator.Rule Type: Suggestion
Fixable: No
Fixable: No
Why This Rule Exists
Code like this is ambiguous:- Return the result of
bar + 2(and assign it tofoo)? - Use
==for comparison instead of=?
Rule Details
This rule disallows assignments inreturn statements.
Options
"except-parens" (default)
Disallow assignments unless enclosed in parentheses.
Incorrect:
"always"
Disallow all assignments in return statements, even with parentheses.
Incorrect:
Examples
Common Mistake: = vs ==
Intentional Assignment
Common Patterns
Caching Pattern
Conditional Assignment
Chained Assignment
Configuration Examples
When Not to Use It
Disable this rule if you:- Commonly use assignment in return statements
- Have a team convention that accepts this pattern
- Use parentheses to make intent clear