Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add no-reactive-functions rule #206

Merged
merged 3 commits into from
Aug 3, 2022
Merged

Conversation

tivac
Copy link
Collaborator

@tivac tivac commented Jul 31, 2022

📖 Rule Details

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>

src/rules/no-reactive-functions.ts Outdated Show resolved Hide resolved
src/rules/no-reactive-functions.ts Outdated Show resolved Hide resolved
Added a description, and now handling the possibility of no space after the reactive statement label.
Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you very much!

@ota-meshi ota-meshi requested a review from JounQin August 3, 2022 06:32
@ota-meshi ota-meshi merged commit bc23974 into sveltejs:main Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants