returnAssignments
Reports using assignment expressions in return statements.
✅ This rule is included in the ts stylistic
preset.
Using assignments in return statements can make code harder to read and can lead to confusion about whether the assignment or the returned value is the primary intent. Assignment expressions return the assigned value, but mixing assignment with return makes the control flow less clear.
Examples
Section titled “Examples”function getValue() { let value; return (value = 1);}
function process() { let result; return (result = calculate());}
const arrow = () => (value = 42);
function compound() { let count; return (count += 5);}
function getValue() { let value = 1; return value;}
function process() { let result = calculate(); return result;}
const arrow = () => { const value = 42; return value;};
function compound() { let count = 0; count += 5; return count;}
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase uses assignments in return statements as a common idiom and you find them readable, you might choose to disable this rule. However, separating assignments from return statements generally improves code clarity and reduces potential for confusion.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
no-return-assign
- Oxlint:
eslint/no-return-assign
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.