pageClass | sidebarDepth | title | description |
---|---|---|---|
rule-details |
0 |
svelte/no-shadow |
Disallow variable declarations from shadowing variables declared in the outer scope |
Disallow variable declarations from shadowing variables declared in the outer scope
- ❗ This rule has not been released yet.
This rule reports shadowed variables, similar to the base ESLint no-shadow
rule. However, it ignores cases where {#snippet}
is used as a named slot in Svelte components. If this rule is active, make sure to disable the base no-shadow
rule, as it will conflict with this rule.
<script>
/* eslint svelte/no-shadow: "error" */
import ComponentWithSnippet from './ComponentWithSnippet.svelte';
</script>
<!-- ✓ GOOD -->
<ComponentWithSnippet>
{#snippet children()}
<AnotherComponentWithSnippet>
{#snippet children()}
Hello!
{/snippet}
</AnotherComponentWithSnippet>
{/snippet}
</ComponentWithSnippet>
<!-- ✗ BAD -->
<ComponentWithSnippet>
{@const foo = 1}
<ComponentWithSnippet>
{@const foo = 2}
</ComponentWithSnippet>
</ComponentWithSnippet>
{
"svelte/no-shadow": [
"error",
{ "builtinGlobals": false, "hoist": "functions", "allow": [], "ignoreOnInitialization": false }
]
}
builtinGlobals
: ThebuiltinGlobals
option isfalse
by default. If it istrue
, the rule prevents shadowing of built-in global variables:Object
,Array
,Number
, and so on.hoist
: Thehoist
option has three settings:functions
(by default) - reports shadowing before the outer functions are defined.all
- reports all shadowing before the outer variables/functions are defined.never
- never report shadowing before the outer variables/functions are defined.
allow
: Theallow
option is an array of identifier names for which shadowing is allowed. For example,"resolve"
,"reject"
,"done"
,"cb"
.ignoreOnInitialization
: TheignoreOnInitialization
option isfalse
by default. If it istrue
, it prevents reporting shadowing of variables in their initializers when the shadowed variable is presumably still uninitialized. The shadowed variable must be on the left side. The shadowing variable must be on the right side and declared in a callback function or in an IIFE.
- See ESLint
no-shadow
rule for more information about the base rule.
Taken with ❤️ from ESLint core