@murky-web/oxlint-plugin-solid 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +163 -18
  2. package/THIRD_PARTY_NOTICES.md +7 -4
  3. package/package.json +5 -2
  4. package/src/compat.mjs +3 -0
  5. package/src/index.mjs +26 -3
  6. package/src/rules/components_return_once.mjs +136 -89
  7. package/src/rules/event_handlers.mjs +55 -35
  8. package/src/rules/filename_matches_export.mjs +292 -0
  9. package/src/rules/function_size.mjs +189 -0
  10. package/src/rules/imports.mjs +24 -21
  11. package/src/rules/init_declarations.mjs +139 -0
  12. package/src/rules/jsx_no_duplicate_props.mjs +46 -18
  13. package/src/rules/jsx_no_script_url.mjs +7 -6
  14. package/src/rules/jsx_no_undef.mjs +35 -38
  15. package/src/rules/jsx_uses_vars.mjs +4 -4
  16. package/src/rules/no_array_handlers.mjs +38 -9
  17. package/src/rules/no_cleanup_in_effect_apply.mjs +154 -0
  18. package/src/rules/no_destructure.mjs +105 -35
  19. package/src/rules/no_innerhtml.mjs +64 -31
  20. package/src/rules/no_module_scope_reactive_primitive.mjs +73 -0
  21. package/src/rules/no_owned_primitives_in_ref.mjs +30 -9
  22. package/src/rules/no_proxy_apis.mjs +44 -15
  23. package/src/rules/no_react_deps.mjs +397 -41
  24. package/src/rules/no_react_specific_props.mjs +40 -11
  25. package/src/rules/no_server_import_in_client.mjs +9 -9
  26. package/src/rules/no_setter_in_effect.mjs +153 -30
  27. package/src/rules/no_single_arg_create_effect.mjs +55 -0
  28. package/src/rules/no_unassigned_vars.mjs +99 -0
  29. package/src/rules/no_unknown_namespaces.mjs +108 -29
  30. package/src/rules/no_untracked_effect_read.mjs +69 -32
  31. package/src/rules/no_write_in_pure_computation.mjs +273 -0
  32. package/src/rules/prefer_arrow_components.mjs +47 -21
  33. package/src/rules/prefer_class_object.mjs +52 -20
  34. package/src/rules/prefer_destructuring.mjs +164 -0
  35. package/src/rules/prefer_for.mjs +42 -12
  36. package/src/rules/prefer_ref_shorthand.mjs +142 -0
  37. package/src/rules/prefer_show.mjs +55 -24
  38. package/src/rules/reactive_async.mjs +64 -17
  39. package/src/rules/reactivity.mjs +1218 -350
  40. package/src/rules/self_closing_comp.mjs +23 -18
  41. package/src/rules/strict_void_return.mjs +50 -20
  42. package/src/rules/style_prop.mjs +53 -25
  43. package/src/rules/typed_merge_defaults.mjs +88 -0
  44. package/src/rules/validate_jsx_nesting.mjs +16 -16
  45. package/src/utils.mjs +65 -34
