Skip to content

Commit 03e7627

Browse files
committed
Minor docs improvements
1 parent 9eab2e7 commit 03e7627

File tree

20 files changed

+127
-97
lines changed

20 files changed

+127
-97
lines changed

packages/core/docs/functions/isReactAPI.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
function isReactAPI(api: string): ReturnType;
77
```
88

9+
Checks if the node is a React API identifier or member expression
10+
911
## Parameters
1012

11-
| Parameter | Type |
12-
| ------ | ------ |
13-
| `api` | `string` |
13+
| Parameter | Type | Description |
14+
| ------ | ------ | ------ |
15+
| `api` | `string` | The React API name to check against (e.g., "useState", "React.memo") |
1416

1517
## Returns
1618

1719
[`ReturnType`](../@eslint-react/namespaces/isReactAPI/type-aliases/ReturnType.md)
20+
21+
A predicate function to check if a node matches the API

packages/core/docs/functions/isReactAPICall.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
function isReactAPICall(api: string): ReturnType;
77
```
88

9+
Checks if the node is a call expression to a specific React API
10+
911
## Parameters
1012

11-
| Parameter | Type |
12-
| ------ | ------ |
13-
| `api` | `string` |
13+
| Parameter | Type | Description |
14+
| ------ | ------ | ------ |
15+
| `api` | `string` | The React API name to check against |
1416

1517
## Returns
1618

1719
[`ReturnType`](../@eslint-react/namespaces/isReactAPICall/type-aliases/ReturnType.md)
20+
21+
A predicate function to check if a node is a call to the API

packages/core/src/component/component-collector-legacy.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export function useComponentCollectorLegacy(): useComponentCollectorLegacy.Retur
7070

