✅ The extends: 'recommended'
property in a configuration file enables this rule.
🔧 The --fix
option on the command line can automatically fix some of the problems reported by this rule.
Negated conditions can be hard to reason about and require additional nesting/parenthesis around the condition:
if (not condition)
unless (not condition)
Negated conditions can often be avoided or simplified by:
- Flipping
{{if (not condition)}} {{prop1}} {{else}} {{prop2}} {{/if}}
to{{if condition}} {{prop2}} {{else}} {{prop1}} {{/if}}
- Replacing
if (not condition)
withunless condition
- Replacing
unless (not condition)
withif condition
This rule forbids the following:
And similar examples with non-block forms like:
This rule allows the following:
And similar examples with non-block forms like:
The following values are valid configuration:
- boolean --
true
for enabled /false
for disabled - object --
simplifyHelpers
-- boolean - whether to flag and autofix negated helpers like(not (eq ...))
or(not (gt ...))
that can be simplified (defaulttrue
)
- no-negated-condition from eslint