Skip to content

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.

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);
}

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.