eslint-plugin-react-features 1.1.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 (114) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/LICENSE +23 -0
  3. package/README.md +155 -0
  4. package/package.json +65 -0
  5. package/src/index.d.ts +1093 -0
  6. package/src/index.js +212 -0
  7. package/src/rules/migration/react-class-to-hooks.d.ts +22 -0
  8. package/src/rules/migration/react-class-to-hooks.js +178 -0
  9. package/src/rules/performance/no-unnecessary-rerenders.d.ts +26 -0
  10. package/src/rules/performance/no-unnecessary-rerenders.js +212 -0
  11. package/src/rules/performance/react-no-inline-functions.d.ts +24 -0
  12. package/src/rules/performance/react-no-inline-functions.js +211 -0
  13. package/src/rules/performance/react-render-optimization.d.ts +31 -0
  14. package/src/rules/performance/react-render-optimization.js +294 -0
  15. package/src/rules/react/checked-requires-onchange-or-readonly.d.ts +16 -0
  16. package/src/rules/react/checked-requires-onchange-or-readonly.js +74 -0
  17. package/src/rules/react/default-props-match-prop-types.d.ts +13 -0
  18. package/src/rules/react/default-props-match-prop-types.js +119 -0
  19. package/src/rules/react/display-name.d.ts +13 -0
  20. package/src/rules/react/display-name.js +164 -0
  21. package/src/rules/react/hooks-exhaustive-deps.d.ts +25 -0
  22. package/src/rules/react/hooks-exhaustive-deps.js +466 -0
  23. package/src/rules/react/jsx-handler-names.d.ts +13 -0
  24. package/src/rules/react/jsx-handler-names.js +57 -0
  25. package/src/rules/react/jsx-key.d.ts +20 -0
  26. package/src/rules/react/jsx-key.js +421 -0
  27. package/src/rules/react/jsx-max-depth.d.ts +19 -0
  28. package/src/rules/react/jsx-max-depth.js +80 -0
  29. package/src/rules/react/jsx-no-bind.d.ts +13 -0
  30. package/src/rules/react/jsx-no-bind.js +64 -0
  31. package/src/rules/react/jsx-no-duplicate-props.d.ts +21 -0
  32. package/src/rules/react/jsx-no-duplicate-props.js +70 -0
  33. package/src/rules/react/jsx-no-literals.d.ts +20 -0
  34. package/src/rules/react/jsx-no-literals.js +83 -0
  35. package/src/rules/react/jsx-no-script-url.d.ts +25 -0
  36. package/src/rules/react/jsx-no-script-url.js +131 -0
  37. package/src/rules/react/jsx-no-target-blank.d.ts +26 -0
  38. package/src/rules/react/jsx-no-target-blank.js +176 -0
  39. package/src/rules/react/no-access-state-in-setstate.d.ts +13 -0
  40. package/src/rules/react/no-access-state-in-setstate.js +92 -0
  41. package/src/rules/react/no-adjacent-inline-elements.d.ts +13 -0
  42. package/src/rules/react/no-adjacent-inline-elements.js +81 -0
  43. package/src/rules/react/no-arrow-function-lifecycle.d.ts +13 -0
  44. package/src/rules/react/no-arrow-function-lifecycle.js +63 -0
  45. package/src/rules/react/no-children-prop.d.ts +13 -0
  46. package/src/rules/react/no-children-prop.js +60 -0
  47. package/src/rules/react/no-danger-with-children.d.ts +16 -0
  48. package/src/rules/react/no-danger-with-children.js +110 -0
  49. package/src/rules/react/no-danger.d.ts +13 -0
  50. package/src/rules/react/no-danger.js +45 -0
  51. package/src/rules/react/no-deprecated.d.ts +16 -0
  52. package/src/rules/react/no-deprecated.js +140 -0
  53. package/src/rules/react/no-did-mount-set-state.d.ts +13 -0
  54. package/src/rules/react/no-did-mount-set-state.js +55 -0
  55. package/src/rules/react/no-did-update-set-state.d.ts +19 -0
  56. package/src/rules/react/no-did-update-set-state.js +80 -0
  57. package/src/rules/react/no-direct-mutation-state.d.ts +20 -0
  58. package/src/rules/react/no-direct-mutation-state.js +277 -0
  59. package/src/rules/react/no-find-dom-node.d.ts +15 -0
  60. package/src/rules/react/no-find-dom-node.js +56 -0
  61. package/src/rules/react/no-invalid-html-attribute.d.ts +13 -0
  62. package/src/rules/react/no-invalid-html-attribute.js +84 -0
  63. package/src/rules/react/no-is-mounted.d.ts +13 -0
  64. package/src/rules/react/no-is-mounted.js +52 -0
  65. package/src/rules/react/no-multi-comp.d.ts +18 -0
  66. package/src/rules/react/no-multi-comp.js +160 -0
  67. package/src/rules/react/no-namespace.d.ts +13 -0
  68. package/src/rules/react/no-namespace.js +41 -0
  69. package/src/rules/react/no-object-type-as-default-prop.d.ts +13 -0
  70. package/src/rules/react/no-object-type-as-default-prop.js +61 -0
  71. package/src/rules/react/no-redundant-should-component-update.d.ts +13 -0
  72. package/src/rules/react/no-redundant-should-component-update.js +55 -0
  73. package/src/rules/react/no-render-return-value.d.ts +13 -0
  74. package/src/rules/react/no-render-return-value.js +74 -0
  75. package/src/rules/react/no-set-state.d.ts +13 -0
  76. package/src/rules/react/no-set-state.js +50 -0
  77. package/src/rules/react/no-string-refs.d.ts +13 -0
  78. package/src/rules/react/no-string-refs.js +68 -0
  79. package/src/rules/react/no-this-in-sfc.d.ts +13 -0
  80. package/src/rules/react/no-this-in-sfc.js +65 -0
  81. package/src/rules/react/no-typos.d.ts +13 -0
  82. package/src/rules/react/no-typos.js +97 -0
  83. package/src/rules/react/no-unescaped-entities.d.ts +13 -0
  84. package/src/rules/react/no-unescaped-entities.js +50 -0
  85. package/src/rules/react/no-unknown-property.d.ts +13 -0
  86. package/src/rules/react/no-unknown-property.js +130 -0
  87. package/src/rules/react/no-unsafe.d.ts +20 -0
  88. package/src/rules/react/no-unsafe.js +112 -0
  89. package/src/rules/react/prefer-es6-class.d.ts +13 -0
  90. package/src/rules/react/prefer-es6-class.js +56 -0
  91. package/src/rules/react/prefer-stateless-function.d.ts +16 -0
  92. package/src/rules/react/prefer-stateless-function.js +134 -0
  93. package/src/rules/react/prop-types.d.ts +18 -0
  94. package/src/rules/react/prop-types.js +153 -0
  95. package/src/rules/react/react-in-jsx-scope.d.ts +13 -0
  96. package/src/rules/react/react-in-jsx-scope.js +94 -0
  97. package/src/rules/react/require-default-props.d.ts +16 -0
  98. package/src/rules/react/require-default-props.js +146 -0
  99. package/src/rules/react/require-optimization.d.ts +26 -0
  100. package/src/rules/react/require-optimization.js +436 -0
  101. package/src/rules/react/require-render-return.d.ts +13 -0
  102. package/src/rules/react/require-render-return.js +87 -0
  103. package/src/rules/react/required-attributes.d.ts +28 -0
  104. package/src/rules/react/required-attributes.js +212 -0
  105. package/src/rules/react/sort-comp.d.ts +17 -0
  106. package/src/rules/react/sort-comp.js +160 -0
  107. package/src/rules/react/state-in-constructor.d.ts +13 -0
  108. package/src/rules/react/state-in-constructor.js +103 -0
  109. package/src/rules/react/static-property-placement.d.ts +20 -0
  110. package/src/rules/react/static-property-placement.js +166 -0
  111. package/src/rules/react/void-dom-elements-no-children.d.ts +15 -0
  112. package/src/rules/react/void-dom-elements-no-children.js +94 -0
  113. package/src/types/index.d.ts +54 -0
  114. package/src/types/index.js +7 -0