7171
/**
7272
* Check whether the given node is a this.setState() call
73-
* @param node - The node to check
73+
* @param node The node to check
74+
* @param node
7475
* @internal
7576
*/
7677
export function isThisSetState(node: TSESTree.CallExpression) {
@@ -85,7 +86,8 @@ export function isThisSetState(node: TSESTree.CallExpression) {
8586

8687
/**
8788
* Check whether the given node is an assignment to this.state
88-
* @param node - The node to check
89+
* @param node The node to check
90+
* @param node
8991
* @internal
9092
*/
9193
export function isAssignmentToThisState(node: TSESTree.AssignmentExpression) {

packages/core/src/component/component-definition.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const FUNCTION_PATTERNS = {
3535
/**
3636
* Checks if the given node is a function within a render method of a class component.
3737
*
38-
* @param node - The AST node to check
38+
* @param node The AST node to check
39+
* @param node
3940
* @returns `true` if the node is a render function inside a class component
4041
*
4142
* @example
@@ -60,8 +61,10 @@ function isFunctionOfRenderMethod(node: AST.TSESTreeFunction) {
6061
/**
6162
* Checks if a function node should be excluded based on provided detection hints
6263
*
63-
* @param node - The function node to check
64-
* @param hint - Component detection hints as bit flags
64+
* @param node The function node to check
65+
* @param hint Component detection hints as bit flags
66+
* @param node
67+
* @param hint
6568
* @returns `true` if the function matches an exclusion hint
6669
*/
6770
function shouldExcludeBasedOnHint(node: AST.TSESTreeFunction, hint: bigint): boolean {
@@ -87,8 +90,10 @@ function shouldExcludeBasedOnHint(node: AST.TSESTreeFunction, hint: bigint): boo
8790
/**
8891
* Determines if the node is an argument within `createElement`'s children list (3rd argument onwards)
8992
*
90-
* @param context - The rule context
91-
* @param node - The AST node to check
93+
* @param context The rule context
94+
* @param node The AST node to check
95+
* @param context
96+
* @param node
9297
* @returns `true` if the node is passed as a child to `createElement`
9398
*/
9499
function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.Node): boolean {
@@ -111,9 +116,12 @@ function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.Node): b
111116
/**
112117
* Determines if a function node represents a valid React component definition
113118
*
114-
* @param context - The rule context
115-
* @param node - The function node to analyze
116-
* @param hint - Component detection hints (bit flags) to customize detection logic
119+
* @param context The rule context
120+
* @param node The function node to analyze
121+
* @param hint Component detection hints (bit flags) to customize detection logic
122+
* @param context
123+
* @param node
124+
* @param hint
117125
* @returns `true` if the node is considered a component definition
118126
*/
119127
export function isComponentDefinition(

packages/core/src/component/component-name.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ import { getFunctionComponentId } from "./component-id";
77

88
/**
99
* Check if a string matches the strict component name pattern
10-
* @param name - The name to check
10+
* @param name The name to check
1111
*/
1212
export function isComponentName(name: string) {
1313
return RE_COMPONENT_NAME.test(name);
1414
}
1515

1616
/**
1717
* Check if a string matches the loose component name pattern
18-
* @param name - The name to check
18+
* @param name The name to check
1919
*/
2020
export function isComponentNameLoose(name: string) {
2121
return RE_COMPONENT_NAME_LOOSE.test(name);
2222
}
2323

2424
/**
2525
* Get component name from an identifier or identifier sequence (e.g., MemberExpression)
26-
* @param id - The identifier or identifier sequence
26+
* @param id The identifier or identifier sequence
2727
*/
2828
export function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identifier[] | unit) {
2929
if (id == null) return unit;
@@ -34,8 +34,8 @@ export function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identi
3434

3535
/**
3636
* Check if the function has no name or a loose component name
37-
* @param context - The rule context
38-
* @param fn - The function node
37+
* @param context The rule context
38+
* @param fn The function node
3939
*/
4040
export function hasNoneOrLooseComponentName(context: RuleContext, fn: AST.TSESTreeFunction) {
4141
const id = getFunctionComponentId(context, fn);

packages/core/src/jsx/jsx-element-is.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { getJsxElementType } from "./jsx-element-type";
77
* Determines if a JSX element is a host element
88
* Host elements in React start with lowercase letters (e.g., div, span)
99
*
10-
* @param context - ESLint rule context
11-
* @param node - AST node to check
10+
* @param context ESLint rule context
11+
* @param node AST node to check
1212
* @returns boolean indicating if the element is a host element
1313
*/
1414
export function isJsxHostElement(context: RuleContext, node: TSESTree.Node) {
@@ -21,8 +21,8 @@ export function isJsxHostElement(context: RuleContext, node: TSESTree.Node) {
2121
* Determines if a JSX element is a React Fragment
2222
* Fragments can be imported from React and used like <Fragment> or <React.Fragment>
2323
*
24-
* @param context - ESLint rule context
25-
* @param node - AST node to check
24+
* @param context ESLint rule context
25+
* @param node AST node to check
2626
* @returns boolean indicating if the element is a Fragment with type narrowing
2727
*/
2828
export function isJsxFragmentElement(context: RuleContext, node: TSESTree.Node): node is TSESTree.JSXElement {

packages/core/src/jsx/jsx-element-type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { stringifyJsx } from "./jsx-stringify";
88
* For JSX elements, returns the stringified name (e.g., "div", "Button", "React.Fragment")
99
* For JSX fragments, returns an empty string
1010
*
11-
* @param context - ESLint rule context
12-
* @param node - JSX element or fragment node
11+
* @param context ESLint rule context
12+
* @param node JSX element or fragment node
1313
* @returns String representation of the element type
1414
*/
1515
export function getJsxElementType(context: RuleContext, node: TSESTree.JSXElement | TSESTree.JSXFragment) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
77
/**
88
* Traverses up the AST to find a parent JSX attribute node that matches a given test
99
*
10-
* @param node - The starting AST node
11-
* @param test - Optional predicate function to test if the attribute meets criteria
10+
* @param node The starting AST node
11+
* @param test Optional predicate function to test if the attribute meets criteria
1212
* Defaults to always returning true (matches any attribute)
1313
* @returns The first matching JSX attribute node found when traversing upwards, or undefined
1414
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { TSESTree } from "@typescript-eslint/utils";
44
/**
55
* Incomplete but sufficient stringification of JSX nodes for common use cases
66
*
7-
* @param node - JSX node from TypeScript ESTree
7+
* @param node JSX node from TypeScript ESTree
88
* @returns String representation of the JSX node
99
*/
1010
export function stringifyJsx(

packages/core/src/utils/is-react-api.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export declare namespace isReactAPI {
1313
};
1414
}
1515

16+
/**
17+
* Checks if the node is a React API identifier or member expression
18+
* @param api The React API name to check against (e.g., "useState", "React.memo")
19+
* @returns A predicate function to check if a node matches the API
20+
*/
1621
export function isReactAPI(api: string): isReactAPI.ReturnType {
1722
const func = (context: RuleContext, node: unit | null | TSESTree.Node): node is
1823
| TSESTree.Identifier
@@ -35,6 +40,11 @@ export declare namespace isReactAPICall {
3540
};
3641
}
3742

43+
/**
44+
* Checks if the node is a call expression to a specific React API
45+
* @param api The React API name to check against
46+
* @returns A predicate function to check if a node is a call to the API
47+
*/
3848
export function isReactAPICall(api: string): isReactAPICall.ReturnType {
3949
const func = (context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.CallExpression => {
4050
if (node == null) return false;
@@ -44,6 +54,7 @@ export function isReactAPICall(api: string): isReactAPICall.ReturnType {
4454
return dual(2, func);
4555
}
4656

57+
// React API checks
4758
export const isCaptureOwnerStack = isReactAPI("captureOwnerStack");
4859
export const isChildrenCount = isReactAPI("Children.count");
4960
export const isChildrenForEach = isReactAPI("Children.forEach");
@@ -58,6 +69,7 @@ export const isForwardRef = isReactAPI("forwardRef");
5869
export const isMemo = isReactAPI("memo");
5970
export const isLazy = isReactAPI("lazy");
6071

72+
// React API Call checks
6173
export const isCaptureOwnerStackCall = isReactAPICall("captureOwnerStack");
6274
export const isChildrenCountCall = isReactAPICall("Children.count");
6375
export const isChildrenForEachCall = isReactAPICall("Children.forEach");

0 commit comments

Comments
 (0)