Skip to content

Commit 5c1f1a8

Browse files
committed
Style fixes for fixture test cases, add ignoreCase option to event-handlers
1 parent fa0ffe7 commit 5c1f1a8

File tree

8 files changed

+37
-9
lines changed

8 files changed

+37
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ If you want to pin a minor version, use a tilde in your `package.json`.
106106

107107
<!-- AUTO-GENERATED-CONTENT:START (TILDE) -->
108108
```diff
109-
- "eslint-plugin-solid": "^0.4.7"
110-
+ "eslint-plugin-solid": "~0.4.7"
109+
- "eslint-plugin-solid": "^0.5.0"
110+
+ "eslint-plugin-solid": "~0.5.0"
111111
```
112112
<!-- AUTO-GENERATED-CONTENT:END -->

docs/event-handlers.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ This rule is **a warning** by default.
1010
See [this issue](https://github.com/joshwilsonvu/eslint-plugin-solid/issues/23) for rationale.
1111

1212
<!-- AUTO-GENERATED-CONTENT:START (OPTIONS) -->
13+
## Rule Options
1314

15+
```
16+
"event-handlers": ["error", { "<key>": "<value>" }]
17+
```
18+
19+
Key | Type | Description
20+
:--- | :---: | :---
21+
ignoreCase | `boolean` | if true, don't warn on ambiguously named event handlers like `onclick` or `onchange`
1422
<!-- AUTO-GENERATED-CONTENT:END -->
1523

1624
<!-- AUTO-GENERATED-CONTENT:START (CASES) -->
@@ -67,5 +75,11 @@ let el = <div on:ly={() => {}} />;
6775

6876
let el = <foo.bar only="true" />;
6977

78+
/* eslint solid/event-handlers: ["error", { "ignoreCase": true }] */
79+
let el = <div onclick={onclick} />;
80+
81+
/* eslint solid/event-handlers: ["error", { "ignoreCase": true }] */
82+
let el = <div only={only} />;
83+
7084
```
7185
<!-- AUTO-GENERATED-CONTENT:END -->

src/rules/event-handlers.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const getCommoneEventHandlerName = (lowercaseEventName: string) => {
7575

7676
const rule: TSESLint.RuleModule<
7777
"naming" | "capitalization" | "make-handler" | "make-attr" | "detected-attr" | "spread-handler",
78-
[]
78+
[{ ignoreCase?: boolean }?]
7979
> = {
8080
meta: {
8181
type: "problem",
@@ -87,7 +87,19 @@ const rule: TSESLint.RuleModule<
8787
},
8888
fixable: "code",
8989
hasSuggestions: true,
90-
schema: [],
90+
schema: [
91+
{
92+
type: "object",
93+
properties: {
94+
ignoreCase: {
95+
description:
96+
"if true, don't warn on ambiguously named event handlers like `onclick` or `onchange`",
97+
type: "boolean",
98+
},
99+
},
100+
additionalProperties: false,
101+
},
102+
],
91103
messages: {
92104
"detected-attr":
93105
'The {{name}} prop is named as an event handler (starts with "on"), but Solid knows its value ({{staticValue}}) is a string or number, so it will be treated as an attribute. If this is intentional, name this prop attr:{{name}}.',
@@ -161,7 +173,7 @@ const rule: TSESLint.RuleModule<
161173
staticValue: node.value !== null ? node.value.value : true,
162174
},
163175
});
164-
} else if (name[2] === name[2].toLowerCase()) {
176+
} else if (name[2] === name[2].toLowerCase() && !context.options[0]?.ignoreCase) {
165177
const lowercaseEventName = match[1].toLowerCase();
166178
if (isCommonEventName(lowercaseEventName)) {
167179
// For common DOM event names, we know the user intended the prop to be an event handler.

test/fixture/valid/stores/create-store/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const App = () => {
3939
console.log(`Creating ${text}`);
4040
return (
4141
<div>
42-
<input type="checkbox" checked={todo.completed} onchange={[toggleTodo, id]} />
42+
<input type="checkbox" checked={todo.completed} onChange={[toggleTodo, id]} />
4343
<span style={{ "text-decoration": todo.completed ? "line-through" : "none" }}>
4444
{text}
4545
</span>

test/fixture/valid/stores/immutable-stores/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const App = () => {
2929
console.log("Create", text);
3030
return (
3131
<div>
32-
<input type="checkbox" checked={todo.completed} onchange={[toggleTodo, id]} />
32+
<input type="checkbox" checked={todo.completed} onChange={[toggleTodo, id]} />
3333
<span style={{ "text-decoration": todo.completed ? "line-through" : "none" }}>
3434
{text}
3535
</span>

test/fixture/valid/stores/mutation/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const App = () => {
4242
console.log(`Creating ${text}`);
4343
return (
4444
<div>
45-
<input type="checkbox" checked={todo.completed} onchange={[toggleTodo, id]} />
45+
<input type="checkbox" checked={todo.completed} onChange={[toggleTodo, id]} />
4646
<span style={{ "text-decoration": todo.completed ? "line-through" : "none" }}>
4747
{text}
4848
</span>

test/fixture/valid/stores/nested-reactivity/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const App = () => {
3737
console.log(`Creating ${text}`);
3838
return (
3939
<div>
40-
<input type="checkbox" checked={todo.completed()} onchange={[toggleTodo, id]} />
40+
<input type="checkbox" checked={todo.completed()} onChange={[toggleTodo, id]} />
4141
<span style={{ "text-decoration": todo.completed() ? "line-through" : "none" }}>
4242
{text}
4343
</span>

test/rules/event-handlers.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export const cases = run("event-handlers", rule, {
1818
`let el = <div onLy={() => {}} />;`,
1919
`let el = <div on:ly={() => {}} />;`,
2020
`let el = <foo.bar only="true" />;`,
21+
{ code: `let el = <div onclick={onclick} />`, options: [{ ignoreCase: true }] },
22+
{ code: `let el = <div only={only} />`, options: [{ ignoreCase: true }] },
2123
],
2224
invalid: [
2325
{

0 commit comments

Comments
 (0)