Skip to content

Commit 7485959

Browse files
committed
Less strict checking of event handler attribute names
1 parent 6635d16 commit 7485959

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/eslint-plugin-solid/src/rules/reactivity.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,14 @@ export default createRule<Options, MessageIds>({
850850
if (node.type === "JSXExpressionContainer") {
851851
if (
852852
node.parent?.type === "JSXAttribute" &&
853-
/^on[:A-Z]/.test(sourceCode.getText(node.parent.name)) &&
853+
sourceCode.getText(node.parent.name).startsWith("on") &&
854854
node.parent.parent?.type === "JSXOpeningElement" &&
855855
node.parent.parent.name.type === "JSXIdentifier" &&
856856
isDOMElementName(node.parent.parent.name.name)
857857
) {
858-
// Expect a function if the attribute is like onClick={} or on:click={}. From the docs:
858+
// Expect a function if the attribute is like onClick={}, onclick={}, on:click={}, or
859+
// custom events such as on-click={}.
860+
// From the docs:
859861
// Events are never rebound and the bindings are not reactive, as it is expensive to
860862
// attach and detach listeners. Since event handlers are called like any other function
861863
// each time an event fires, there is no need for reactivity; simply shortcut your handler

test/valid/reactivity/on/main.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createSignal, createEffect, on } from "solid-js";
55
const App = () => {
66
const [a, setA] = createSignal(1);
77
const [b, setB] = createSignal(1);
8+
const [c, setC] = createSignal(1);
89

910
createEffect(
1011
on(
@@ -19,7 +20,11 @@ const App = () => {
1920
return (
2021
<>
2122
<button onClick={() => setA(a() + 1)}>Increment A</button>
22-
<button onClick={() => setB(b() + 1)}>Increment B</button>
23+
<button on:click={() => setB(b() + 1)}>Increment B</button>
24+
<button on-click={() => setC(c() + 1)}>Increment C</button>
25+
<button onClick={async () => setA(a() + 1)}>Async Increment A</button>
26+
<button on:click={async () => setB(b() + 1)}>Async Increment B</button>
27+
<button on-click={async () => setC(c() + 1)}>Async Increment C</button>
2328
</>
2429
);
2530
};

0 commit comments

Comments
 (0)