Skip to content

feat(prefer-svelte-reactivity): ignoring encapsulated local variables by default #1287

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
5 changes: 5 additions & 0 deletions .changeset/long-ghosts-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': minor
---

feat(prefer-svelte-reactivity): ignoring variables encapsulated in functions
5 changes: 5 additions & 0 deletions .changeset/lovely-carpets-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': minor
---

feat(prefer-svelte-reactivity): reporting public properties
5 changes: 5 additions & 0 deletions .changeset/lovely-moments-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': minor
---

feat(prefer-svelte-reactivity): reporting returned variables
13 changes: 12 additions & 1 deletion docs/rules/prefer-svelte-reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ export default e;

## :wrench: Options

Nothing.
```json
{
"svelte/prefer-svelte-reactivity": [
"error",
{
"ignoreEncapsulatedLocalVariables": true
}
]
}
```

- `ignoreEncapsulatedLocalVariables` ... Whether to ignore variables that are defined inside a function and aren't returned, thus being encapsulated in the function. Default `true`.

## :books: Further Reading

Expand Down
6 changes: 5 additions & 1 deletion packages/eslint-plugin-svelte/src/rule-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export interface RuleOptions {
* disallow using mutable instances of built-in classes where a reactive alternative is provided by svelte/reactivity
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/prefer-svelte-reactivity/
*/
'svelte/prefer-svelte-reactivity'?: Linter.RuleEntry<[]>
'svelte/prefer-svelte-reactivity'?: Linter.RuleEntry<SveltePreferSvelteReactivity>
/**
* Prefer using writable $derived instead of $state and $effect
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/prefer-writable-derived/
Expand Down Expand Up @@ -580,6 +580,10 @@ type SveltePreferConst = []|[{
excludedRunes?: string[]
[k: string]: unknown | undefined
}]
// ----- svelte/prefer-svelte-reactivity -----
type SveltePreferSvelteReactivity = []|[{
ignoreEncapsulatedLocalVariables?: boolean
}]
// ----- svelte/require-event-prefix -----
type SvelteRequireEventPrefix = []|[{
checkAsyncFunctions?: boolean
Expand Down
Loading
Loading