no-return-assign
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-return-assign": "error",
},
},
];function doSomething() {
return foo = bar + 2;
}
function doSomethingElse() {
return foo += 2;
}
const foo = (a, b) => a = b
const bar = (a, b, c) => (a = b, c == b)
function doSomethingMore() {
return foo = bar && foo > 0;
}function doSomething() {
return foo = bar + 2;
}
function doSomethingElse() {
return foo += 2;
}
function doSomethingMore() {
return (foo = bar + 2);
}function doSomething() {
return foo == bar + 2;
}
function doSomethingElse() {
return foo === bar + 2;
}
function doSomethingMore() {
return (foo = bar + 2);
}
const foo = (a, b) => (a = b)
const bar = (a, b, c) => ((a = b), c == b)
function doAnotherThing() {
return (foo = bar) && foo > 0;
}function doSomething() {
return foo == bar + 2;
}
function doSomethingElse() {
return foo === bar + 2;
}Examples from the ESLint documentation.
no-return-assign
eslint
export default [
{
rules: {
"no-return-assign": "error",
},
},
];no-return-assign
eslint plugin · style
{
"rules": {
"no-return-assign": "error"
}
}suspicious/noReturnAssign
suspicious · since 2.3.11
{
"linter": {
"rules": {
"suspicious": {
"noReturnAssign": "error"
}
}
}
}Enforce variables to be declared either together or separately in functions
Disallow specified global variables
Require using Error objects as Promise rejection reasons
Disallow new operators outside of assignments or comparisons