Skip to content

Latest commit

 

History

History
58 lines (44 loc) · 1.62 KB

prefer-let.md

File metadata and controls

58 lines (44 loc) · 1.62 KB
pageClass sidebarDepth title description
rule-details
0
svelte/prefer-let
Prefer `let` over `const` for Svelte 5 reactive variable declarations.

svelte/prefer-let

Prefer let over const for Svelte 5 reactive variable declarations.

  • This rule has not been released yet.
  • 🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.

📖 Rule Details

This rule reports usages of const variable declarations on Svelte reactive function assignments. While values may not be reassigned in the code itself, they are reassigned by Svelte.

<script>
  /* eslint svelte/prefer-let: "error" */

  // ✓ GOOD
  let { a, b } = $props();
  let c = $state('');
  let d = $derived(a * 2);
  let e = $derived.by(() => b * 2);

  // ✗ BAD
  const g = $state(0);
  const h = $derived({ count: g });
</script>

🔧 Options

{
  "svelte/prefer-const": [
    "error",
    {
      "exclude": ["$props", "$derived", "$derived.by", "$state", "$state.raw"]
    }
  ]
}
  • exclude: The reactive assignments that you want to exclude from being reported.

🔍 Implementation