Skip to content

Files

Latest commit

 

History

History
42 lines (30 loc) · 1 KB

no-reactive-functions.md

File metadata and controls

42 lines (30 loc) · 1 KB

Pattern: Unnecessary function definition in reactive statement

Issue: -

Description

This rule reports whenever a function is defined in a reactive statement. This isn't necessary, as each time the function is executed it'll already have access to the latest values necessary. Redefining the function in the reactive statement is just a waste of CPU cycles.

<script>
  /* eslint svelte/no-reactive-functions: "error" */

  /* ✓ GOOD */
  const arrowFn = () => {
    /* ... */
  };
  const func = function () {
    /* ... */
  };

  /* ✗ BAD */
  $: arrowFn = () => {
    /* ... */
  };
  $: func = function () {
    /* ... */
  };
</script>

🔧 Options

Nothing

🚀 Version

This rule was introduced in eslint-plugin-svelte v2.5.0

🔍 Implementation