src/content/docs/linter/rules/no-negation-else.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/style/noNegationElse`](/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 [`no-negated-condition`](https://eslint.org/docs/latest/rules/no-negated-condition) - Same as [`if_not_else`](https://rust-lang.github.io/rust-clippy/master/#if_not_else){
"linter": {
"rules": {
"style": {
"noNegationElse": "error"
}
}
}
}
Disallow negation in the condition of an if statement if it has an else clause.
if (!cond) { f();} else { g();}
!cond ? 0 : 1
if (!cond) { f(); }
cond ? 1 : 0
if (!cond) { f(); }
if (!!val) { f(); } else { g(); }