eslint-plugin-react-features 1.2.4 → 1.2.6

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 (129) hide show
  1. package/package.json +21 -19
  2. package/src/index.d.ts +15 -2074
  3. package/src/index.js +1 -36
  4. package/src/oxlint.d.ts +17 -20
  5. package/src/oxlint.js +0 -18
  6. package/src/rules/component-api/no-arbitrary-token-class.js +0 -11
  7. package/src/rules/component-api/no-default-test-id.js +0 -7
  8. package/src/rules/component-api/no-inline-style.js +0 -6
  9. package/src/rules/component-api/no-is-prefix-prop.js +0 -7
  10. package/src/rules/component-api/no-kind-prop-discriminator.js +0 -5
  11. package/src/rules/component-api/no-raw-color-literal.js +0 -8
  12. package/src/rules/component-api/no-wrapper-sub-component.js +0 -8
  13. package/src/rules/component-api/require-data-slot.js +0 -5
  14. package/src/rules/migration/react-class-to-hooks.js +1 -26
  15. package/src/rules/performance/no-unnecessary-rerenders.js +1 -32
  16. package/src/rules/performance/react-no-inline-functions.js +2 -29
  17. package/src/rules/performance/react-render-optimization.js +1 -40
  18. package/src/rules/react/checked-requires-onchange-or-readonly.js +0 -7
  19. package/src/rules/react/default-props-match-prop-types.js +2 -23
  20. package/src/rules/react/display-name.js +1 -33
  21. package/src/rules/react/hooks-exhaustive-deps.js +1 -90
  22. package/src/rules/react/jsx-handler-names.js +0 -8
  23. package/src/rules/react/jsx-key.js +0 -84
  24. package/src/rules/react/jsx-max-depth.js +0 -10
  25. package/src/rules/react/jsx-no-bind.js +0 -10
  26. package/src/rules/react/jsx-no-duplicate-props.js +0 -5
  27. package/src/rules/react/jsx-no-literals.js +0 -5
  28. package/src/rules/react/jsx-no-script-url.js +0 -16
  29. package/src/rules/react/jsx-no-target-blank.js +1 -20
  30. package/src/rules/react/no-access-state-in-setstate.js +0 -13
  31. package/src/rules/react/no-adjacent-inline-elements.js +0 -10
  32. package/src/rules/react/no-arrow-function-lifecycle.js +0 -7
  33. package/src/rules/react/no-children-prop.js +0 -7
  34. package/src/rules/react/no-danger-with-children.js +0 -13
  35. package/src/rules/react/no-danger.js +0 -5
  36. package/src/rules/react/no-deprecated.js +0 -11
  37. package/src/rules/react/no-did-mount-set-state.js +0 -6
  38. package/src/rules/react/no-did-update-set-state.js +0 -10
  39. package/src/rules/react/no-direct-mutation-state.js +3 -29
  40. package/src/rules/react/no-find-dom-node.js +0 -7
  41. package/src/rules/react/no-invalid-html-attribute.js +36 -41
  42. package/src/rules/react/no-is-mounted.js +0 -7
  43. package/src/rules/react/no-multi-comp.js +0 -14
  44. package/src/rules/react/no-namespace.js +0 -5
  45. package/src/rules/react/no-object-type-as-default-prop.js +0 -9
  46. package/src/rules/react/no-redundant-should-component-update.js +0 -6
  47. package/src/rules/react/no-render-return-value.js +1 -9
  48. package/src/rules/react/no-set-state.js +0 -6
  49. package/src/rules/react/no-string-refs.js +0 -8
  50. package/src/rules/react/no-this-in-sfc.js +0 -11
  51. package/src/rules/react/no-typos.js +1 -9
  52. package/src/rules/react/no-unescaped-entities.js +0 -7
  53. package/src/rules/react/no-unknown-property.js +0 -13
  54. package/src/rules/react/no-unsafe.js +0 -7
  55. package/src/rules/react/prefer-es6-class.js +0 -7
  56. package/src/rules/react/prefer-stateless-function.js +0 -13
  57. package/src/rules/react/prop-types.js +0 -12
  58. package/src/rules/react/react-in-jsx-scope.js +0 -9
  59. package/src/rules/react/require-default-props.js +0 -19
  60. package/src/rules/react/require-optimization.js +6 -44
  61. package/src/rules/react/require-render-return.js +0 -9
  62. package/src/rules/react/required-attributes.js +0 -34
  63. package/src/rules/react/sort-comp.js +1 -19
  64. package/src/rules/react/state-in-constructor.js +0 -11
  65. package/src/rules/react/static-property-placement.js +1 -21
  66. package/src/rules/react/void-dom-elements-no-children.js +0 -7
  67. package/src/types/index.js +0 -5
  68. package/CHANGELOG.md +0 -236
  69. package/src/rules/component-api/no-arbitrary-token-class.d.ts +0 -17
  70. package/src/rules/component-api/no-default-test-id.d.ts +0 -15
  71. package/src/rules/component-api/no-inline-style.d.ts +0 -15
  72. package/src/rules/component-api/no-is-prefix-prop.d.ts +0 -17
  73. package/src/rules/component-api/no-kind-prop-discriminator.d.ts +0 -25
  74. package/src/rules/component-api/no-raw-color-literal.d.ts +0 -16
  75. package/src/rules/component-api/no-wrapper-sub-component.d.ts +0 -23
  76. package/src/rules/component-api/require-data-slot.d.ts +0 -15
  77. package/src/rules/migration/react-class-to-hooks.d.ts +0 -22
  78. package/src/rules/performance/no-unnecessary-rerenders.d.ts +0 -26
  79. package/src/rules/performance/react-no-inline-functions.d.ts +0 -24
  80. package/src/rules/performance/react-render-optimization.d.ts +0 -31
  81. package/src/rules/react/checked-requires-onchange-or-readonly.d.ts +0 -16
  82. package/src/rules/react/default-props-match-prop-types.d.ts +0 -13
  83. package/src/rules/react/display-name.d.ts +0 -13
  84. package/src/rules/react/hooks-exhaustive-deps.d.ts +0 -25
  85. package/src/rules/react/jsx-handler-names.d.ts +0 -13
  86. package/src/rules/react/jsx-key.d.ts +0 -20
  87. package/src/rules/react/jsx-max-depth.d.ts +0 -19
  88. package/src/rules/react/jsx-no-bind.d.ts +0 -13
  89. package/src/rules/react/jsx-no-duplicate-props.d.ts +0 -21
  90. package/src/rules/react/jsx-no-literals.d.ts +0 -20
  91. package/src/rules/react/jsx-no-script-url.d.ts +0 -25
  92. package/src/rules/react/jsx-no-target-blank.d.ts +0 -26
  93. package/src/rules/react/no-access-state-in-setstate.d.ts +0 -13
  94. package/src/rules/react/no-adjacent-inline-elements.d.ts +0 -13
  95. package/src/rules/react/no-arrow-function-lifecycle.d.ts +0 -13
  96. package/src/rules/react/no-children-prop.d.ts +0 -13
  97. package/src/rules/react/no-danger-with-children.d.ts +0 -16
  98. package/src/rules/react/no-danger.d.ts +0 -13
  99. package/src/rules/react/no-deprecated.d.ts +0 -16
  100. package/src/rules/react/no-did-mount-set-state.d.ts +0 -13
  101. package/src/rules/react/no-did-update-set-state.d.ts +0 -19
  102. package/src/rules/react/no-direct-mutation-state.d.ts +0 -20
  103. package/src/rules/react/no-find-dom-node.d.ts +0 -15
  104. package/src/rules/react/no-invalid-html-attribute.d.ts +0 -13
  105. package/src/rules/react/no-is-mounted.d.ts +0 -13
  106. package/src/rules/react/no-multi-comp.d.ts +0 -18
  107. package/src/rules/react/no-namespace.d.ts +0 -13
  108. package/src/rules/react/no-object-type-as-default-prop.d.ts +0 -13
  109. package/src/rules/react/no-redundant-should-component-update.d.ts +0 -13
  110. package/src/rules/react/no-render-return-value.d.ts +0 -13
  111. package/src/rules/react/no-set-state.d.ts +0 -13
  112. package/src/rules/react/no-string-refs.d.ts +0 -13
  113. package/src/rules/react/no-this-in-sfc.d.ts +0 -13
  114. package/src/rules/react/no-typos.d.ts +0 -13
  115. package/src/rules/react/no-unescaped-entities.d.ts +0 -13
  116. package/src/rules/react/no-unknown-property.d.ts +0 -13
  117. package/src/rules/react/no-unsafe.d.ts +0 -20
  118. package/src/rules/react/prefer-es6-class.d.ts +0 -13
  119. package/src/rules/react/prefer-stateless-function.d.ts +0 -16
  120. package/src/rules/react/prop-types.d.ts +0 -18
  121. package/src/rules/react/react-in-jsx-scope.d.ts +0 -13
  122. package/src/rules/react/require-default-props.d.ts +0 -16
  123. package/src/rules/react/require-optimization.d.ts +0 -26
  124. package/src/rules/react/require-render-return.d.ts +0 -13
  125. package/src/rules/react/required-attributes.d.ts +0 -28
  126. package/src/rules/react/sort-comp.d.ts +0 -17
  127. package/src/rules/react/state-in-constructor.d.ts +0 -13
  128. package/src/rules/react/static-property-placement.d.ts +0 -20
  129. package/src/rules/react/void-dom-elements-no-children.d.ts +0 -15