@@ -0,0 +1,466 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Ofri Peretz
4
+ * Licensed under the MIT License. Use of this source code is governed by the
5
+ * MIT license that can be found in the LICENSE file.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.hooksExhaustiveDeps = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ // Hook names that require dependency array checking
12
+ const HOOKS_WITH_DEPS = [
13
+ 'useEffect',
14
+ 'useLayoutEffect',
15
+ 'useCallback',
16
+ 'useMemo',
17
+ 'useImperativeHandle',
18
+ ];
19
+ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
20
+ name: 'hooks-exhaustive-deps',
21
+ meta: {
22
+ type: 'problem',
23
+ docs: {
24
+ description: 'Enforce exhaustive dependencies in React hooks to prevent stale closures',
25
+ },
26
+ hasSuggestions: true,
27
+ messages: {
28
+ missingDep: (0, eslint_devkit_2.formatLLMMessage)({
29
+ icon: eslint_devkit_2.MessageIcons.WARNING,
30
+ issueName: 'Missing Hook Dependency',
31
+ description: 'React Hook {{hookName}} has missing dependencies: {{deps}}',
32
+ severity: 'HIGH',
33
+ fix: 'Add missing dependencies to the dependency array or memoize values with useMemo/useCallback',
34
+ documentationLink: 'https://react.dev/reference/react/useEffect#specifying-reactive-dependencies',
35
+ }),
36
+ extraDep: (0, eslint_devkit_2.formatLLMMessage)({
37
+ icon: eslint_devkit_2.MessageIcons.WARNING,
38
+ issueName: 'Unnecessary Hook Dependency',
39
+ description: 'React Hook {{hookName}} has unnecessary dependency: {{dep}}',
40
+ severity: 'MEDIUM',
41
+ fix: 'Remove the unnecessary dependency from the array - it never changes or is not used in the effect',
42
+ documentationLink: 'https://react.dev/reference/react/useEffect#removing-unnecessary-dependencies',
43
+ }),
44
+ unnecessaryDep: (0, eslint_devkit_2.formatLLMMessage)({
45
+ icon: eslint_devkit_2.MessageIcons.INFO,
46
+ issueName: 'Unnecessary Dependency',
47
+ description: 'The dependency {{dep}} is stable and never changes',
48
+ severity: 'LOW',
49
+ fix: 'Consider removing stable dependencies like setState functions or refs',
50
+ documentationLink: 'https://react.dev/reference/react/useEffect#removing-unnecessary-dependencies',
51
+ }),
52
+ suggestAddDep: (0, eslint_devkit_2.formatLLMMessage)({
53
+ icon: eslint_devkit_2.MessageIcons.INFO,
54
+ issueName: 'Add Missing Dependency',
55
+ description: 'Add {{dep}} to dependency array',
56
+ severity: 'LOW',
57
+ fix: 'Add the missing dependency to prevent stale closures',
58
+ documentationLink: 'https://react.dev/reference/react/useEffect#specifying-reactive-dependencies',
59
+ }),
60
+ suggestRemoveDep: (0, eslint_devkit_2.formatLLMMessage)({
61
+ icon: eslint_devkit_2.MessageIcons.INFO,
62
+ issueName: 'Remove Unnecessary Dependency',
63
+ description: 'Remove {{dep}} from dependency array',
64
+ severity: 'LOW',
65
+ fix: 'Remove the unnecessary dependency',
66
+ documentationLink: 'https://react.dev/reference/react/useEffect#removing-unnecessary-dependencies',
67
+ }),
68
+ },
69
+ schema: [
70
+ {
71
+ type: 'object',
72
+ properties: {
73
+ additionalHooks: {
74
+ type: 'string',
75
+ description: 'Regex pattern for additional hooks to check (e.g., "useMyCustomHook")',
76
+ },
77
+ enableDangerousAutofixThisMayCauseInfiniteLoops: {
78
+ type: 'boolean',
79
+ default: false,
80
+ description: 'Enable autofix (warning: may cause infinite loops)',
81
+ },
82
+ },
83
+ additionalProperties: false,
84
+ },
85
+ ],
86
+ },
87
+ defaultOptions: [{}],
88
+ create(context) {
89
+ const options = context.options[0] || {};
90
+ const additionalHooksPattern = options.additionalHooks
91
+ ? new RegExp(options.additionalHooks)
92
+ : null;
93
+ /**
94
+ * Check if a call expression is a React hook with dependencies
95
+ */
96
+ function isHookWithDeps(node) {
97
+ const callee = node.callee;
98
+ // Direct hook call: useEffect(...)
99
+ if (callee.type === 'Identifier') {
100
+ if (HOOKS_WITH_DEPS.includes(callee.name)) {
101
+ return true;
102
+ }
103
+ if (additionalHooksPattern?.test(callee.name)) {
104
+ return true;
105
+ }
106
+ }
107
+ // Namespaced hook call: React.useEffect(...)
108
+ if (callee.type === 'MemberExpression' &&
109
+ callee.object.type === 'Identifier' &&
110
+ callee.object.name === 'React' &&
111
+ callee.property.type === 'Identifier' &&
112
+ HOOKS_WITH_DEPS.includes(callee.property.name)) {
113
+ return true;
114
+ }
115
+ return false;
116
+ }
117
+ /**
118
+ * Get the hook name from a call expression
119
+ */
120
+ function getHookName(node) {
121
+ const callee = node.callee;
122
+ if (callee.type === 'Identifier') {
123
+ return callee.name;
124
+ }
125
+ if (callee.type === 'MemberExpression' &&
126
+ callee.property.type === 'Identifier') {
127
+ return callee.property.name;
128
+ }
129
+ return 'unknown';
130
+ }
131
+ /**
132
+ * Extract variables declared inside a function (to exclude from deps)
133
+ */
134
+ function extractLocallyDeclaredIdentifiers(node) {
135
+ const declared = new Set();
136
+ const visited = new WeakSet();
137
+ const skipKeys = new Set(['parent', 'loc', 'range', 'tokens', 'comments']);
138
+ function visit(n) {
139
+ if (visited.has(n))
140
+ return;
141
+ visited.add(n);
142
+ // Variable declarations: const x = 1, let y, var z
143
+ if (n.type === 'VariableDeclaration') {
144
+ for (const declarator of n.declarations) {
145
+ if (declarator.id.type === 'Identifier') {
146
+ declared.add(declarator.id.name);
147
+ }
148
+ else if (declarator.id.type === 'ObjectPattern') {
149
+ // Destructuring: const { a, b } = obj
150
+ for (const prop of declarator.id.properties) {
151
+ if (prop.type === 'Property' && prop.value.type === 'Identifier') {
152
+ declared.add(prop.value.name);
153
+ }
154
+ }
155
+ }
156
+ else if (declarator.id.type === 'ArrayPattern') {
157
+ // Array destructuring: const [a, b] = arr
158
+ for (const element of declarator.id.elements) {
159
+ if (element && element.type === 'Identifier') {
160
+ declared.add(element.name);
161
+ }
162
+ }
163
+ }
164
+ }
165
+ }
166
+ // Function parameters and declarations
167
+ if (n.type === 'FunctionDeclaration' && n.id) {
168
+ declared.add(n.id.name);
169
+ }
170
+ // Traverse children
171
+ for (const key of Object.keys(n)) {
172
+ if (skipKeys.has(key))
173
+ continue;
174
+ const child = n[key];
175
+ if (child && typeof child === 'object') {
176
+ if (Array.isArray(child)) {
177
+ child.forEach((c) => {
178
+ if (c && typeof c === 'object' && 'type' in c) {
179
+ visit(c);
180
+ }
181
+ });
182
+ }
183
+ else if ('type' in child) {
184
+ visit(child);
185
+ }
186
+ }
187
+ }
188
+ }
189
+ visit(node);
190
+ return declared;
191
+ }
192
+ /**
193
+ * Extract identifiers used inside a function node (only standalone identifiers, not property names)
194
+ */
195
+ function extractUsedIdentifiers(node) {
196
+ const used = new Set();
197
+ const visited = new WeakSet();
198
+ // Keys to skip during traversal (to avoid infinite loops)
199
+ const skipKeys = new Set(['parent', 'loc', 'range', 'tokens', 'comments']);
200
+ function visit(n, isPropertyKey = false) {
201
+ // Prevent infinite loops
202
+ if (visited.has(n)) {
203
+ return;
204
+ }
205
+ visited.add(n);
206
+ // For MemberExpression, only capture the object (root), not the property
207
+ if (n.type === 'MemberExpression') {
208
+ visit(n.object, false);
209
+ // Don't visit computed properties as property keys
210
+ if (n.computed && n.property) {
211
+ visit(n.property, false);
212
+ }
213
+ // Non-computed properties are just property names, skip them
214
+ return;
215
+ }
216
+ // For CallExpression, capture callee and arguments
217
+ if (n.type === 'CallExpression') {
218
+ if (n.callee) {
219
+ visit(n.callee, false);
220
+ }
221
+ if (n.arguments) {
222
+ n.arguments.forEach((arg) => visit(arg, false));
223
+ }
224
+ return;
225
+ }
226
+ // Only add identifiers that aren't property keys
227
+ if (n.type === 'Identifier' && !isPropertyKey) {
228
+ used.add(n.name);
229
+ }
230
+ // Traverse child nodes
231
+ for (const key of Object.keys(n)) {
232
+ // Skip parent and metadata to avoid circular references
233
+ if (skipKeys.has(key)) {
234
+ continue;
235
+ }
236
+ const child = n[key];
237
+ if (child && typeof child === 'object') {
238
+ if (Array.isArray(child)) {
239
+ child.forEach((c) => {
240
+ if (c && typeof c === 'object' && 'type' in c) {
241
+ visit(c, false);
242
+ }
243
+ });
244
+ }
245
+ else if ('type' in child) {
246
+ visit(child, false);
247
+ }
248
+ }
249
+ }
250
+ }
251
+ visit(node);
252
+ return used;
253
+ }
254
+ /**
255
+ * Extract dependencies from the dependency array
256
+ */
257
+ function extractDependencies(depsArray) {
258
+ const deps = new Set();
259
+ for (const element of depsArray.elements) {
260
+ if (element?.type === 'Identifier') {
261
+ deps.add(element.name);
262
+ }
263
+ else if (element?.type === 'MemberExpression' &&
264
+ element.object.type === 'Identifier') {
265
+ // For props.foo, we track the full path
266
+ const sourceCode = context.sourceCode || context.getSourceCode();
267
+ deps.add(sourceCode.getText(element));
268
+ }
269
+ }
270
+ return deps;
271
+ }
272
+ /**
273
+ * Check if an identifier is a stable React reference
274
+ */
275
+ function isStableReference(name) {
276
+ // setState functions from useState are stable
277
+ // dispatch from useReducer is stable
278
+ // refs from useRef are stable
279
+ const stablePatterns = [
280
+ /^set[A-Z]/, // setState patterns
281
+ /dispatch/i,
282
+ /Ref$/,
283
+ ];
284
+ return stablePatterns.some((pattern) => pattern.test(name));
285
+ }
286
+ /**
287
+ * Filter out stable references and non-reactive values
288
+ */
289
+ function filterReactiveDeps(used) {
290
+ const reactive = new Set();
291
+ // Common non-reactive values
292
+ const nonReactive = new Set([
293
+ 'undefined',
294
+ 'null',
295
+ 'true',
296
+ 'false',
297
+ 'console',
298
+ 'window',
299
+ 'document',
300
+ 'Math',
301
+ 'JSON',
302
+ 'Object',
303
+ 'Array',
304
+ 'String',
305
+ 'Number',
306
+ 'Boolean',
307
+ 'Date',
308
+ 'Promise',
309
+ 'Error',
310
+ 'Map',
311
+ 'Set',
312
+ 'WeakMap',
313
+ 'WeakSet',
314
+ 'Symbol',
315
+ 'Reflect',
316
+ 'Proxy',
317
+ 'Intl',
318
+ 'navigator',
319
+ 'localStorage',
320
+ 'sessionStorage',
321
+ 'fetch',
322
+ 'setTimeout',
323
+ 'setInterval',
324
+ 'clearTimeout',
325
+ 'clearInterval',
326
+ 'requestAnimationFrame',
327
+ 'cancelAnimationFrame',
328
+ ]);
329
+ for (const name of used) {
330
+ if (!nonReactive.has(name) && !isStableReference(name)) {
331
+ reactive.add(name);
332
+ }
333
+ }
334
+ return reactive;
335
+ }
336
+ return {
337
+ CallExpression(node) {
338
+ if (!isHookWithDeps(node)) {
339
+ return;
340
+ }
341
+ const hookName = getHookName(node);
342
+ const args = node.arguments;
343
+ // Check if hook has a callback argument
344
+ if (args.length === 0) {
345
+ return;
346
+ }
347
+ const callback = args[0];
348
+ if (callback.type !== 'ArrowFunctionExpression' &&
349
+ callback.type !== 'FunctionExpression') {
350
+ return;
351
+ }
352
+ // Get the dependency array (second argument)
353
+ const depsArg = args[1];
354
+ // If no deps array provided, don't warn (different rule)
355
+ if (!depsArg) {
356
+ return;
357
+ }
358
+ if (depsArg.type !== 'ArrayExpression') {
359
+ return;
360
+ }
361
+ // Extract used identifiers from callback
362
+ const usedInCallback = extractUsedIdentifiers(callback.body);
363
+ // Extract locally declared identifiers (should not be dependencies)
364
+ const locallyDeclared = extractLocallyDeclaredIdentifiers(callback.body);
365
+ // Filter out locally declared vars before checking reactive deps
366
+ const externalUsed = new Set();
367
+ for (const id of usedInCallback) {
368
+ if (!locallyDeclared.has(id)) {
369
+ externalUsed.add(id);
370
+ }
371
+ }
372
+ const reactiveDeps = filterReactiveDeps(externalUsed);
373
+ // Extract declared dependencies
374
+ const declaredDeps = extractDependencies(depsArg);
375
+ // Find missing dependencies
376
+ const missingDeps = [];
377
+ for (const dep of reactiveDeps) {
378
+ // Simple check - skip if it looks like a local variable or function
379
+ // This is a simplified heuristic
380
+ if (!declaredDeps.has(dep) && /^[a-z]/.test(dep)) {
381
+ missingDeps.push(dep);
382
+ }
383
+ }
384
+ // Find extra/unnecessary dependencies
385
+ const extraDeps = [];
386
+ for (const dep of declaredDeps) {
387
+ if (!usedInCallback.has(dep) && !dep.includes('.')) {
388
+ extraDeps.push(dep);
389
+ }
390
+ }
391
+ // Report missing dependencies
392
+ if (missingDeps.length > 0) {
393
+ context.report({
394
+ node: depsArg,
395
+ messageId: 'missingDep',
396
+ data: {
397
+ hookName,
398
+ deps: missingDeps.join(', '),
399
+ },
400
+ suggest: missingDeps.map((dep) => ({
401
+ messageId: 'suggestAddDep',
402
+ data: { dep },
403
+ fix(fixer) {
404
+ const lastElement = depsArg.elements[depsArg.elements.length - 1];
405
+ if (lastElement) {
406
+ return fixer.insertTextAfter(lastElement, `, ${dep}`);
407
+ }
408
+ else {
409
+ // Empty array
410
+ return fixer.insertTextAfterRange([depsArg.range[0] + 1, depsArg.range[0] + 1], dep);
411
+ }
412
+ },
413
+ })),
414
+ });
415
+ }
416
+ // Report extra dependencies
417
+ for (const dep of extraDeps) {
418
+ context.report({
419
+ node: depsArg,
420
+ messageId: 'extraDep',
421
+ data: {
422
+ hookName,
423
+ dep,
424
+ },
425
+ suggest: [
426
+ {
427
+ messageId: 'suggestRemoveDep',
428
+ data: { dep },
429
+ fix(fixer) {
430
+ const element = depsArg.elements.find((el) => el?.type === 'Identifier' && el.name === dep);
431
+ if (element) {
432
+ const index = depsArg.elements.indexOf(element);
433
+ const isLast = index === depsArg.elements.length - 1;
434
+ const isFirst = index === 0;
435
+ if (isFirst && depsArg.elements.length > 1) {
436
+ // Remove first element and following comma
437
+ const nextElement = depsArg.elements[1];
438
+ if (nextElement) {
439
+ return fixer.removeRange([
440
+ element.range[0],
441
+ nextElement.range[0],
442
+ ]);
443
+ }
444
+ }
445
+ else if (isLast && index > 0) {
446
+ // Remove last element and preceding comma
447
+ const prevElement = depsArg.elements[index - 1];
448
+ if (prevElement) {
449
+ return fixer.removeRange([
450
+ prevElement.range[1],
451
+ element.range[1],
452
+ ]);
453
+ }
454
+ }
455
+ return fixer.remove(element);
456
+ }
457
+ return null;
458
+ },
459
+ },
460
+ ],
461
+ });
462
+ }
463
+ },
464
+ };
465
+ },
466
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: jsx-handler-names
8
+ * Enforce event handler naming conventions
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ export declare const jsxHandlerNames: TSESLint.RuleModule<"jsxHandlerNames", [], unknown, TSESLint.RuleListener> & {
12
+ name: string;
13
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2025 Ofri Peretz
4
+ * Licensed under the MIT License. Use of this source code is governed by the
5
+ * MIT license that can be found in the LICENSE file.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.jsxHandlerNames = void 0;
9
+ const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
+ const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
+ exports.jsxHandlerNames = (0, eslint_devkit_1.createRule)({
12
+ name: 'jsx-handler-names',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Enforce event handler naming conventions',
17
+ },
18
+ schema: [],
19
+ messages: {
20
+ jsxHandlerNames: (0, eslint_devkit_2.formatLLMMessage)({
21
+ icon: eslint_devkit_2.MessageIcons.WARNING,
22
+ issueName: 'Invalid Handler Name',
23
+ description: 'Event handler does not follow naming convention',
24
+ severity: 'LOW',
25
+ fix: 'Rename handler to start with "handle" or "on" (e.g., handleClick, onSubmit)',
26
+ documentationLink: 'https://react.dev/learn/responding-to-events#naming-event-handler-functions',
27
+ }),
28
+ },
29
+ },
30
+ defaultOptions: [],
31
+ create(context) {
32
+ return {
33
+ JSXAttribute(node) {
34
+ if (node.name.type === 'JSXIdentifier') {
35
+ const attrName = node.name.name;
36
+ // Check if this is an event handler (starts with 'on')
37
+ if (attrName.startsWith('on') && attrName.length > 2) {
38
+ // Check if the value is an identifier (function reference)
39
+ if (node.value && node.value.type === 'JSXExpressionContainer') {
40
+ const expression = node.value.expression;
41
+ if (expression.type === 'Identifier') {
42
+ const handlerName = expression.name;
43
+ // Check naming convention: should start with 'handle' or 'on'
44
+ if (!handlerName.startsWith('handle') && !handlerName.startsWith('on')) {
45
+ context.report({
46
+ node: expression,
47
+ messageId: 'jsxHandlerNames',
48
+ });
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ },
55
+ };
56
+ },
57
+ });
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * ESLint Rule: jsx-key
8
+ * Detect missing or incorrect React keys (requires deep reconciliation understanding)
9
+ */
10
+ import type { TSESLint } from '@interlace/eslint-devkit';
11
+ type MessageIds = 'missingKey' | 'invalidKey' | 'duplicateKey' | 'unstableKey' | 'suggestKey';
12
+ export interface Options {
13
+ /** Warn about potentially unstable keys */
14
+ warnUnstableKeys?: boolean;
15
+ }
16
+ type RuleOptions = [Options?];
17
+ export declare const jsxKey: TSESLint.RuleModule<MessageIds, RuleOptions, unknown, TSESLint.RuleListener> & {
18
+ name: string;
19
+ };
20
+ export {};