no-negated-condition.md
January 23, 2019 ยท View on GitHub
no-negated-condition
It can be hard to reason about negated conditions:
if (not condition)unless (not condition)
Negated conditions can often be avoided or simplified by:
- Flipping
if (not condition) ... else ...toif .... else ... - Replacing
if (not condition)withunless - Replacing
unless (not condition)withif
This rule forbids the following:
{{#if (not condition)}}
...
{{/if}}
{{#if (not condition)}}
...
{{else}}
...
{{/if}}
{{#unless (not condition)}}
...
{{/unless}}
And similar examples with non-block forms like:
<img class={{if (not condition) "some-class" "other-class"}}>
{{input class=(if (not condition) "some-class" "other-class")}}
This rule allows the following:
{{#if condition}}
...
{{/if}}
{{#if condition}}
...
{{else}}
...
{{/if}}
{{#unless condition}}
...
{{/unless}}
And similar examples with non-block forms like:
<img class={{if condition "some-class" "other-class"}}>
{{input class=(if condition "some-class" "other-class")}}
Related Rules
References
- no-negated-condition from eslint