@@ -0,0 +1,139 @@
1
+ // Fork of eslint's init-declarations ("always") for Solid code. Every `let` and
2
+ // `var` needs an initial value, except a variable a `ref` assigns: Solid sets
3
+ // it to the element before anything reads it, and a default would be a value
4
+ // nobody ever sees. Assigned by a ref means `ref={el}` or `ref={el!}` (the
5
+ // compiler rewrites the single shorthand to an assignment) or `el = node` in a
6
+ // ref callback, directly or inside a `ref={[…]}` array. A bare `el` inside a
7
+ // ref array is never assigned; solid/prefer-ref-shorthand reports that entry,
8
+ // so this rule leaves its declaration alone. As in eslint, `for-in`/`for-of`
9
+ // variables and `declare` declarations are ignored.
10
+ import { findVariable } from "../compat.mjs";
11
+ import { isFunctionNode, jsxPropName, walkOwnBody } from "../utils.mjs";
12
+
13
+ function unwrapNonNull(node) {
14
+ return node?.type === "TSNonNullExpression" ? node.expression : node;
15
+ }
16
+
17
+ function isLoopVariable(declaration) {
18
+ const { parent } = declaration;
19
+ return (
20
+ (parent.type === "ForInStatement" ||
21
+ parent.type === "ForOfStatement") &&
22
+ parent.left === declaration
23
+ );
24
+ }
25
+
26
+ /** `declare let x: T;`, or any declaration in a `declare module`/`global`. */
27
+ function isAmbient(declaration) {
28
+ for (let node = declaration; node; node = node.parent) {
29
+ if (node.declare === true) {
30
+ return true;
31
+ }
32
+ }
33
+ return false;
34
+ }
35
+
36
+ export default {
37
+ meta: {
38
+ type: "suggestion",
39
+ docs: {
40
+ description:
41
+ "Require an initial value for `let` and `var`, except for a variable a `ref` assigns."
42
+ },
43
+ schema: [],
44
+ messages: {
45
+ noInitialValue:
46
+ "`{{kind}} {{name}}` has no initial value and no `ref` assigns it, so every read before the first write gets `undefined`. Fix: give it its start value, `{{kind}} {{name}} = …;`: a real default, `= undefined` for an `Optional<T>` (`let timer: Optional<Timeout> = undefined;`) or `= null` for a `Maybe<T>`; or derive it with `const`. Only a variable a `ref` assigns may stay uninitialized (`let el!: HTMLDivElement;` with `ref={el}`). Do not: add `!` without a ref, or `= undefined` without an `Optional<T>` type (typebuddy/no-useless-undefined reports it)."
47
+ }
48
+ },
49
+ defaultOptions: [],
50
+ create(context) {
51
+ const refAssigned = new Set();
52
+ const uninitialized = [];
53
+
54
+ function markAssigned(identifier) {
55
+ const variable = findVariable(context, identifier);
56
+ if (variable) {
57
+ refAssigned.add(variable);
58
+ }
59
+ }
60
+
61
+ /** `(node) => { el = node; }`: every `x = node` in the callback. */
62
+ function markCallback(callback) {
63
+ const [param] = callback.params;
64
+ if (param?.type !== "Identifier") {
65
+ return;
66
+ }
67
+ walkOwnBody(callback.body, (node) => {
68
+ if (
69
+ node.type === "AssignmentExpression" &&
70
+ node.operator === "=" &&
71
+ node.left.type === "Identifier" &&
72
+ node.right.type === "Identifier" &&
73
+ node.right.name === param.name
74
+ ) {
75
+ markAssigned(node.left);
76
+ }
77
+ });
78
+ }
79
+
80
+ function markEntry(entry, inArray) {
81
+ const node = unwrapNonNull(entry);
82
+ if (node?.type === "Identifier") {
83
+ // In an array: never assigned, but prefer-ref-shorthand
84
+ // reports the entry, which is where the fix goes.
85
+ markAssigned(node);
86
+ } else if (node && isFunctionNode(node)) {
87
+ markCallback(node);
88
+ } else if (!inArray && node?.type === "ArrayExpression") {
89
+ for (const element of node.elements) {
90
+ markEntry(element, true);
91
+ }
92
+ }
93
+ }
94
+
95
+ return {
96
+ JSXAttribute(node) {
97
+ if (
98
+ jsxPropName(node) === "ref" &&
99
+ node.value?.type === "JSXExpressionContainer"
100
+ ) {
101
+ markEntry(node.value.expression, false);
102
+ }
103
+ },
104
+ VariableDeclaration(node) {
105
+ if (
106
+ (node.kind !== "let" && node.kind !== "var") ||
107
+ isLoopVariable(node) ||
108
+ isAmbient(node)
109
+ ) {
110
+ return;
111
+ }
112
+ for (const declarator of node.declarations) {
113
+ if (
114
+ declarator.init === null &&
115
+ declarator.id.type === "Identifier"
116
+ ) {
117
+ uninitialized.push(declarator);
118
+ }
119
+ }
120
+ },
121
+ "Program:exit"() {
122
+ for (const declarator of uninitialized) {
123
+ const variable = findVariable(context, declarator.id);
124
+ if (variable && refAssigned.has(variable)) {
125
+ continue;
126
+ }
127
+ context.report({
128
+ data: {
129
+ kind: declarator.parent.kind,
130
+ name: declarator.id.name
131
+ },
132
+ messageId: "noInitialValue",
133
+ node: declarator
134
+ });
135
+ }
136
+ }
137
+ };
138
+ }
139
+ };
@@ -1,10 +1,11 @@
1
- import { jsxGetAllProps } from "../utils.mjs";
1
+ import { getSourceCode } from "../compat.mjs";
2
+ import { jsxGetAllProps, messageCode } from "../utils.mjs";
2
3
  export default {
3
4
  meta: {
4
5
  type: "problem",
5
6
  docs: {
6
7
  description: "Disallow passing the same prop twice in JSX.",
7
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-no-duplicate-props.md",
8
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-no-duplicate-props.md"
8
9
  },
9
10
  schema: [
10
11
  {
@@ -14,19 +15,20 @@ export default {
14
15
  type: "boolean",
15
16
  description:
16
17
  "Consider two prop names differing only by case to be the same.",
17
- default: false,
18
- },
18
+ default: false
19
+ }
19
20
  },
20
- additionalProperties: false,
21
- },
21
+ additionalProperties: false
22
+ }
22
23
  ],
