-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
svelte/require-store-reactive-access
rule (#289)
* feat: add `svelte/require-store-reactive-access` rule * Create warm-eagles-sing.md * fix: add testcases and fix bugs * fix: error message * feat: improves demo * fix: docs * fix: shim path * fix: docs and message * feat: improve require-store-reactive-access
- Loading branch information
Showing
116 changed files
with
2,359 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"eslint-plugin-svelte": patch | ||
--- | ||
|
||
feat: add `svelte/require-store-reactive-access` rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ LICENSE | |
# should we ignore markdown files? | ||
*.md | ||
/docs-svelte-kit/ | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
pageClass: "rule-details" | ||
sidebarDepth: 0 | ||
title: "svelte/require-store-reactive-access" | ||
description: "disallow to use of the store itself as an operand. Need to use $ prefix or get function." | ||
--- | ||
|
||
# svelte/require-store-reactive-access | ||
|
||
> disallow to use of the store itself as an operand. Need to use $ prefix or get function. | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge> | ||
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. | ||
|
||
## :book: Rule Details | ||
|
||
This rule disallow to use of the store itself as an operand. | ||
You should access the store value using the `$` prefix or the `get` function. | ||
|
||
<ESLintCodeBlock fix> | ||
|
||
<!--eslint-skip--> | ||
|
||
```svelte | ||
<script> | ||
/* eslint svelte/require-store-reactive-access: "error" */ | ||
import { writable, get } from "svelte/store" | ||
const storeValue = writable("world") | ||
const color = writable("red") | ||
/* ✓ GOOD */ | ||
$: message = `Hello ${$storeValue}` | ||
/* ✗ BAD */ | ||
$: message = `Hello ${storeValue}` | ||
</script> | ||
<!-- ✓ GOOD --> | ||
<p>{$storeValue}</p> | ||
<p>{get(storeValue)}</p> | ||
<p class={$storeValue} /> | ||
<p style:color={$color} /> | ||
<MyComponent prop="Hello {$storeValue}" /> | ||
<MyComponent bind:this={$storeValue} /> | ||
<MyComponent --style-props={$storeValue} /> | ||
<MyComponent {...$storeValue} /> | ||
<!-- ✗ BAD --> | ||
<p>{storeValue}</p> | ||
<p class={storeValue} /> | ||
<p style:color /> | ||
<MyComponent prop="Hello {storeValue}" /> | ||
<MyComponent bind:this={storeValue} /> | ||
<MyComponent --style-props={storeValue} /> | ||
<MyComponent {...storeValue} /> | ||
``` | ||
|
||
</ESLintCodeBlock> | ||
|
||
This rule checks the usage of store variables only if the store can be determined within a single file. | ||
However, when using `@typescript-eslint/parser` and full type information, this rule uses the type information to determine if the expression is a store. | ||
|
||
<!--eslint-skip--> | ||
|
||
```ts | ||
// fileName: my-stores.ts | ||
import { writable } from "svelte/store" | ||
export const storeValue = writable("hello") | ||
``` | ||
|
||
<!--eslint-skip--> | ||
|
||
```svelte | ||
<script lang="ts"> | ||
/* eslint svelte/require-store-reactive-access: "error" */ | ||
import { storeValue } from "./my-stores" | ||
</script> | ||
<!-- ✓ GOOD --> | ||
<p>{$storeValue}</p> | ||
<!-- ✗ BAD --> | ||
<p>{storeValue}</p> | ||
``` | ||
|
||
## :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/src/rules/require-store-reactive-access.ts) | ||
- [Test source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/tests/src/rules/require-store-reactive-access.ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.