Skip to content

Commit b9ab289

Browse files
committed
release: 2.3.13-beta.3
1 parent 057b815 commit b9ab289

File tree

22 files changed

+76
-52
lines changed

22 files changed

+76
-52
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.13-next.3
1+
2.3.13-beta.3

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/monorepo",
3-
"version": "2.3.13-next.3",
3+
"version": "2.3.13-beta.3",
44
"private": true,
55
"description": "Monorepo for eslint-plugin-react-[x, dom, web-api, hooks-extra, naming-convention].",
66
"keywords": [

packages/core/docs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@
120120
| [getComponentFlagFromInitPath](functions/getComponentFlagFromInitPath.md) | - |
121121
| [getComponentNameFromId](functions/getComponentNameFromId.md) | Get component name from an identifier or identifier sequence (e.g., MemberExpression) |
122122
| [getFunctionComponentId](functions/getFunctionComponentId.md) | - |
123-
| [getJsxAttribute](functions/getJsxAttribute.md) | Get a function to find JSX attributes by name, considering direct attributes and spread attributes. |
123+
| [getJsxAttribute](functions/getJsxAttribute.md) | Creates a helper function to find a specific JSX attribute by name Handles direct attributes and spread attributes (variables or object literals) |
124124
| [getJsxAttributeName](functions/getJsxAttributeName.md) | Get the stringified name of a JSX attribute |
125-
| [getJsxConfigFromAnnotation](functions/getJsxConfigFromAnnotation.md) | Get JsxConfig from pragma comments (annotations) in the source code. |
126-
| [getJsxConfigFromContext](functions/getJsxConfigFromContext.md) | Get JsxConfig from the rule context by reading compiler options. |
125+
| [getJsxConfigFromAnnotation](functions/getJsxConfigFromAnnotation.md) | Get JsxConfig from pragma comments (annotations) in the source code |
126+
| [getJsxConfigFromContext](functions/getJsxConfigFromContext.md) | Get JsxConfig from the rule context by reading compiler options |
127127
| [getJsxElementType](functions/getJsxElementType.md) | Extracts the element type name from a JSX element or fragment For JSX elements, returns the stringified name (e.g., "div", "Button", "React.Fragment") For JSX fragments, returns an empty string |
128128
| [getPhaseKindOfFunction](functions/getPhaseKindOfFunction.md) | - |
129129
| [hasNoneOrLooseComponentName](functions/hasNoneOrLooseComponentName.md) | Check if the function has no name or a loose component name |
@@ -156,7 +156,7 @@
156156
| [isRenderMethodLike](functions/isRenderMethodLike.md) | Check whether given node is a render method of a class component |
157157
| [isRenderPropLoose](functions/isRenderPropLoose.md) | Unsafe check whether given JSXAttribute is a render prop `_ = <Component renderRow={() => <div />} /> ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `` |
158158
| [isUseEffectLikeCall](functions/isUseEffectLikeCall.md) | Detects useEffect calls and variations (useLayoutEffect, etc.) using regex pattern. |
159-
| [resolveJsxAttributeValue](functions/resolveJsxAttributeValue.md) | - |
159+
| [resolveJsxAttributeValue](functions/resolveJsxAttributeValue.md) | Resolves the static value of a JSX attribute or spread attribute |
160160
| [stringifyJsx](functions/stringifyJsx.md) | Incomplete but sufficient stringification of JSX nodes for common use cases |
161161
| [useComponentCollector](functions/useComponentCollector.md) | Get a ctx and listeners for the rule to collect function components |
162162
| [useComponentCollectorLegacy](functions/useComponentCollectorLegacy.md) | Get a ctx and listeners object for the rule to collect class components |

packages/core/docs/functions/getJsxAttribute.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ function getJsxAttribute(
99
initialScope?: Scope): (name: string) => JSXAttribute | JSXSpreadAttribute | undefined;
1010
```
1111

12-
Get a function to find JSX attributes by name, considering direct attributes and spread attributes.
12+
Creates a helper function to find a specific JSX attribute by name
13+
Handles direct attributes and spread attributes (variables or object literals)
1314

1415
## Parameters
1516

1617
| Parameter | Type | Description |
1718
| ------ | ------ | ------ |
1819
| `context` | `RuleContext` | The ESLint rule context |
1920
| `node` | `JSXElement` | The JSX element node |
20-
| `initialScope?` | `Scope` | Optional initial scope for variable resolution |
21+
| `initialScope?` | `Scope` | (Optional) The initial scope to use for variable resolution |
2122

2223
## Returns
2324

24-
A function that takes an attribute name and returns the corresponding JSX attribute node or undefined
25-
2625
```ts
2726
(name: string): JSXAttribute | JSXSpreadAttribute | undefined;
2827
```

packages/core/docs/functions/getJsxConfigFromAnnotation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
function getJsxConfigFromAnnotation(context: RuleContext): JsxConfig;
77
```
88

9-
Get JsxConfig from pragma comments (annotations) in the source code.
9+
Get JsxConfig from pragma comments (annotations) in the source code
1010

1111
## Parameters
1212

1313
| Parameter | Type | Description |
1414
| ------ | ------ | ------ |
15-
| `context` | `RuleContext` | The RuleContext. |
15+
| `context` | `RuleContext` | The RuleContext |
1616

1717
## Returns
1818

1919
[`JsxConfig`](../interfaces/JsxConfig.md)
2020

21-
JsxConfig derived from pragma comments.
21+
JsxConfig derived from pragma comments

packages/core/docs/functions/getJsxConfigFromContext.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ function getJsxConfigFromContext(context: RuleContext): {
1111
};
1212
```
1313

14-
Get JsxConfig from the rule context by reading compiler options.
14+
Get JsxConfig from the rule context by reading compiler options
1515

1616
## Parameters
1717

1818
| Parameter | Type | Description |
1919
| ------ | ------ | ------ |
20-
| `context` | `RuleContext` | The RuleContext. |
20+
| `context` | `RuleContext` | The RuleContext |
2121

2222
## Returns
2323

@@ -30,7 +30,7 @@ Get JsxConfig from the rule context by reading compiler options.
3030
}
3131
```
3232

33-
JsxConfig derived from compiler options.
33+
JsxConfig derived from compiler options
3434

3535
| Name | Type |
3636
| ------ | ------ |

packages/core/docs/functions/resolveJsxAttributeValue.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ function resolveJsxAttributeValue(context: RuleContext, attribute: TSESTreeJSXAt
4646
};
4747
```
4848