23
24
  messages: {
24
- noDuplicateProps: "Duplicate props are not allowed.",
25
+ noDuplicateProps:
26
+ "`{{name}}` is passed twice. The later value overwrites the earlier one, and as two JSX attributes TypeScript rejects it (TS17001). Fix: keep the one `{{name}}` you mean and delete the other.",
25
27
  noDuplicateClass:
26
- "Duplicate `class` props are not allowed; while it might seem to work, it can break unexpectedly. Pass one `class` with the object or array form instead.",
28
+ "`class` is passed twice. One value overwrites the other, and as two JSX attributes TypeScript rejects it (TS17001). Fix: one `class` with both values in the array form, `{{fix}}`.",
27
29
  noDuplicateChildren:
28
- "Using {{used}} at the same time is not allowed.",
29
- },
30
+ "{{used}} each set the element's content, so one replaces the other. Fix: keep one of them: JSX children for markup, `textContent` for plain text, `innerHTML` for trusted HTML."
31
+ }
30
32
  },
31
33
  defaultOptions: [],
32
34
  create(context) {
@@ -34,7 +36,24 @@ export default {
34
36
  JSXOpeningElement(node) {
35
37
  const ignoreCase = context.options[0]?.ignoreCase ?? false;
36
38
  const props = new Set();
39
+ // The first node of each name, for the merged `class` fix.
40
+ const firstNodes = new Map();
41
+ const sourceCode = getSourceCode(context);
42
+ // The value of the prop whose name is `nameNode`: an
43
+ // attribute's string or expression, or a spread property's.
44
+ const valueText = (nameNode) => {
45
+ const { value } = nameNode.parent;
46
+ if (!value) {
47
+ return "true";
48
+ }
49
+ return sourceCode.getText(
50
+ value.type === "JSXExpressionContainer"
51
+ ? value.expression
52
+ : value
53
+ );
54
+ };
37
55
  const checkPropName = (name, node) => {
56
+ const written = name;
38
57
  if (ignoreCase || name.startsWith("on")) {
39
58
  name = name
40
59
  .toLowerCase()
@@ -48,12 +67,21 @@ export default {
48
67
  name === "class"
49
68
  ? "noDuplicateClass"
50
69
  : "noDuplicateProps",
70
+ data: {
71
+ name: written,
72
+ fix: messageCode(
73
+ `class={[${valueText(firstNodes.get(name))}, ${valueText(node)}]}`,
74
+ 'class={["card", { active: active() }]}'
75
+ )
76
+ }
51
77
  });
78
+ } else {
79
+ firstNodes.set(name, node);
52
80
  }
53
81
  props.add(name);
54
82
  };
55
83
  for (const [name, propNode] of jsxGetAllProps(
56
- node.attributes,
84
+ node.attributes
57
85
  )) {
58
86
  checkPropName(name, propNode);
59
87
  }
@@ -64,21 +92,21 @@ export default {
64
92
  const hasTextContent =
65
93
  props.has("textContent") || props.has("textContent");
66
94
  const used = [
67
- hasChildrenProp && "`props.children`",
95
+ hasChildrenProp && "`children`",
68
96
  hasChildren && "JSX children",
69
- hasInnerHTML && "`props.innerHTML`",
70
- hasTextContent && "`props.textContent`",
97
+ hasInnerHTML && "`innerHTML`",
98
+ hasTextContent && "`textContent`"
71
99
  ].filter(Boolean);
72
100
  if (used.length > 1) {
73
101
  context.report({
74
102
  node,
75
103
  messageId: "noDuplicateChildren",
76
104
  data: {
77
- used: used.join(", "),
78
- },
105
+ used: used.join(", ")
106
+ }
79
107
  });
80
108
  }
81
- },
109
+ }
82
110
  };
