@eslint-react/core 2.3.13-next.2 → 2.3.13-next.4

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.
package/dist/index.d.ts CHANGED
@@ -291,7 +291,17 @@ declare const isGetDerivedStateFromProps: (node: TSESTree.Node) => node is AST.T
291
291
  declare const isGetDerivedStateFromError: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
292
292
  //#endregion
293
293
  //#region src/component/component-method-parts.d.ts
294
+ /**
295
+ * Checks if the node is a function of `componentDidMount`
296
+ * @param node The AST node to check
297
+ * @returns `true` if the node is a function of `componentDidMount`
298
+ */
294
299
  declare function isFunctionOfComponentDidMount(node: TSESTree.Node): boolean;
300
+ /**
301
+ * Checks if the node is a function of `componentWillUnmount`
302
+ * @param node The AST node to check
303
+ * @returns `true` if the node is a function of `componentWillUnmount`
304
+ */
295
305
  declare function isFunctionOfComponentWillUnmount(node: TSESTree.Node): boolean;
296
306
  //#endregion
297
307
  //#region src/component/component-name.d.ts
@@ -492,16 +502,24 @@ declare const REACT_BUILTIN_HOOK_NAMES: readonly ["use", "useActionState", "useC
492
502
  declare function isReactHookName(name: string): boolean;
493
503
  //#endregion
494
504
  //#region src/hook/hook-parts.d.ts
505
+ /**
506
+ * Determines if a node is the setup function passed to a useEffect-like hook
507
+ * @param node The AST node to check
508
+ */
495
509
  declare function isFunctionOfUseEffectSetup(node: TSESTree.Node | unit): boolean;
510
+ /**
511
+ * Determines if a node is the cleanup function returned by a useEffect-like hook's setup function.
512
+ * @param node The AST node to check
513
+ */
496
514
  declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node | unit): boolean;
497
515
  //#endregion
498
516
  //#region src/jsx/jsx-attribute.d.ts
499
517
  /**
500
- * Get a function to find JSX attributes by name, considering direct attributes and spread attributes.
518
+ * Creates a helper function to find a specific JSX attribute by name
519
+ * Handles direct attributes and spread attributes (variables or object literals)
501
520
  * @param context The ESLint rule context
502
521
  * @param node The JSX element node
503
- * @param initialScope Optional initial scope for variable resolution
504
- * @returns A function that takes an attribute name and returns the corresponding JSX attribute node or undefined
522
+ * @param initialScope (Optional) The initial scope to use for variable resolution
505
523
  */
506
524
  declare function getJsxAttribute(context: RuleContext, node: TSESTree.JSXElement, initialScope?: Scope): (name: string) => TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | undefined;
507
525
  //#endregion
@@ -542,6 +560,13 @@ type JsxAttributeValue = {
542
560
  node: TSESTree.JSXSpreadChild["expression"];
543
561
  toStatic(): unknown;
544
562
  };