@@ -1,25 +1,8 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.hooksExhaustiveDeps = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
5
  const eslint_devkit_2 = require("@interlace/eslint-devkit");
11
- /**
12
- * Per-(node.type) cache of which property keys point at child AST nodes.
13
- *
14
- * The previous traversal allocated `Object.keys(node)` for every visited
15
- * node and filtered out metadata (`loc`, `range`, `parent`, …). On next.js's
16
- * 14K-file lint pass the same node types recur millions of times — the
17
- * Object.keys allocation alone showed up as ~4% of the rule's runtime in
18
- * the v2 profile. Caching by node.type makes the second-and-later visit
19
- * per type a single map lookup.
20
- *
21
- * Module-level so the cache amortizes across files in one ESLint run.
22
- */
23
6
  const SKIP_KEYS = new Set(['parent', 'loc', 'range', 'tokens', 'comments', 'type']);
24
7
  const CHILD_KEYS_CACHE = new Map();
25
8
  function getChildKeys(node) {
@@ -32,15 +15,12 @@ function getChildKeys(node) {
32
15
  continue;
33
16
  const v = node[key];
34
17
  if (v && typeof v === 'object') {
35
- // Either an AST node or an array of nodes — record either way; the
36
- // traversal logic at the call site handles both shapes.
37
18
  keys.push(key);
38
19
  }
39
20
  }
40
21
  CHILD_KEYS_CACHE.set(node.type, keys);
41
22
  return keys;
42
23
  }
