# svelte/no-dupe-else-if-blocks

disallow duplicate conditions in {#if} / {:else if} chains

  • ⚙️ This rule is included in "plugin:svelte/recommended".

# 📖 Rule Details

This rule disallows duplicate conditions in the same {#if} / {:else if} chain.

<script>
  /* eslint svelte/no-dupe-else-if-blocks: "error" */
</script>

<!-- ✓ GOOD -->
{#if a}
  <div>foo</div>
{:else if b}
  <div>bar</div>
{:else if c}
  <div>baz</div>
{/if}

<!-- ✗ BAD -->
{#if a}
  <div>foo</div>
{:else if b}
  <div>bar</div>
{:else if 
This branch can never execute. Its condition is a duplicate or covered by previous conditions in the `{#if}` / `{:else if}` chain. (svelte/no-dupe-else-if-blocks)
b
}
<div>baz</div> {/if} {#if a} <div>foo</div> {:else if b} <div>bar</div> {:else} baz {#if
This branch can never execute. Its condition is a duplicate or covered by previous conditions in the `{#if}` / `{:else if}` chain. (svelte/no-dupe-else-if-blocks)
b
}
<div>qux</div> {/if} {/if}

This rule can also detect some cases where the conditions are not identical, but the branch can never execute due to the logic of || and && operators.

<script>
  /* eslint svelte/no-dupe-else-if-blocks: "error" */
</script>

<!-- ✗ BAD -->
{#if a || b}
  1
{:else if 
This branch can never execute. Its condition is a duplicate or covered by previous conditions in the `{#if}` / `{:else if}` chain. (svelte/no-dupe-else-if-blocks)
a
}
2 {/if} {#if a} 1 {:else if b} 2 {:else if
This branch can never execute. Its condition is a duplicate or covered by previous conditions in the `{#if}` / `{:else if}` chain. (svelte/no-dupe-else-if-blocks)
a || b
}
3 {/if} {#if a} 1 {:else if
This branch can never execute. Its condition is a duplicate or covered by previous conditions in the `{#if}` / `{:else if}` chain. (svelte/no-dupe-else-if-blocks)
a
&& b}
2 {/if} {#if a && b} 1 {:else if
This branch can never execute. Its condition is a duplicate or covered by previous conditions in the `{#if}` / `{:else if}` chain. (svelte/no-dupe-else-if-blocks)
a && b && c
}
2 {/if} {#if a || b} 1 {:else if
This branch can never execute. Its condition is a duplicate or covered by previous conditions in the `{#if}` / `{:else if}` chain. (svelte/no-dupe-else-if-blocks)
b
&& c}
2 {/if} {#if a} 1 {:else if b && c} 2 {:else if d && (
This branch can never execute. Its condition is a duplicate or covered by previous conditions in the `{#if}` / `{:else if}` chain. (svelte/no-dupe-else-if-blocks)
(c && e && b) || a
)}
3 {/if}

# 🔧 Options

Nothing.

# 🚀 Version

This rule was introduced in eslint-plugin-svelte v0.0.1

# 🔍 Implementation