src/content/docs/linter/rules/no-return-assign.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.11` - Diagnostic Category: [`lint/nursery/noReturnAssign`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`no-return-assign`](https://eslint.org/docs/latest/rules/no-return-assign){
"linter": {
"rules": {
"nursery": {
"noReturnAssign": "error"
}
}
}
}
Disallow assignments in return statements.
In return statements, it is common to mistype a comparison operator (such as ==) as an assignment operator (such as =).
Moreover, the use of assignments in a return statement is confusing.
Return statements are often considered side-effect free.
function f(a) {
return a = 1;
}
function f(a) {
a = 1;
return a;
}
function f(a) {
return a == 1;
}