Skip to content

Latest commit

 

History

History
51 lines (33 loc) · 1.43 KB

no-ignored-unsubscribe.md

File metadata and controls

51 lines (33 loc) · 1.43 KB
pageClass sidebarDepth title description since
rule-details
0
svelte/no-ignored-unsubscribe
disallow ignoring the unsubscribe method returned by the `subscribe()` on Svelte stores.
v2.34.0

svelte/no-ignored-unsubscribe

disallow ignoring the unsubscribe method returned by the subscribe() on Svelte stores.

📖 Rule Details

This rule fails if an "unsubscriber" returned by call to subscribe() is neither assigned to a variable or property or passed to a function.

One should always unsubscribe from a store when it is no longer needed. Otherwise, the subscription will remain active and constitute a memory leak. This rule helps to find such cases by ensuring that the unsubscriber (the return value from the store's subscribe method) is not ignored.

<script>
  /* eslint svelte/no-ignored-unsubscribe: "error" */

  import myStore from './my-stores';

  /* ✓ GOOD */
  const unsubscribe = myStore.subscribe(() => {});

  /* ✗ BAD */
  myStore.subscribe(() => {});
</script>

🔧 Options

Nothing.

🚀 Version

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

🔍 Implementation