49+
Resolves the static value of a JSX attribute or spread attribute
50+
4951
## Parameters
5052

51-
| Parameter | Type |
52-
| ------ | ------ |
53-
| `context` | `RuleContext` |
54-
| `attribute` | `TSESTreeJSXAttributeLike` |
53+
| Parameter | Type | Description |
54+
| ------ | ------ | ------ |
55+
| `context` | `RuleContext` | The ESLint rule context |
56+
| `attribute` | `TSESTreeJSXAttributeLike` | The JSX attribute node to resolve |
5557

5658
## Returns
5759

@@ -95,3 +97,5 @@ function resolveJsxAttributeValue(context: RuleContext, attribute: TSESTreeJSXAt
9597
`node`: `Expression`;
9698
`toStatic`: `unknown`;
9799
\}
100+
101+
An object containing the value kind, the node (if applicable), and a `toStatic` helper

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eslint-react/core",
3-
"version": "2.3.13-next.3",
3+
"version": "2.3.13-beta.3",
44
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
55
"homepage": "https://github.com/Rel1cx/eslint-react",
66
"bugs": {

packages/core/src/jsx/jsx-attribute-value.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,20 @@ export type JsxAttributeValue =
1818
| { kind: "spreadProps"; node: TSESTree.JSXSpreadAttribute["argument"]; toStatic(name?: string): unknown } // Spread props (e.g., {...props})
1919
| { kind: "spreadChild"; node: TSESTree.JSXSpreadChild["expression"]; toStatic(): unknown }; // Spread children (e.g., {...["Hello", " ", "spread", " ", "children"]})
2020

21+
/**
22+
* Resolves the static value of a JSX attribute or spread attribute
23+
*
24+
* @param context - The ESLint rule context
25+
* @param attribute - The JSX attribute node to resolve
26+
* @returns An object containing the value kind, the node (if applicable), and a `toStatic` helper
27+
*/
2128
export function resolveJsxAttributeValue(context: RuleContext, attribute: AST.TSESTreeJSXAttributeLike) {
2229
const initialScope = context.sourceCode.getScope(attribute);
30+
31+
/**
32+
* Handles standard JSX attributes (e.g., prop="value", prop={value}, prop)
33+
* @param node The JSX attribute node
34+
*/
2335
function handleJsxAttribute(node: TSESTree.JSXAttribute) {
2436
// Case 1: Boolean attribute with no value (e.g., disabled)
2537
if (node.value == null) {
@@ -74,6 +86,10 @@ export function resolveJsxAttributeValue(context: RuleContext, attribute: AST.TS
7486
}
7587
}
7688

89+
/**
90+
* Handles JSX spread attributes (e.g., {...props})
91+
* @param node The JSX spread attribute node
92+
*/
7793
function handleJsxSpreadAttribute(node: TSESTree.JSXSpreadAttribute) {
7894
// For spread attributes (e.g., {...props}), try to extract static value
7995
return {
@@ -88,6 +104,7 @@ export function resolveJsxAttributeValue(context: RuleContext, attribute: AST.TS
88104
},
89105
} as const satisfies JsxAttributeValue;
90106
}
107+
91108
switch (attribute.type) {
92109
case T.JSXAttribute:
93110
return handleJsxAttribute(attribute);

packages/core/src/jsx/jsx-attribute.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,41 @@ import type { Scope } from "@typescript-eslint/scope-manager";
77
import { getJsxAttributeName } from "./jsx-attribute-name";
88

99
/**
10-
* Get a function to find JSX attributes by name, considering direct attributes and spread attributes.
10+
* Creates a helper function to find a specific JSX attribute by name
11+
* Handles direct attributes and spread attributes (variables or object literals)
1112
* @param context The ESLint rule context
1213
* @param node The JSX element node
13-
* @param initialScope Optional initial scope for variable resolution
14-
* @returns A function that takes an attribute name and returns the corresponding JSX attribute node or undefined
14+
* @param initialScope (Optional) The initial scope to use for variable resolution
1515
*/
1616
export function getJsxAttribute(context: RuleContext, node: TSESTree.JSXElement, initialScope?: Scope) {
1717
const scope = initialScope ?? context.sourceCode.getScope(node);
1818
const attributes = node.openingElement.attributes;
19+
1920
/**
20-
* Find a JSX attribute by name, considering both direct attributes and spread attributes.
21-
* @param name The name of the attribute to find
22-
* @returns The JSX attribute node if found, otherwise undefined
21+
* Finds the last occurrence of a specific attribute
22+
* @param name The attribute name to search for
2323
*/
2424
return (name: string) => {
2525
return attributes.findLast((attr) => {
26-
// Case 1: Direct JSX attribute (e.g., className="value")
26+
// 1. Direct attribute: className="value"
2727
if (attr.type === T.JSXAttribute) {
2828
return getJsxAttributeName(context, attr) === name;
2929
}
30+
3031
switch (attr.argument.type) {
31-
// Case 2: Spread from variable (e.g., {...props})
32+
// 2. Spread variable: {...props}
3233
case T.Identifier: {
3334
const variable = findVariable(attr.argument.name, scope);
3435
const variableNode = getVariableDefinitionNode(variable, 0);
36+
37+
// Check if the variable resolves to an object with the target property
3538
if (variableNode?.type === T.ObjectExpression) {
3639
return findProperty(name, variableNode.properties, scope) != null;
3740
}
3841
return false;
3942
}
40-
// Case 3: Spread from object literal (e.g., {{...{prop: value}}})
43+
44+
// 3. Spread literal: {{...{prop: value}}}
4145
case T.ObjectExpression:
4246
return findProperty(name, attr.argument.properties, scope) != null;
4347
}

0 commit comments

Comments
 (0)