563
+ /**
564
+ * Resolves the static value of a JSX attribute or spread attribute
565
+ *
566
+ * @param context - The ESLint rule context
567
+ * @param attribute - The JSX attribute node to resolve
568
+ * @returns An object containing the value kind, the node (if applicable), and a `toStatic` helper
569
+ */
545
570
  declare function resolveJsxAttributeValue(context: RuleContext, attribute: AST.TSESTreeJSXAttributeLike): {
546
571
  readonly kind: "boolean";
547
572
  readonly toStatic: () => true;
@@ -584,9 +609,9 @@ interface JsxConfig {
584
609
  jsxImportSource?: string;
585
610
  }
586
611
  /**
587
- * Get JsxConfig from the rule context by reading compiler options.
588
- * @param context The RuleContext.
589
- * @returns JsxConfig derived from compiler options.
612
+ * Get JsxConfig from the rule context by reading compiler options
613
+ * @param context The RuleContext
614
+ * @returns JsxConfig derived from compiler options
590
615
  */
591
616
  declare function getJsxConfigFromContext(context: RuleContext): {
592
617
  jsx: 4 | typescript0.JsxEmit;
@@ -595,9 +620,9 @@ declare function getJsxConfigFromContext(context: RuleContext): {
595
620
  jsxImportSource: string;
596
621
  };
597
622
  /**
598
- * Get JsxConfig from pragma comments (annotations) in the source code.
599
- * @param context The RuleContext.
600
- * @returns JsxConfig derived from pragma comments.
623
+ * Get JsxConfig from pragma comments (annotations) in the source code
624
+ * @param context The RuleContext
625
+ * @returns JsxConfig derived from pragma comments
601
626
  */
602
627
  declare function getJsxConfigFromAnnotation(context: RuleContext): JsxConfig;
603
628
  //#endregion
package/dist/index.js CHANGED
@@ -197,10 +197,18 @@ function isReactHookId(id) {
197
197
 
198
198
  //#endregion
199
199
  //#region src/hook/hook-parts.ts
200
+ /**
201
+ * Determines if a node is the setup function passed to a useEffect-like hook
202
+ * @param node The AST node to check
203
+ */
200
204
  function isFunctionOfUseEffectSetup(node) {
201
205
  if (node == null) return false;
202
206
  return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.arguments.at(0) === node && isUseEffectLikeCall(node.parent);
203
207
  }
208
+ /**
209
+ * Determines if a node is the cleanup function returned by a useEffect-like hook's setup function.
210
+ * @param node The AST node to check
211
+ */
204
212
  function isFunctionOfUseEffectCleanup(node) {
205
213
  if (node == null) return false;
206
214
  const pReturn = AST.findParentNode(node, AST.is(AST_NODE_TYPES.ReturnStatement));
@@ -245,19 +253,18 @@ function getJsxAttributeName(context, node) {
245
253
  //#endregion
246
254
  //#region src/jsx/jsx-attribute.ts
247
255
  /**
248
- * Get a function to find JSX attributes by name, considering direct attributes and spread attributes.
256
+ * Creates a helper function to find a specific JSX attribute by name
257
+ * Handles direct attributes and spread attributes (variables or object literals)
249
258
  * @param context The ESLint rule context
250
259
  * @param node The JSX element node
251
- * @param initialScope Optional initial scope for variable resolution
252
- * @returns A function that takes an attribute name and returns the corresponding JSX attribute node or undefined
260
+ * @param initialScope (Optional) The initial scope to use for variable resolution
253
261
  */
254
262
  function getJsxAttribute(context, node, initialScope) {
255
263
  const scope = initialScope ?? context.sourceCode.getScope(node);
256
264
  const attributes = node.openingElement.attributes;
257
265
  /**
258
- * Find a JSX attribute by name, considering both direct attributes and spread attributes.
259
- * @param name The name of the attribute to find
260
- * @returns The JSX attribute node if found, otherwise undefined
266
+ * Finds the last occurrence of a specific attribute
267
+ * @param name The attribute name to search for
261
268
  */
262
269
  return (name) => {
263
270
  return attributes.findLast((attr) => {
@@ -277,8 +284,19 @@ function getJsxAttribute(context, node, initialScope) {
277
284
 
278
285
  //#endregion
279
286
  //#region src/jsx/jsx-attribute-value.ts
287
+ /**
288
+ * Resolves the static value of a JSX attribute or spread attribute
289
+ *
290
+ * @param context - The ESLint rule context
291
+ * @param attribute - The JSX attribute node to resolve
292
+ * @returns An object containing the value kind, the node (if applicable), and a `toStatic` helper
293
+ */
280
294
  function resolveJsxAttributeValue(context, attribute) {
281
295
  const initialScope = context.sourceCode.getScope(attribute);
296
+ /**
297
+ * Handles standard JSX attributes (e.g., prop="value", prop={value}, prop)
298
+ * @param node The JSX attribute node
299
+ */
282
300
  function handleJsxAttribute(node) {
283
301
  if (node.value == null) return {
284
302
  kind: "boolean",
@@ -323,6 +341,10 @@ function resolveJsxAttributeValue(context, attribute) {
323
341
  };
324
342
  }
325
343
  }
344
+ /**
345
+ * Handles JSX spread attributes (e.g., {...props})
346
+ * @param node The JSX spread attribute node
347
+ */
326
348
  function handleJsxSpreadAttribute(node) {
327
349
  return {
328
350
  kind: "spreadProps",
@@ -350,9 +372,9 @@ const JsxEmit = {
350
372
  ReactJSXDev: 5
351
373
  };
352
374
  /**
353
- * Get JsxConfig from the rule context by reading compiler options.
354
- * @param context The RuleContext.
355
- * @returns JsxConfig derived from compiler options.
375
+ * Get JsxConfig from the rule context by reading compiler options
376
+ * @param context The RuleContext
377
+ * @returns JsxConfig derived from compiler options
356
378
  */
357
379
  function getJsxConfigFromContext(context) {
358
380
  const options = context.sourceCode.parserServices?.program?.getCompilerOptions() ?? {};
@@ -365,9 +387,9 @@ function getJsxConfigFromContext(context) {
365
387
  }
366
388
  const cache = /* @__PURE__ */ new WeakMap();
367
389
  /**
368
- * Get JsxConfig from pragma comments (annotations) in the source code.
369
- * @param context The RuleContext.
370
- * @returns JsxConfig derived from pragma comments.
390
+ * Get JsxConfig from pragma comments (annotations) in the source code
391
+ * @param context The RuleContext
392
+ * @returns JsxConfig derived from pragma comments
371
393
  */
372
394
  function getJsxConfigFromAnnotation(context) {
373
395
  return getOrElseUpdate(cache, context.sourceCode, () => {
@@ -1134,9 +1156,19 @@ const isGetDerivedStateFromError = createLifecycleChecker("getDerivedStateFromEr
1134
1156
 
1135
1157
  //#endregion
1136
1158
  //#region src/component/component-method-parts.ts
1159
+ /**
1160
+ * Checks if the node is a function of `componentDidMount`
1161
+ * @param node The AST node to check
1162
+ * @returns `true` if the node is a function of `componentDidMount`
1163
+ */
1137
1164
  function isFunctionOfComponentDidMount(node) {
1138
1165
  return AST.isFunction(node) && isComponentDidMount(node.parent) && node.parent.value === node;
1139
1166
  }
1167
+ /**
1168
+ * Checks if the node is a function of `componentWillUnmount`
1169
+ * @param node The AST node to check
1170
+ * @returns `true` if the node is a function of `componentWillUnmount`
1171
+ */
1140
1172
  function isFunctionOfComponentWillUnmount(node) {
1141
1173
  return AST.isFunction(node) && isComponentWillUnmount(node.parent) && node.parent.value === node;
1142
1174
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "2.3.13-next.2",
3
+ "version": "2.3.13-next.4",
4
4
  "description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -35,10 +35,10 @@
35
35
  "@typescript-eslint/utils": "^8.48.1",
36
36
  "birecord": "^0.1.1",
37
37
  "ts-pattern": "^5.9.0",
38
- "@eslint-react/ast": "2.3.13-next.2",
39
- "@eslint-react/shared": "2.3.13-next.2",
40
- "@eslint-react/var": "2.3.13-next.2",
41
- "@eslint-react/eff": "2.3.13-next.2"
38
+ "@eslint-react/ast": "2.3.13-next.4",
39
+ "@eslint-react/shared": "2.3.13-next.4",
40
+ "@eslint-react/eff": "2.3.13-next.4",
41
+ "@eslint-react/var": "2.3.13-next.4"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "eslint": "^8.57.0 || ^9.0.0",