src/content/docs/linter/rules/no-yoda-expression.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.8.0` - Diagnostic Category: [`lint/style/noYodaExpression`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`yoda`](https://eslint.org/docs/latest/rules/yoda){
"linter": {
"rules": {
"style": {
"noYodaExpression": "error"
}
}
}
}
Disallow the use of yoda expressions.
A Yoda expression is a programming style where, given a binary operation, the "static" part of the binary operation is placed on the left-hand side. This rule forbids the use of Yoda expressions and enforces the placing of the "static" part of the binary operations on the right-hand side.
Range expressions like 0 < value && value < 1 or value <= 0 || 1 < value are allowed.
if ("red" == value) {}
if (true === value) {}
if (5 != value) {}
if (value === "red") {}
if (value === value) {}
if (value != 5) {}
if (0 < value && value < 1) {}