Skip to content

Latest commit

 

History

History
88 lines (64 loc) · 1.46 KB

no-negated-condition.md

File metadata and controls

88 lines (64 loc) · 1.46 KB

no-negated-condition

✅ The extends: 'recommended' property in a configuration file enables this rule.

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)}} {{prop1}} {{else}} {{prop2}} {{/if}} to {{if condition}} {{prop2}} {{else}} {{prop1}} {{/if}}
  • Replacing if (not condition) with unless condition
  • Replacing unless (not condition) with if condition

Examples

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