Skip to content

Latest commit

 

History

History
76 lines (53 loc) · 1.61 KB

simple-unless.md

File metadata and controls

76 lines (53 loc) · 1.61 KB

simple-unless

✅ 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.

This rule strongly advises against {{unless}} blocks in the following situations:

  • With other block helpers (e.g. {{else}}, {{else if}})
  • With template helpers in the condition

Common solutions are to use an {{if}} block, or refactor potentially confusing logic within the template.

Examples

This rule forbids the following:

{{!-- `unless` condition has a template helper  --}}

{{unless (if true) "This is not recommended"}}
{{!-- `unless` statement has an `else` block  --}}

{{#unless bandwagoner}}
  Go Niners!
{{else}}
  Go Seahawks!
{{/unless}}
{{!-- conditional statement has an `else unless` block  --}}

{{#if condition}}
  Hello
{{else unless otherCondition}}
  World
{{/unless}}

This rule allows the following:

{{#if bandwagoner}}
  Go Blue Jays!
{{else}}
  Go Mariners!
{{/if}}
{{#unless condition}}
  Hello World
{{/unless}}

Configuration

The following values are valid configuration:

  • boolean -- true for enabled / false for disabled
  • object --
    • allowlist -- array - ['or'] for specific helpers / [] for wildcard
    • denylist -- array - ['or'] for specific helpers / [] for none
    • maxHelpers -- number - default 1 - use -1 for no limit

Related Rules

References