Skip to content

Commit 3fe5aae

Browse files
Rel1cxCopilot
andauthored
refactor(core): restructure component detection APIs (#1197)
Signed-off-by: REL1CX <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent a479f05 commit 3fe5aae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+560
-414
lines changed

packages/core/docs/README.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
- [isChildrenToArrayCall](variables/isChildrenToArrayCall.md)
5656
- [isCloneElement](variables/isCloneElement.md)
5757
- [isCloneElementCall](variables/isCloneElementCall.md)
58+
- [isComponentDidCatch](variables/isComponentDidCatch.md)
59+
- [isComponentDidMount](variables/isComponentDidMount.md)
60+
- [isComponentDidUpdate](variables/isComponentDidUpdate.md)
61+
- [isComponentWillMount](variables/isComponentWillMount.md)
62+
- [isComponentWillReceiveProps](variables/isComponentWillReceiveProps.md)
63+
- [isComponentWillUnmount](variables/isComponentWillUnmount.md)
64+
- [isComponentWillUpdate](variables/isComponentWillUpdate.md)
5865
- [isCreateContext](variables/isCreateContext.md)
5966
- [isCreateContextCall](variables/isCreateContextCall.md)
6067
- [isCreateElement](variables/isCreateElement.md)
@@ -63,11 +70,22 @@
6370
- [isCreateRefCall](variables/isCreateRefCall.md)
6471
- [isForwardRef](variables/isForwardRef.md)
6572
- [isForwardRefCall](variables/isForwardRefCall.md)
73+
- [isGetChildContext](variables/isGetChildContext.md)
74+
- [isGetDefaultProps](variables/isGetDefaultProps.md)
75+
- [isGetDerivedStateFromError](variables/isGetDerivedStateFromError.md)
76+
- [isGetDerivedStateFromProps](variables/isGetDerivedStateFromProps.md)
77+
- [isGetInitialState](variables/isGetInitialState.md)
78+
- [isGetSnapshotBeforeUpdate](variables/isGetSnapshotBeforeUpdate.md)
6679
- [isInversePhase](variables/isInversePhase.md)
6780
- [isLazy](variables/isLazy.md)
6881
- [isLazyCall](variables/isLazyCall.md)
6982
- [isMemo](variables/isMemo.md)
7083
- [isMemoCall](variables/isMemoCall.md)
84+
- [isRender](variables/isRender.md)
85+
- [isShouldComponentUpdate](variables/isShouldComponentUpdate.md)
86+
- [isUnsafeComponentWillMount](variables/isUnsafeComponentWillMount.md)
87+
- [isUnsafeComponentWillReceiveProps](variables/isUnsafeComponentWillReceiveProps.md)
88+
- [isUnsafeComponentWillUpdate](variables/isUnsafeComponentWillUpdate.md)
7189
- [isUseActionStateCall](variables/isUseActionStateCall.md)
7290
- [isUseCall](variables/isUseCall.md)
7391
- [isUseCallbackCall](variables/isUseCallbackCall.md)
@@ -107,27 +125,14 @@
107125
- [isAssignmentToThisState](functions/isAssignmentToThisState.md)
108126
- [isChildrenOfCreateElement](functions/isChildrenOfCreateElement.md)
109127
- [isClassComponent](functions/isClassComponent.md)
110-
- [isComponentDidCatch](functions/isComponentDidCatch.md)
111-
- [isComponentDidMount](functions/isComponentDidMount.md)
112-
- [isComponentDidUpdate](functions/isComponentDidUpdate.md)
128+
- [isComponentDefinition](functions/isComponentDefinition.md)
113129
- [isComponentName](functions/isComponentName.md)
114130
- [isComponentNameLoose](functions/isComponentNameLoose.md)
115-
- [isComponentWillMount](functions/isComponentWillMount.md)
116-
- [isComponentWillReceiveProps](functions/isComponentWillReceiveProps.md)
117-
- [isComponentWillUnmount](functions/isComponentWillUnmount.md)
118-
- [isComponentWillUpdate](functions/isComponentWillUpdate.md)
119131
- [isComponentWrapperCall](functions/isComponentWrapperCall.md)
120132
- [isComponentWrapperCallLoose](functions/isComponentWrapperCallLoose.md)
121133
- [isDeclaredInRenderPropLoose](functions/isDeclaredInRenderPropLoose.md)
122134
- [isFragmentElement](functions/isFragmentElement.md)
123-
- [isFunctionOfRender](functions/isFunctionOfRender.md)
124135
- [isFunctionOfRenderMethod](functions/isFunctionOfRenderMethod.md)
125-
- [isGetChildContext](functions/isGetChildContext.md)
126-
- [isGetDefaultProps](functions/isGetDefaultProps.md)
127-
- [isGetDerivedStateFromError](functions/isGetDerivedStateFromError.md)
128-
- [isGetDerivedStateFromProps](functions/isGetDerivedStateFromProps.md)
129-
- [isGetInitialState](functions/isGetInitialState.md)
130-
- [isGetSnapshotBeforeUpdate](functions/isGetSnapshotBeforeUpdate.md)
131136
- [isHostElement](functions/isHostElement.md)
132137
- [isJsxLike](functions/isJsxLike.md)
133138
- [isJsxText](functions/isJsxText.md)
@@ -142,16 +147,10 @@
142147
- [isReactHookId](functions/isReactHookId.md)
143148
- [isReactHookName](functions/isReactHookName.md)
144149
- [isRenderFunctionLoose](functions/isRenderFunctionLoose.md)
145-
- [isRenderLike](functions/isRenderLike.md)
146150
- [isRenderMethodLike](functions/isRenderMethodLike.md)
147151
- [isRenderPropLoose](functions/isRenderPropLoose.md)
148-
- [isShouldComponentUpdate](functions/isShouldComponentUpdate.md)
149152
- [isThisSetState](functions/isThisSetState.md)
150-
- [isUnsafeComponentWillMount](functions/isUnsafeComponentWillMount.md)
151-
- [isUnsafeComponentWillReceiveProps](functions/isUnsafeComponentWillReceiveProps.md)
152-
- [isUnsafeComponentWillUpdate](functions/isUnsafeComponentWillUpdate.md)
153153
- [isUseEffectCallLoose](functions/isUseEffectCallLoose.md)
154-
- [isValidComponentDefinition](functions/isValidComponentDefinition.md)
155154
- [stringifyJsx](functions/stringifyJsx.md)
156155
- [useComponentCollector](functions/useComponentCollector.md)
157156
- [useComponentCollectorLegacy](functions/useComponentCollectorLegacy.md)

packages/core/docs/functions/findParentAttribute.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@
88

99
> **findParentAttribute**(`node`, `test`): `undefined` \| `JSXAttribute`
1010
11-
Find the parent JSX attribute node of a node
11+
Traverses up the AST to find a parent JSX attribute node that matches a given test
1212

1313
## Parameters
1414

1515
### node
1616

1717
`Node`
1818

19-
The node to find the parent attribute of
19+
The starting AST node
2020

2121
### test
2222

2323
(`node`) => `boolean`
2424

25-
The test to apply to the parent attribute
25+
Optional predicate function to test if the attribute meets criteria
26+
Defaults to always returning true (matches any attribute)
2627

2728
## Returns
2829

2930
`undefined` \| `JSXAttribute`
3031

31-
The parent attribute node or undefined
32+
The first matching JSX attribute node found when traversing upwards, or undefined

packages/core/docs/functions/getAttribute.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,37 @@
88

99
> **getAttribute**(`context`, `name`, `attributes`, `initialScope?`): `undefined` \| `JSXAttribute` \| `JSXSpreadAttribute`
1010
11-
Get the JSX attribute node with the given name
11+
Searches for a specific JSX attribute by name in a list of attributes
12+
Returns the last matching attribute (rightmost in JSX)
1213

1314
## Parameters
1415

1516
### context
1617

1718
`RuleContext`
1819

19-
The ESLint rule context
20+
ESLint rule context
2021

2122
### name
2223

2324
`string`
2425

25-
The name of the attribute
26+
The name of the attribute to find
2627

2728
### attributes
2829

2930
(`JSXAttribute` \| `JSXSpreadAttribute`)[]
3031

31-
The attributes to search
32+
Array of JSX attributes to search through
3233

3334
### initialScope?
3435

3536
`Scope`
3637

37-
The initial scope to use for variable resolution
38+
Optional scope for resolving variables
3839

3940
## Returns
4041

4142
`undefined` \| `JSXAttribute` \| `JSXSpreadAttribute`
4243

43-
The JSX attribute node or undefined
44+
The found attribute or undefined

packages/core/docs/functions/getAttributeValue.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@
88

99
> **getAttributeValue**(`context`, `node`, `name`): \{ `initialScope`: `undefined` \| `Scope`; `kind`: `"none"`; `node`: `Node`; \} \| \{ `initialScope`: `undefined` \| `Scope`; `kind`: `"some"`; `node`: `Node`; `value`: `unknown`; \}
1010
11-
Get a StaticValue of the attribute value
11+
Extracts the value of a JSX attribute by name
1212

1313
## Parameters
1414

1515
### context
1616

1717
`RuleContext`
1818

19-
The rule context
19+
ESLint rule context
2020

2121
### node
2222

23-
The JSX attribute node
23+
JSX attribute or spread attribute node
2424

2525
`JSXAttribute` | `JSXSpreadAttribute`
2626

2727
### name
2828

2929
`string`
3030

31-
The name of the attribute
31+
Name of the attribute to extract
3232

3333
## Returns
3434

3535
\{ `initialScope`: `undefined` \| `Scope`; `kind`: `"none"`; `node`: `Node`; \} \| \{ `initialScope`: `undefined` \| `Scope`; `kind`: `"some"`; `node`: `Node`; `value`: `unknown`; \}
3636

37-
The StaticValue of the attribute value
37+
The extracted attribute value in a structured format

packages/core/docs/functions/getElementType.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@
88

99
> **getElementType**(`context`, `node`): `string`
1010
11-
Get the stringified type of a JSX element
11+
Extracts the element type name from a JSX element or fragment
12+
For JSX elements, returns the stringified name (e.g., "div", "Button", "React.Fragment")
13+
For JSX fragments, returns an empty string
1214

1315
## Parameters
1416

1517
### context
1618

1719
`RuleContext`
1820

19-
The ESLint rule context
21+
ESLint rule context
2022

2123
### node
2224

23-
The JSX element node
25+
JSX element or fragment node
2426

2527
`JSXElement` | `JSXFragment`
2628

2729
## Returns
2830

2931
`string`
3032

31-
The type of the element
33+
String representation of the element type

packages/core/docs/functions/hasAnyAttribute.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,36 @@
88

99
> **hasAnyAttribute**(`context`, `names`, `attributes`, `initialScope?`): `boolean`
1010
11+
Checks if a JSX element has at least one of the specified attributes
12+
1113
## Parameters
1214

1315
### context
1416

1517
`RuleContext`
1618

19+
ESLint rule context
20+
1721
### names
1822

1923
`string`[]
2024

25+
Array of attribute names to check for
26+
2127
### attributes
2228

2329
(`JSXAttribute` \| `JSXSpreadAttribute`)[]
2430

31+
List of JSX attributes from opening element
32+
2533
### initialScope?
2634

2735
`Scope`
2836

37+
Optional scope for resolving variables in spread attributes
38+
2939
## Returns
3040

3141
`boolean`
42+
43+
boolean indicating whether any of the attributes exist

packages/core/docs/functions/hasAttribute.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,36 @@
88

99
> **hasAttribute**(`context`, `name`, `attributes`, `initialScope?`): `boolean`
1010
11+
Checks if a JSX element has a specific attribute
12+
1113
## Parameters
1214

1315
### context
1416

1517
`RuleContext`
1618

19+
ESLint rule context
20+
1721
### name
1822

1923
`string`
2024

25+
Name of the attribute to check for
26+
2127
### attributes
2228

2329
(`JSXAttribute` \| `JSXSpreadAttribute`)[]
2430

31+
List of JSX attributes from opening element
32+
2533
### initialScope?
2634

2735
`Scope`
2836

37+
Optional scope for resolving variables in spread attributes
38+
2939
## Returns
3040

3141
`boolean`
42+
43+
boolean indicating whether the attribute exists

packages/core/docs/functions/hasEveryAttribute.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,36 @@
88

99
> **hasEveryAttribute**(`context`, `names`, `attributes`, `initialScope?`): `boolean`
1010
11+
Checks if a JSX element has all of the specified attributes
12+
1113
## Parameters
1214

1315
### context
1416

1517
`RuleContext`
1618

19+
ESLint rule context
20+
1721
### names
1822

1923
`string`[]
2024

25+
Array of attribute names to check for
26+
2127
### attributes
2228

2329
(`JSXAttribute` \| `JSXSpreadAttribute`)[]
2430

31+
List of JSX attributes from opening element
32+
2533
### initialScope?
2634

2735
`Scope`
2836

37+
Optional scope for resolving variables in spread attributes
38+
2939
## Returns
3040

3141
`boolean`
42+
43+
boolean indicating whether all of the attributes exist
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / isComponentDefinition
6+
7+
# Function: isComponentDefinition()
8+
9+
> **isComponentDefinition**(`context`, `node`, `hint`): `boolean`
10+
11+
Determines if a function node represents a valid React component definition
12+
13+
## Parameters
14+
15+
### context
16+
17+
`RuleContext`
18+
19+
The rule context
20+
21+
### node
22+
23+
`TSESTreeFunction`
24+
25+
The function node to check
26+
27+
### hint
28+
29+
`bigint`
30+
31+
Component detection hints as bit flags
32+
33+
## Returns
34+
35+
`boolean`
36+
37+
`true` if the node is a valid component definition, `false` otherwise

packages/core/docs/functions/isFragmentElement.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@
88

99
> **isFragmentElement**(`context`, `node`): `node is JSXElement`
1010
11+
Determines if a JSX element is a React Fragment
12+
Fragments can be imported from React and used like <Fragment> or <React.Fragment>
13+
1114
## Parameters
1215

1316
### context
1417

1518
`RuleContext`
1619

20+
ESLint rule context
21+
1722
### node
1823

1924
`Node`
2025

26+
AST node to check
27+
2128
## Returns
2229

2330
`node is JSXElement`
31+
32+
boolean indicating if the element is a Fragment with type narrowing

0 commit comments

Comments
 (0)