83
- },
111
+ }
84
112
  };
@@ -14,14 +14,14 @@ export const jsxNoScriptUrlRule = {
14
14
  meta: {
15
15
  docs: {
16
16
  description: "Disallow javascript: URLs.",
17
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-no-script-url.md",
17
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-no-script-url.md"
18
18
  },
19
19
  messages: {
20
20
  noJSURL:
21
- "For security, don't use javascript: URLs. Use event handlers instead if you can.",
21
+ '`{{name}}` holds a `javascript:` URL, which runs its text as code when followed; text from input makes it a script injection (XSS). Fix: run the code in an event handler, `<button type="button" onClick={() => …}>`, and give a link a real `href`. Do not: assemble the URL at run time to get past this rule.'
22
22
  },
23
23
  schema: [],
24
- type: "problem",
24
+ type: "problem"
25
25
  },
26
26
  defaultOptions: [],
27
27
  create(context) {
@@ -37,7 +37,7 @@ export const jsxNoScriptUrlRule = {
37
37
  : node.value;
38
38
  const staticValue = getStaticValue(
39
39
  expression,
40
- getScope(context, node),
40
+ getScope(context, node)
41
41
  );
42
42
 
43
43
  if (
@@ -48,9 +48,10 @@ export const jsxNoScriptUrlRule = {
48
48
  context.report({
49
49
  messageId: "noJSURL",
50
50
  node: node.value,
51
+ data: { name: node.name.name }
51
52
  });
52
53
  }
53
- },
54
+ }
54
55
  };
55
- },
56
+ }
56
57
  };
@@ -1,10 +1,5 @@
1
1
  import { getScope, getSourceCode } from "../compat.mjs";
2
- import {
3
- isDOMElementName,
4
- formatList,
5
- appendImports,
6
- insertImports,
7
- } from "../utils.mjs";
2
+ import { isDOMElementName, appendImports, insertImports } from "../utils.mjs";
8
3
  // Currently all of the control flow components are from 'solid-js'.
9
4
  // Solid 2.0 dropped `Index` (use `<For keyed={false}>`) and renamed the
10
5
  // async/error boundaries. All of these are exported from `solid-js`.
@@ -16,7 +11,7 @@ const AUTO_COMPONENTS = [
16
11
  "Loading",
17
12
  "Errored",
18
13
  "Repeat",
19
- "Reveal",
14
+ "Reveal"
20
15
  ];
21
16
  const SOURCE_MODULE = "solid-js";
22
17
  export default {
@@ -25,7 +20,7 @@ export default {
25
20
  docs: {
26
21
  description:
27
22
  "Disallow references to undefined variables in JSX. Handles custom directives.",
28
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-no-undef.md",
23
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-no-undef.md"
29
24
  },
30
25
  fixable: "code",
31
26
  schema: [
@@ -36,30 +31,32 @@ export default {
36
31
  type: "boolean",
37
32
  description:
38
33
  "When true, the rule will consider the global scope when checking for defined components.",
39
- default: false,
34
+ default: false
40
35
  },
41
36
  autoImport: {
42
37
  type: "boolean",
43
38
  description:
44
39
  'Automatically import certain components from `"solid-js"` if they are undefined.',
45
- default: true,
40
+ default: true
46
41
  },
47
42
  typescriptEnabled: {
48
43
  type: "boolean",
49
44
  description:
50
45
  "Adjusts behavior not to conflict with TypeScript's type checking.",
51
- default: false,
52
- },
46
+ default: false
47
+ }
53
48
  },
54
- additionalProperties: false,
55
- },
49
+ additionalProperties: false
50
+ }
56
51
  ],
