src/content/docs/linter/rules/no-assign-in-expressions.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/suspicious/noAssignInExpressions`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Inspired from [`no-cond-assign`](https://eslint.org/docs/latest/rules/no-cond-assign){
"linter": {
"rules": {
"suspicious": {
"noAssignInExpressions": "error"
}
}
}
}
Disallow assignments in expressions.
In expressions, it is common to mistype a comparison operator (such as ==) as an assignment operator (such as =).
Moreover, the use of assignments in expressions is confusing.
Indeed, expressions are often considered as side-effect free.
let a, b;
a = (b = 1) + 1;
let a;
if (a = 1) {
}
function f(a) {
return a = 1;
}
let a;
a = 1;
let a = 0;
const f = b => a += b;