43
- // Hook names that require dependency array checking
44
24
  const HOOKS_WITH_DEPS = new Set([
45
25
  'useEffect',
46
26
  'useLayoutEffect',
@@ -132,12 +112,8 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
132
112
  const additionalHooksPattern = options.additionalHooks
133
113
  ? new RegExp(options.additionalHooks)
134
114
  : null;
135
- /**
136
- * Check if a call expression is a React hook with dependencies
137
- */
138
115
  function isHookWithDeps(node) {
139
116
  const callee = node.callee;
140
- // Direct hook call: useEffect(...)
141
117
  if (callee.type === 'Identifier') {
142
118
  if (HOOKS_WITH_DEPS.has(callee.name)) {
143
119
  return true;
@@ -146,7 +122,6 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
146
122
  return true;
147
123
  }
148
124
  }
149
- // Namespaced hook call: React.useEffect(...)
150
125
  if (callee.type === 'MemberExpression' &&
151
126
  callee.object.type === 'Identifier' &&
152
127
  callee.object.name === 'React' &&
@@ -156,10 +131,6 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
156
131
  }
157
132
  return false;
158
133
  }
159
- /**
160
- * Get the hook name from a call expression
161
- */
162
- // oxlint-disable-next-line consistent-function-scoping
163
134
  function getHookName(node) {
164
135
  const callee = node.callee;
165
136
  if (callee.type === 'Identifier') {
@@ -171,9 +142,6 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
171
142
  }
172
143
  return 'unknown';
173
144
  }
174
- /**
175
- * Extract variables declared inside a function (to exclude from deps)
176
- */
177
145
  function extractLocallyDeclaredIdentifiers(node) {
178
146
  const declared = new Set();
179
147
  const visited = new WeakSet();
@@ -181,14 +149,12 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
181
149
  if (visited.has(n))
182
150
  return;
183
151
  visited.add(n);
184
- // Variable declarations: const x = 1, let y, var z
185
152
  if (n.type === 'VariableDeclaration') {
186
153
  for (const declarator of n.declarations) {
187
154
  if (declarator.id.type === 'Identifier') {
188
155
  declared.add(declarator.id.name);
189
156
  }
190
157
  else if (declarator.id.type === 'ObjectPattern') {
191
- // Destructuring: const { a, b } = obj
192
158
  for (const prop of declarator.id.properties) {
193
159
  if (prop.type === 'Property' && prop.value.type === 'Identifier') {
194
160
  declared.add(prop.value.name);
@@ -196,7 +162,6 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
196
162
  }
197
163
  }
198
164
  else if (declarator.id.type === 'ArrayPattern') {
199
- // Array destructuring: const [a, b] = arr
200
165
  for (const element of declarator.id.elements) {
201
166
  if (element && element.type === 'Identifier') {
202
167
  declared.add(element.name);
@@ -205,15 +170,9 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
205
170
  }
206
171
  }
207
172
  }
208
- // Function parameters and declarations
209
173
  if (n.type === 'FunctionDeclaration' && n.id) {
210
174
  declared.add(n.id.name);
211
175
  }
212
- // Function parameters of nested arrow / function expressions —
213
- // these are LOCAL to the inner callback, not closures over the
214
- // hook's body. Without this, callbacks like `.then((r) => ...)`
215
- // had `r` flagged as a missing dependency (real FP found by the
216
- // CWE-react-hooks corpus).
217
176
  if (n.type === 'ArrowFunctionExpression' ||
218
177
  n.type === 'FunctionExpression' ||
219
178
  n.type === 'FunctionDeclaration') {
@@ -247,7 +206,6 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
247
206
  for (const param of n.params)
248
207
  collectFromPattern(param);
249
208
  }
250
- // Traverse children using the cached child-keys table.
251
209
  const keys = getChildKeys(n);
252
210
  for (let i = 0; i < keys.length; i++) {
253
211
  const child = n[keys[i]];
@@ -267,30 +225,21 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
267
225
  visit(node);
268
226
  return declared;
269
227
  }
270
- /**
271
- * Extract identifiers used inside a function node (only standalone identifiers, not property names)
272
- */
273
228
  function extractUsedIdentifiers(node) {
274
229
  const used = new Set();
275
230
  const visited = new WeakSet();
276
- // Keys to skip during traversal (to avoid infinite loops)
277
231
  function visit(n, isPropertyKey = false) {
278
- // Prevent infinite loops
279
232
  if (visited.has(n)) {
280
233
  return;
281
234
  }
282
235
  visited.add(n);
283
- // For MemberExpression, only capture the object (root), not the property
284
236
  if (n.type === 'MemberExpression') {
285
237
  visit(n.object, false);
286
- // Don't visit computed properties as property keys
287
238
  if (n.computed && n.property) {
288
239
  visit(n.property, false);
289
240
  }
290
- // Non-computed properties are just property names, skip them
291
241
  return;
292
242
  }
293
- // For CallExpression, capture callee and arguments
294
243
  if (n.type === 'CallExpression') {
295
244
  if (n.callee) {
296
245
  visit(n.callee, false);
@@ -300,11 +249,9 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
300
249
  }
301
250
  return;
302
251
  }
303
- // Only add identifiers that aren't property keys
304
252
  if (n.type === 'Identifier' && !isPropertyKey) {
305
253
  used.add(n.name);
306
254
  }
307
- // Traverse child nodes (cached child-keys table — see getChildKeys).
308
255
  const keys = getChildKeys(n);
309
256
  for (let i = 0; i < keys.length; i++) {
310
257
  const child = n[keys[i]];
@@ -324,9 +271,6 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
324
271
  visit(node);
325
272
  return used;
326
273
  }
327
- /**
328
- * Extract dependencies from the dependency array
329
- */
330
274
  function extractDependencies(depsArray) {
331
275
  const deps = new Set();
332
276
  for (const element of depsArray.elements) {
@@ -335,34 +279,22 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
335
279
  }
336
280
  else if (element?.type === 'MemberExpression' &&
337
281
  element.object.type === 'Identifier') {
338
- // For props.foo, we track the full path
339
282
  const sourceCode = context.sourceCode;
340
283
  deps.add(sourceCode.getText(element));
341
284
  }
342
285
  }
343
286
  return deps;
344
287
  }
345
- /**
346
- * Check if an identifier is a stable React reference
347
- */
348
- // oxlint-disable-next-line consistent-function-scoping
349
288
  function isStableReference(name) {
350
- // setState functions from useState are stable
351
- // dispatch from useReducer is stable
352
- // refs from useRef are stable
353
289
  const stablePatterns = [
354
- /^set[A-Z]/, // setState patterns
290
+ /^set[A-Z]/,
355
291
  /dispatch/i,
356
292
  /Ref$/,
357
293
  ];
358
294
  return stablePatterns.some((pattern) => pattern.test(name));
359
295
  }
360
- /**
361
- * Filter out stable references and non-reactive values
362
- */
363
296
  function filterReactiveDeps(used) {
364
297
  const reactive = new Set();
365
- // Common non-reactive values
366
298
  const nonReactive = new Set([
367
299
  'undefined',
368
300
  'null',
@@ -414,7 +346,6 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
414
346
  }
415
347
  const hookName = getHookName(node);
416
348
  const args = node.arguments;
417
- // Check if hook has a callback argument
418
349
  if (args.length === 0) {
419
350
  return;
420
351
  }
@@ -423,17 +354,10 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
423
354
  callback.type !== 'FunctionExpression') {
424
355
  return;
425
356
  }
426
- // Get the dependency array (second argument)
427
357
  const depsArg = args[1];
428
- // If no deps array provided, don't warn (different rule)
429
358
  if (!depsArg) {
430
359
  return;
431
360
  }
432
- // Mirrors eslint-plugin-react-hooks: handle `as const` casts on the
433
- // deps array, then report when the deps argument is anything other
434
- // than an inline array literal (we can't statically verify a variable
435
- // reference, so the user gets no protection — silent skip would be
436
- // a missed FN, see CWE-XXX in next.js compiled bundles for examples).
437
361
  const isTSAsArrayExpression = depsArg.type === 'TSAsExpression' && depsArg.expression?.type === 'ArrayExpression';
438
362
  const isArrayExpression = depsArg.type === 'ArrayExpression';
439
363
  if (!isArrayExpression && !isTSAsArrayExpression) {
@@ -447,11 +371,8 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
447
371
  const depsArrayNode = isTSAsArrayExpression
448
372
  ? depsArg.expression
449
373
  : depsArg;
450
- // Extract used identifiers from callback
451
374
  const usedInCallback = extractUsedIdentifiers(callback.body);
452
- // Extract locally declared identifiers (should not be dependencies)
453
375
  const locallyDeclared = extractLocallyDeclaredIdentifiers(callback.body);
454
- // Filter out locally declared vars before checking reactive deps
455
376
  const externalUsed = new Set();
456
377
  for (const id of usedInCallback) {
457
378
  if (!locallyDeclared.has(id)) {
@@ -459,25 +380,19 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
459
380
  }
460
381
  }
461
382
  const reactiveDeps = filterReactiveDeps(externalUsed);
462
- // Extract declared dependencies
463
383
  const declaredDeps = extractDependencies(depsArrayNode);
464
- // Find missing dependencies
465
384
  const missingDeps = [];
466
385
  for (const dep of reactiveDeps) {
467
- // Simple check - skip if it looks like a local variable or function
468
- // This is a simplified heuristic
469
386
  if (!declaredDeps.has(dep) && /^[a-z]/.test(dep)) {
470
387
  missingDeps.push(dep);
471
388
  }
472
389
  }
473
- // Find extra/unnecessary dependencies
474
390
  const extraDeps = [];
475
391
  for (const dep of declaredDeps) {
476
392
  if (!usedInCallback.has(dep) && !dep.includes('.')) {
477
393
  extraDeps.push(dep);
478
394
  }
479
395
  }
480
- // Report missing dependencies
481
396
  if (missingDeps.length > 0) {
482
397
  context.report({
483
398
  node: depsArg,
@@ -495,14 +410,12 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
495
410
  return fixer.insertTextAfter(lastElement, `, ${dep}`);
496
411
  }
497
412
  else {
498
- // Empty array
499
413
  return fixer.insertTextAfterRange([depsArrayNode.range[0] + 1, depsArrayNode.range[0] + 1], dep);
500
414
  }
501
415
  },
502
416
  })),
503
417
  });
504
418
  }
505
- // Report extra dependencies
506
419
  for (const dep of extraDeps) {
507
420
  context.report({
508
421
  node: depsArg,
@@ -522,7 +435,6 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
522
435
  const isLast = index === depsArrayNode.elements.length - 1;
523
436
  const isFirst = index === 0;
524
437
  if (isFirst && depsArrayNode.elements.length > 1) {
525
- // Remove first element and following comma
526
438
  const nextElement = depsArrayNode.elements[1];
527
439
  if (nextElement) {
528
440
  return fixer.removeRange([
@@ -532,7 +444,6 @@ exports.hooksExhaustiveDeps = (0, eslint_devkit_1.createRule)({
532
444
  }
533
445
  }
534
446
  else if (isLast && index > 0) {
535
- // Remove last element and preceding comma
536
447
  const prevElement = depsArrayNode.elements[index - 1];
537
448
  if (prevElement) {
538
449
  return fixer.removeRange([
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.jsxHandlerNames = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -34,14 +29,11 @@ exports.jsxHandlerNames = (0, eslint_devkit_1.createRule)({
34
29
  JSXAttribute(node) {
35
30
  if (node.name.type === 'JSXIdentifier') {
36
31
  const attrName = node.name.name;
37
- // Check if this is an event handler (starts with 'on')
38
32
  if (attrName.startsWith('on') && attrName.length > 2) {
39
- // Check if the value is an identifier (function reference)
40
33
  if (node.value && node.value.type === 'JSXExpressionContainer') {
41
34
  const expression = node.value.expression;
42
35
  if (expression.type === 'Identifier') {
43
36
  const handlerName = expression.name;
44
- // Check naming convention: should start with 'handle' or 'on'
45
37
  if (!handlerName.startsWith('handle') && !handlerName.startsWith('on')) {
46
38
  context.report({
47
39
  node: expression,
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.jsxKey = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -76,35 +71,21 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
76
71
  create(context) {
77
72
  const [options] = context.options;
78
73
  const { warnUnstableKeys = true } = options || {};
79
- // Track keys in current iteration context
80
74
  const keyTracker = new Map();
81
75
  function resetKeyTracker() {
82
76
  keyTracker.clear();
83
77
  }
84
- /**
85
- * Array iterator methods that produce lists requiring keys
86
- */
87
78
  const ITERATOR_METHODS = new Set(['map', 'forEach', 'flatMap']);
88
- /**
89
- * Check if a CallExpression is an iterator call that produces a list
90
- * Handles:
91
- * - array.map(), array.forEach(), array.flatMap()
92
- * - Array.from(items, mapFn)
93
- * - React.Children.map(), Children.map()
94
- * - [...items].map() (spread then map)
95
- */
96
79
  function isIteratorCall(node) {
97
80
  if (node.type !== 'CallExpression') {
98
81
  return false;
99
82
  }
100
83
  const { callee } = node;
101
- // Pattern 1: array.map(), array.forEach(), array.flatMap()
102
84
  if (callee.type === 'MemberExpression' &&
103
85
  callee.property.type === 'Identifier' &&
104
86
  ITERATOR_METHODS.has(callee.property.name)) {
105
87
  return true;
106
88
  }
107
- // Pattern 2: Array.from(items, mapFn) - only when 2nd argument is a mapping function
108
89
  if (callee.type === 'MemberExpression' &&
109
90
  callee.object.type === 'Identifier' &&
110
91
  callee.object.name === 'Array' &&
@@ -112,25 +93,17 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
112
93
  callee.property.name === 'from' &&
113
94
  node.arguments.length >= 2) {
114
95
  const mapFn = node.arguments[1];
115
- // Check if second argument is a function (arrow or regular)
116
96
  if (mapFn.type === 'ArrowFunctionExpression' ||
117
97
  mapFn.type === 'FunctionExpression') {
118
98
  return true;
119
99
  }
120
100
  }
121
- // NOTE: React.Children.map(children, fn) / Children.map(children, fn)
122
- // are already matched by Pattern 1 above — any member call named `map`
123
- // returns true there, so no separate pattern is needed.
124
101
  return false;
125
102
  }
126
- /**
127
- * Check if node is inside Array.from's mapping function (2nd argument)
128
- */
129
103
  function isInsideArrayFromMapFn(node) {
130
104
  let current = node;
131
105
  while (current?.parent) {
132
106
  const parent = current.parent;
133
- // Found a function - check if it's Array.from's 2nd argument
134
107
  if (parent.type === 'ArrowFunctionExpression' ||
135
108
  parent.type === 'FunctionExpression') {
136
109
  const grandParent = parent.parent;
@@ -148,9 +121,6 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
148
121
  }
149
122
  return false;
150
123
  }
151
- /**
152
- * Check if node is inside Children.map or React.Children.map
153
- */
154
124
  function isInsideChildrenMap(node) {
155
125
  let current = node;
156
126
  while (current?.parent) {
@@ -164,11 +134,9 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
164
134
  callee.property.type === 'Identifier' &&
165
135
  callee.property.name === 'map') {
166
136
  const obj = callee.object;
167
- // Children.map()
168
137
  if (obj.type === 'Identifier' && obj.name === 'Children') {
169
138
  return true;
170
139
  }
171
- // React.Children.map()
172
140
  if (obj.type === 'MemberExpression' &&
173
141
  obj.object.type === 'Identifier' &&
174
142
  obj.object.name === 'React' &&
@@ -183,19 +151,7 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
183
151
  }
184
152
  return false;
185
153
  }
186
- /**
187
- * Check if a JSXElement is the DIRECT return value of an iterator callback.
188
- * Uses node.parent traversal for reliability.
189
- *
190
- * Handles:
191
- * - array.map(item => <div>)
192
- * - array.map(function(item) { return <div>; })
193
- * - Array.from(items, item => <div>)
194
- * - React.Children.map(children, child => <div>)
195
- * - [...items].map(item => <div>)
196
- */
197
154
  function isDirectIteratorReturn(node) {
198
- // Quick check for Array.from and Children.map patterns
199
155
  if (isInsideArrayFromMapFn(node)) {
200
156
  return isDirectReturnFromFunction(node);
201
157
  }
@@ -205,22 +161,17 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
205
161
  let current = node;
206
162
  while (current.parent) {
207
163
  const parent = current.parent;
208
- // If we hit another JSXElement, this is a nested element - skip
209
164
  if (parent.type === 'JSXElement' || parent.type === 'JSXFragment') {
210
165
  return false;
211
166
  }
212
- // Check: arrow function expression body -> item => <div>
213
167
  if (parent.type === 'ArrowFunctionExpression' &&
214
168
  parent.body === current) {
215
- // Check if the arrow function is argument to map/forEach/flatMap
216
169
  if (parent.parent && isIteratorCall(parent.parent)) {
217
170
  return true;
218
171
  }
219
172
  }
220
- // Check: return statement -> return <div>
221
173
  if (parent.type === 'ReturnStatement' &&
222
174
  parent.argument === current) {
223
- // Walk up to find the function, then check if it's a map callback
224
175
  let funcParent = parent.parent;
225
176
  while (funcParent) {
226
177
  if (funcParent.type === 'ArrowFunctionExpression' ||
@@ -237,52 +188,39 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
237
188
  break;
238
189
  }
239
190
  }
240
- // Check: JSX expression container inside another map
241
191
  if (parent.type === 'JSXExpressionContainer') {
242
- // This could be {items.map(...)} inside JSX - check if current is the map result
243
192
  if (current.type === 'JSXElement' && parent.parent?.type === 'JSXElement') {
244
- // We're inside a JSX expression, check if we came from a map callback
245
193
  return false;
246
194
  }
247
195
  }
248
- // Continue walking up for: conditional expressions, parentheses, etc.
249
196
  if (parent.type === 'ConditionalExpression' ||
250
197
  parent.type === 'LogicalExpression' ||
251
198
  parent.type === 'SequenceExpression') {
252
199
  current = parent;
253
200
  continue;
254
201
  }
255
- // If we hit CallExpression directly, check if it's the map callback
256
202
  if (parent.type === 'CallExpression') {
257
- // We might be the map callback's return value
258
203
  break;
259
204
  }
260
205
  current = parent;
261
206
  }
262
207
  return false;
263
208
  }
264
- /**
265
- * Helper: Check if JSX is directly returned from a function (arrow body or return statement)
266
- */
267
209
  function isDirectReturnFromFunction(node) {
268
210
  let current = node;
269
211
  while (current.parent) {
270
212
  const parent = current.parent;
271
- // Nested in another JSXElement - not a direct return
272
213
  if (parent.type === 'JSXElement' || parent.type === 'JSXFragment') {
273
214
  return false;
274
215
  }
275
- // Arrow function with expression body: item => <div>
276
216
  if (parent.type === 'ArrowFunctionExpression' &&
277
217
  parent.body === current) {
278
218
  return true;
279
219
  }
280
- // Return statement: return <div>
281
220
  if (parent.type === 'ReturnStatement' &&
282
221
  parent.argument === current) {
283
222
  return true;
284
223
  }
285
- // Continue for conditionals/logical expressions
286
224
  if (parent.type === 'ConditionalExpression' ||
287
225
  parent.type === 'LogicalExpression') {
288
226
  current = parent;
@@ -292,21 +230,11 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
292
230
  }
293
231
  return false;
294
232
  }
295
- /**
296
- * Extract the callback parameter name from an iterator call.
297
- * Returns the first parameter name (e.g., 'user' from users.map(user => ...))
298
- *
299
- * Handles:
300
- * - array.map(item => ...) -> 'item'
301
- * - Array.from(items, (item, index) => ...) -> 'item'
302
- * - Children.map(children, child => ...) -> 'child'
303
- */
304
233
  function getIteratorCallbackParamName(node) {
305
234
  let current = node;
306
235
  while (current.parent) {
307
236
  const parent = current.parent;
308
237
  const grandParent = parent.parent;
309
- // Check arrow function expression - isIteratorCall already handles Array.from
310
238
  if (parent.type === 'ArrowFunctionExpression' &&
311
239
  parent.params.length > 0 &&
312
240
  parent.params[0].type === 'Identifier' &&
@@ -314,7 +242,6 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
314
242
  isIteratorCall(grandParent)) {
315
243
  return parent.params[0].name;
316
244
  }
317
- // Check function expression - isIteratorCall already handles Array.from
318
245
  if (parent.type === 'FunctionExpression' &&
319
246
  parent.params.length > 0 &&
320
247
  parent.params[0].type === 'Identifier' &&
@@ -322,7 +249,6 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
322
249
  isIteratorCall(grandParent)) {
323
250
  return parent.params[0].name;
324
251
  }
325
- // Check block statement -> return -> function
326
252
  if (parent.type === 'ReturnStatement') {
327
253
  let funcParent = parent.parent;
328
254
  while (funcParent) {
@@ -344,23 +270,18 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
344
270
  }
345
271
  current = parent;
346
272
  }
347
- // Default fallback
348
273
  return 'item';
349
274
  }
350
275
  function checkJSXElementInIteration(node) {
351
276
  const isDirectReturn = isDirectIteratorReturn(node);
352
- // Only check elements that are direct returns from iterators
353
277
  if (!isDirectReturn) {
354
278
  return;
355
279
  }
356
- // Check for key prop
357
280
  const keyProp = node.openingElement.attributes.find((attr) => attr.type === 'JSXAttribute' &&
358
281
  attr.name.type === 'JSXIdentifier' &&
359
282
  attr.name.name === 'key');
360
283
  if (!keyProp) {
361
- // Get the actual callback parameter name for the fix
362
284
  const paramName = getIteratorCallbackParamName(node);
363
- // Missing key - this is the primary issue
364
285
  context.report({
365
286
  node: node.openingElement,
366
287
  messageId: 'missingKey',
@@ -375,10 +296,8 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
375
296
  });
376
297
  return;
377
298
  }
378
- // Key exists, now analyze its quality
379
299
  if (keyProp.type === 'JSXAttribute' && keyProp.value) {
380
300
  const keyValue = keyProp.value;
381
- // Check for common index variable names used as keys (unstable)
382
301
  if (warnUnstableKeys &&
383
302
  keyValue.type === 'JSXExpressionContainer' &&
384
303
  keyValue.expression.type === 'Identifier' &&
@@ -394,11 +313,8 @@ exports.jsxKey = (0, eslint_devkit_1.createRule)({
394
313
  JSXElement(node) {
395
314
  checkJSXElementInIteration(node);
396
315
  },
397
- // Reset key tracker for each new array/map context
398
316
  CallExpression(node) {
399
- // Check if this is any iterator pattern that produces lists
400
317
  if (isIteratorCall(node)) {
401
- // Entering a new iteration context
402
318
  resetKeyTracker();
403
319
  }
404
320
  },
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.jsxMaxDepth = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -57,19 +52,14 @@ exports.jsxMaxDepth = (0, eslint_devkit_1.createRule)({
57
52
  };
58
53
  },
59
54
  });
60
- /**
61
- * Calculate the maximum depth of JSX nesting
62
- */
63
55
  function calculateDepth(node, currentDepth = 0) {
64
56
  let maxDepth = currentDepth;
65
- // Check children
66
57
  for (const child of node.children) {
67
58
  if (child.type === 'JSXElement') {
68
59
  const childDepth = calculateDepth(child, currentDepth + 1);
69
60
  maxDepth = Math.max(maxDepth, childDepth);
70
61
  }
71
62
  else if (child.type === 'JSXExpressionContainer') {
72
- // Check for JSX inside expressions
73
63
  const expression = child.expression;
74
64
  if (expression.type === 'JSXElement') {
75
65
  const childDepth = calculateDepth(expression, currentDepth + 1);
@@ -1,9 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.jsxNoBind = void 0;
9
4
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
@@ -34,11 +29,9 @@ exports.jsxNoBind = (0, eslint_devkit_1.createRule)({
34
29
  JSXAttribute(node) {
35
30
  if (node.value && node.value.type === 'JSXExpressionContainer') {
36
31
  const expression = node.value.expression;
37
- // Skip empty expressions like {}
38
32
  if (expression.type === 'JSXEmptyExpression') {
39
33
  return;
40
34
  }
41
- // Check for .bind() calls
42
35
  if (isBindCall(expression)) {
43
36
  context.report({
44
37
  node: expression,
@@ -50,9 +43,6 @@ exports.jsxNoBind = (0, eslint_devkit_1.createRule)({
50
43
  };
51
44
  },
52
45
  });
53
- /**
54
- * Check if expression is a .bind() call
55
- */
56
46
  function isBindCall(node) {
57
47
  if (node.type === 'CallExpression') {
58
48
  if (node.callee.type === 'MemberExpression' &&