57
52
  messages: {
58
- undefined: "'{{identifier}}' is not defined.",
53
+ undefined:
54
+ "`{{identifier}}` is used in JSX but not defined in this module, so rendering it throws a ReferenceError. Fix: import `{{identifier}}` or fix its spelling.",
59
55
  customDirectiveUndefined:
60
- "Custom directive '{{identifier}}' is not defined.",
61
- autoImport: "{{imports}} should be imported from '{{source}}'.",
62
- },
56
+ "The directive `{{identifier}}` in `use:{{identifier}}` is not defined in this module, so applying it throws a ReferenceError. Fix: import `{{identifier}}` or fix its spelling.",
57
+ autoImport:
58
+ 'Used in JSX but not imported: `{{imports}}`. Rendering throws a ReferenceError. Fix: `import { {{imports}} } from "{{source}}";`, or add them to the existing `{{source}}` import.'
59
+ }
63
60
  },
64
61
  defaultOptions: [],
65
62
  create(context) {
@@ -76,7 +73,7 @@ export default {
76
73
  */
77
74
  function checkIdentifierInJSX(
78
75
  node,
79
- { isComponent, isCustomDirective } = {},
76
+ { isComponent, isCustomDirective } = {}
80
77
  ) {
81
78
  let scope = getScope(context, node);
82
79
  const sourceCode = getSourceCode(context);
@@ -101,7 +98,7 @@ export default {
101
98
  // Temporary fix for babel-eslint
102
99
  if (scope.childScopes[0].childScopes.length) {
103
100
  variables.push(
104
- ...scope.childScopes[0].childScopes[0].variables,
101
+ ...scope.childScopes[0].childScopes[0].variables
105
102
  );
106
103
  }
107
104
  }
@@ -121,16 +118,16 @@ export default {
121
118
  node,
122
119
  messageId: "customDirectiveUndefined",
123
120
  data: {
124
- identifier: node.name,
125
- },
121
+ identifier: node.name
122
+ }
126
123
  });
127
124
  } else if (!isTypeScriptEnabled) {
128
125
  context.report({
129
126
  node,
130
127
  messageId: "undefined",
131
128
  data: {
132
- identifier: node.name,
133
- },
129
+ identifier: node.name
130
+ }
134
131
  });
135
132
  }
136
133
  }
@@ -141,7 +138,7 @@ export default {
141
138
  case "JSXIdentifier":
142
139
  if (!isDOMElementName(node.name.name)) {
143
140
  checkIdentifierInJSX(node.name, {
144
- isComponent: true,
141
+ isComponent: true
145
142
  });
146
143
  }
147
144
  break;
@@ -166,14 +163,14 @@ export default {
166
163
  node.name?.type === "JSXIdentifier"
167
164
  ) {
168
165
  checkIdentifierInJSX(node.name, {
169
- isCustomDirective: true,
166
+ isCustomDirective: true
170
167
  });
171
168
  }
172
169
  },
173
170
  "Program:exit": (programNode) => {
174
171
  // add in any auto import components used in the program
175
172
  const missingComponents = Array.from(
176
- missingComponentsSet.values(),
173
+ missingComponentsSet.values()
177
174
  );
178
175
  if (autoImport && missingComponents.length) {
179
176
  const importNode = programNode.body.find(
@@ -181,32 +178,32 @@ export default {
181
178
  n.type === "ImportDeclaration" &&
182
179
  n.importKind !== "type" &&
183
180
  n.source.type === "Literal" &&
184
- n.source.value === SOURCE_MODULE,
181
+ n.source.value === SOURCE_MODULE
185
182
  );
186
183
  if (importNode) {
187
184
  context.report({
188
185
  node: importNode,
189
186
  messageId: "autoImport",
190
187
  data: {
191
- imports: formatList(missingComponents), // "Show, For, and Switch"
192
- source: SOURCE_MODULE,
188
+ imports: missingComponents.join(", "), // "Show, For, Switch"
189
+ source: SOURCE_MODULE
193
190
  },
194
191
  fix: (fixer) => {
195
192
  return appendImports(
196
193
  fixer,
197
194
  getSourceCode(context),
198
195
  importNode,
199
- missingComponents,
196
+ missingComponents
200
197
  );
201
- },
198
+ }
202
199
  });
203
200
  } else {
204
201
  context.report({
205
202
  node: programNode,
206
203
  messageId: "autoImport",
207
204
  data: {
208
- imports: formatList(missingComponents),
209
- source: SOURCE_MODULE,
205
+ imports: missingComponents.join(", "),
206
+ source: SOURCE_MODULE
210
207
  },
211
208
  fix: (fixer) => {
212
209
  // insert `import { missing, identifiers } from "solid-js"` at top of module
@@ -214,13 +211,13 @@ export default {
214
211
  fixer,
215
212
  getSourceCode(context),
216
213
  "solid-js",
217
- missingComponents,
214
+ missingComponents
218
215
  );
219
- },
216
+ }
220
217
  });
221
218
  }
222
219
  }
