Skip to content

Commit b84cc7e

Browse files
committed
Improve language and tests.
1 parent 1310464 commit b84cc7e

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const [editedValue, setEditedValue] = createSignal(props.value);
131131
|| 🔧 | [solid/no-destructure](docs/no-destructure.md) | Disallow destructuring props. In Solid, props must be used with property accesses (`props.foo`) to preserve reactivity. This rule only tracks destructuring in the parameter list. |
132132
|| 🔧 | [solid/no-innerhtml](docs/no-innerhtml.md) | Disallow usage of the innerHTML attribute, which can often lead to security vulnerabilities. |
133133
| | | [solid/no-proxy-apis](docs/no-proxy-apis.md) | Disallow usage of APIs that use ES6 Proxies, only to target environments that don't support them. |
134-
|| 🔧 | [solid/no-react-deps](docs/no-react-deps.md) | Disallow usage of dependency arrays in createEffect and createMemo. |
134+
|| 🔧 | [solid/no-react-deps](docs/no-react-deps.md) | Disallow usage of dependency arrays in `createEffect` and `createMemo`. |
135135
|| 🔧 | [solid/no-react-specific-props](docs/no-react-specific-props.md) | Disallow usage of React-specific `className`/`htmlFor` props, which were deprecated in v1.4.0. |
136136
|| | [solid/no-unknown-namespaces](docs/no-unknown-namespaces.md) | Enforce using only Solid-specific namespaced attribute names (i.e. `'on:'` in `<div on:click={...} />`). |
137137
| | 🔧 | [solid/prefer-classlist](docs/prefer-classlist.md) | Enforce using the classlist prop over importing a classnames helper. The classlist prop accepts an object `{ [class: string]: boolean }` just like classnames. |

docs/no-react-deps.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- AUTO-GENERATED-CONTENT:START (HEADER) -->
22
# solid/no-react-deps
3-
Disallow usage of dependency arrays in createEffect and createMemo.
3+
Disallow usage of dependency arrays in `createEffect` and `createMemo`.
44
This rule is **a warning** by default.
55

66
[View source](../src/rules/no-react-deps.ts) · [View tests](../test/rules/no-react-deps.test.ts)
@@ -16,7 +16,7 @@ This rule is **a warning** by default.
1616

1717
### Invalid Examples
1818

19-
These snippets cause lint errors, and all of them can be auto-fixed.
19+
These snippets cause lint errors, and some can be auto-fixed.
2020

2121
```js
2222
createEffect(() => {
@@ -35,6 +35,11 @@ createEffect(() => {
3535
console.log(signal());
3636
});
3737

38+
const deps = [signal];
39+
createEffect(() => {
40+
console.log(signal());
41+
}, deps);
42+
3843
const value = createMemo(() => computeExpensiveValue(a(), b()), [a(), b()]);
3944
// after eslint --fix:
4045
const value = createMemo(() => computeExpensiveValue(a(), b()));
@@ -47,6 +52,13 @@ const value = createMemo(() => computeExpensiveValue(a(), b()), [a, b()]);
4752
// after eslint --fix:
4853
const value = createMemo(() => computeExpensiveValue(a(), b()));
4954

55+
const deps = [a, b];
56+
const value = createMemo(() => computeExpensiveValue(a(), b()), deps);
57+
58+
const deps = [a, b];
59+
const memoFn = () => computeExpensiveValue(a(), b());
60+
const value = createMemo(memoFn, deps);
61+
5062
```
5163

5264
### Valid Examples

src/rules/no-react-deps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ const rule: TSESLint.RuleModule<"noUselessDep", []> = {
66
type: "problem",
77
docs: {
88
recommended: "warn",
9-
description: "Disallow usage of dependency arrays in createEffect and createMemo.",
9+
description: "Disallow usage of dependency arrays in `createEffect` and `createMemo`.",
1010
url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/docs/no-react-deps.md",
1111
},
1212
fixable: "code",
1313
schema: [],
1414
messages: {
1515
noUselessDep:
16-
"In Solid, {{ name }} doesn't need a dependency array because it automatically tracks its dependencies. If you really need to override the list of dependencies, use `on`.",
16+
"In Solid, `{{name}}` doesn't accept a dependency array because it automatically tracks its dependencies. If you really need to override the list of dependencies, use `on`.",
1717
},
1818
},
1919
create(context) {

test/rules/no-react-deps.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ export const cases = run("no-react-deps", rule, {
3333
console.log(signal());
3434
}, );`,
3535
},
36+
{
37+
code: `const deps = [signal];
38+
createEffect(() => {
39+
console.log(signal());
40+
}, deps);`,
41+
errors: [{ messageId: "noUselessDep", data: { name: "createEffect" } }],
42+
// no `output`
43+
},
3644
{
3745
code: `const value = createMemo(() => computeExpensiveValue(a(), b()), [a(), b()]);`,
3846
errors: [{ messageId: "noUselessDep", data: { name: "createMemo" } }],
@@ -48,5 +56,18 @@ export const cases = run("no-react-deps", rule, {
4856
errors: [{ messageId: "noUselessDep", data: { name: "createMemo" } }],
4957
output: `const value = createMemo(() => computeExpensiveValue(a(), b()), );`,
5058
},
59+
{
60+
code: `const deps = [a, b];
61+
const value = createMemo(() => computeExpensiveValue(a(), b()), deps);`,
62+
errors: [{ messageId: "noUselessDep", data: { name: "createMemo" } }],
63+
// no `output`
64+
},
65+
{
66+
code: `const deps = [a, b];
67+
const memoFn = () => computeExpensiveValue(a(), b());
68+
const value = createMemo(memoFn, deps);`,
69+
errors: [{ messageId: "noUselessDep", data: { name: "createMemo" } }],
70+
// no `output`
71+
},
5172
],
5273
});

0 commit comments

Comments
 (0)