223
- },
220
+ }
224
221
  };
225
- },
222
+ }
226
223
  };
@@ -5,11 +5,11 @@ export const jsxUsesVarsRule = {
5
5
  docs: {
6
6
  description:
7
7
  "Prevent variables used in JSX from being marked as unused.",
8
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-uses-vars.md",
8
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/jsx-uses-vars.md"
9
9
  },
10
10
  messages: {},
11
11
  schema: [],
12
- type: "problem",
12
+ type: "problem"
13
13
  },
14
14
  defaultOptions: [],
15
15
  create(context) {
@@ -45,7 +45,7 @@ export const jsxUsesVarsRule = {
45
45
  ) {
46
46
  markVariableAsUsed(context, node.name.name, node.name);
47
47
  }
48
- },
48
+ }
49
49
  };
50
- },
50
+ }
51
51
  };
@@ -1,17 +1,18 @@
1
- import { isDOMElementName, trace } from "../utils.mjs";
1
+ import { getSourceCode } from "../compat.mjs";
2
+ import { isDOMElementName, messageCode, trace } from "../utils.mjs";
2
3
 
3
4
  export const noArrayHandlersRule = {
4
5
  meta: {
5
6
  docs: {
6
7
  description: "Disallow usage of type-unsafe event handlers.",
7
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-array-handlers.md",
8
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/no-array-handlers.md"
8
9
  },
9
10
  messages: {
10
11
  noArrayHandlers:
11
- "Passing an array as an event handler is potentially type-unsafe.",
12
+ "`{{name}}` gets the array `{{expression}}`. Solid calls `handler(data, event)` for `[handler, data]`, but the JSX types take `data` as `any`, so a wrong argument passes the type check. Fix: `{{name}}={{{fix}}}`."
12
13
  },
13
14
  schema: [],
14
- type: "problem",
15
+ type: "problem"
15
16
  },
16
17
  defaultOptions: [],
17
18
  create(context) {
@@ -32,18 +33,46 @@ export const noArrayHandlersRule = {
32
33
  node.name.type === "JSXIdentifier" &&
33
34
  /^on[a-zA-Z]/.test(node.name.name);
34
35
 
36
+ const traced =
37
+ node.value?.type === "JSXExpressionContainer"
38
+ ? trace(node.value.expression, context)
39
+ : null;
35
40
  if (
36
41
  (isNamespacedHandler || isNormalEventHandler) &&
37
- node.value?.type === "JSXExpressionContainer" &&
38
- trace(node.value.expression, context).type ===
39
- "ArrayExpression"
42
+ traced?.type === "ArrayExpression"
40
43
  ) {
44
+ const sourceCode = getSourceCode(context);
45
+ const [handler, data] = traced.elements.map(
46
+ (element, index) => {
47
+ if (!element || element.type === "SpreadElement") {
48
+ return null;
49
+ }
50
+ const text = sourceCode.getText(element);
51
+ // An inline function is called as `(fn)(...)`.
52
+ return index === 0 &&
53
+ element.type !== "Identifier" &&
54
+ element.type !== "MemberExpression"
55
+ ? `(${text})`
56
+ : text;
57
+ }
58
+ );
41
59
  context.report({
42
60
  messageId: "noArrayHandlers",
43
61
  node,
62
+ data: {
63
+ name: sourceCode.getText(node.name),
64
+ expression: messageCode(
65
+ sourceCode.getText(node.value.expression),
66
+ "[handler, data]"
67
+ ),
68
+ fix: messageCode(
69
+ `(event) => ${handler ?? "handler"}(${data ?? "data"}, event)`,
70
+ "(event) => handler(data, event)"
71
+ )
72
+ }
44
73
  });
45
74
  }
46
- },
75
+ }
47
76
  };
48
- },
77
+ }
49
78
  };