Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"vite-node": "^6.0.0",
"vitest": "^4.1.10"
},
"packageManager": "pnpm@11.13.0",
"packageManager": "pnpm@11.13.1",
"engines": {
"node": ">=22.0.0"
}
Expand Down
5 changes: 3 additions & 2 deletions packages/jsx/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
| [collapseMultilineText](functions/collapseMultilineText.md) | Collapse a multiline JSX text string following React's whitespace rules. |
| [findAttribute](functions/findAttribute.md) | Find a JSX attribute (or spread attribute containing the property) by name on a given element. |
| [findParentAttribute](functions/findParentAttribute.md) | Walk up the AST from `node` to find the nearest ancestor that is a `JSXAttribute` and (optionally) passes a predicate. |
| [findSpreadProperty](functions/findSpreadProperty.md) | Find the `Property` node that provides a given key inside a spread argument. |
| [getAttributeName](functions/getAttributeName.md) | Get the stringified name of a `JSXAttribute` node. |
| [getAttributeStaticValue](functions/getAttributeStaticValue.md) | Find an attribute by name on a JSX element and collapse its value to a plain JavaScript value in a single step. |
| [getAttributeValue](functions/getAttributeValue.md) | Find an attribute by name on a JSX element and resolve its value in a single call. |
Expand All @@ -33,6 +34,6 @@
| [isEmptyStringExpression](functions/isEmptyStringExpression.md) | Check whether a JSX child node is an empty string expression (`{""}`). |
| [isFragmentElement](functions/isFragmentElement.md) | Check whether a node is a React Fragment element. |
| [isHostElement](functions/isHostElement.md) | Check whether a node is a host (intrinsic / DOM) element. |
| [isWhitespace](functions/isWhitespace.md) | Check whether a JSX child node is whitespace padding that React would trim away during rendering. |
| [isPaddingWhitespace](functions/isPaddingWhitespace.md) | Check whether a JSX child node is whitespace padding that React would trim away during rendering. |
| [isWhitespaceText](functions/isWhitespaceText.md) | Check whether a JSX child node is any whitespace-only text. |
| [resolveAttributeValue](functions/resolveAttributeValue.md) | Resolve the value of a JSX attribute (or spread attribute) into a AttributeValue descriptor that can be inspected further. |
| [resolveAttributeValue](functions/resolveAttributeValue.md) | Resolve the value of a JSX attribute (or spread attribute) into an AttributeValue descriptor that can be inspected further. |
3 changes: 2 additions & 1 deletion packages/jsx/docs/functions/findAttribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ or `undefined` when the attribute is not present.

Spread attributes are resolved when possible: if the spread argument is an identifier
that resolves to an object expression, the object's properties are searched for a matching key.
Nested object expressions and nested spread identifiers are also resolved.
Nested object expressions and nested spread identifiers are also resolved
(see [findSpreadProperty](findSpreadProperty.md)).

## Parameters

Expand Down
6 changes: 3 additions & 3 deletions packages/jsx/docs/functions/findParentAttribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Function: findParentAttribute()

```ts
function findParentAttribute(node: Node, test?: (node: JSXAttribute) => boolean): JSXAttribute | null;
function findParentAttribute(node: Node, test?: (node: JSXAttribute) => boolean): JSXAttribute | undefined;
```

Walk up the AST from `node` to find the nearest ancestor that is a `JSXAttribute`
Expand All @@ -21,6 +21,6 @@ inside an expression container) and needs to know which JSX attribute it belongs

## Returns

`JSXAttribute` \| `null`
`JSXAttribute` \| `undefined`

The first matching `JSXAttribute` ancestor, or `null` if none is found before reaching the root.
The first matching `JSXAttribute` ancestor, or `undefined` if none is found before reaching the root.
43 changes: 43 additions & 0 deletions packages/jsx/docs/functions/findSpreadProperty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[@eslint-react/jsx](../README.md) / findSpreadProperty

# Function: findSpreadProperty()

```ts
function findSpreadProperty(
context: RuleContext,
argument: Expression,
name: string,
seen?: Set<Node>,
): Property | undefined;
```

Find the `Property` node that provides a given key inside a spread argument.

This is the single resolution routine shared by [findAttribute](findAttribute.md) (existence
checks) and the `spreadProps` variant of `resolveAttributeValue` (value extraction):

- An `Identifier` argument is resolved to its initializer via variable
resolution, following alias chains (`const b = a`) like `getStaticValue`
does; an `ObjectExpression` argument is searched directly.
- Properties are walked **in reverse** so that later entries win, matching
JavaScript object semantics (`{ ...a, k: 1 }` -> the literal `k`).
- Nested `SpreadElement`s (identifiers or inline object expressions) are
searched recursively; a `seen` set guards against circular references.
- Plain identifier keys and string literal keys are matched directly;
computed keys are matched when they are statically evaluable
(ex: `{ ["class" + "Name"]: 1 }`).

## Parameters

| Parameter | Type | Description |
| ---------- | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| `context` | `RuleContext` | The ESLint rule context (needed for variable resolution). |
| `argument` | `Expression` | The spread argument expression to search. |
| `name` | `string` | The property name to look for. |
| `seen` | [`Set`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)\<`Node`\> | Internal set of already-visited nodes (cycle guard). |

## Returns

`Property` \| `undefined`

The matching `Property` node, or `undefined` when the key is not found.
8 changes: 4 additions & 4 deletions packages/jsx/docs/functions/getAttributeStaticValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ This is a convenience composition of [findAttribute](findAttribute.md) ->
[resolveAttributeValue](resolveAttributeValue.md) -> `toStatic()`, with automatic handling of the
`spreadProps` case (extracts the named property from the spread object).

Returns `null` when the attribute is absent, `undefined` when the value cannot
be statically determined (including empty expression containers), and the
resolved static value otherwise.
Returns `undefined` both when the attribute is absent and when its value
cannot be statically determined; use [findAttribute](findAttribute.md) or
[hasAttribute](hasAttribute.md) when presence itself matters.

## Parameters

Expand All @@ -33,4 +33,4 @@ resolved static value otherwise.

`unknown`

The static value of the attribute, `null` when absent, or `undefined` when indeterminate.
The static value of the attribute, or `undefined` when absent or indeterminate.
6 changes: 3 additions & 3 deletions packages/jsx/docs/functions/getAttributeValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function getAttributeValue(
context: RuleContext,
element: JSXElement,
name: string,
): AttributeValue | null;
): AttributeValue | undefined;
```

Find an attribute by name on a JSX element and resolve its value in a single call.
Expand All @@ -26,6 +26,6 @@ pattern in lint rules.

## Returns

`AttributeValue` \| `null`
`AttributeValue` \| `undefined`

A JsxAttributeValue descriptor, or `null` when the attribute is not present on the element.
An AttributeValue descriptor, or `undefined` when the attribute is not present on the element.
2 changes: 1 addition & 1 deletion packages/jsx/docs/functions/getChildren.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Mirrors Babel's `buildChildren` helper:
1. Iterate over `element.children`.
2. Skip `JSXText` nodes that clean to nothing (padding whitespace).
3. Skip `JSXExpressionContainer` nodes whose expression is empty.
4. Skip `JSXEmptyExpression` nodes.
4. Skip empty string expressions (`{""}`), which produce no DOM node.
5. Collect everything else.

## Parameters
Expand Down
1 change: 1 addition & 0 deletions packages/jsx/docs/functions/getElementFullType.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Get the string representation of a JSX element's type.
- `<div>` -> `"div"`
- `<Foo.Bar>` -> `"Foo.Bar"`
- `<React.Fragment>` -> `"React.Fragment"`
- `<xml:space>` -> `"xml:space"`
- `<></>` -> `""`.

## Parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[@eslint-react/jsx](../README.md) / isWhitespace
[@eslint-react/jsx](../README.md) / isPaddingWhitespace

# Function: isWhitespace()
# Function: isPaddingWhitespace()

```ts
function isWhitespace(node: JSXChild): boolean;
function isPaddingWhitespace(node: JSXChild): boolean;
```

Check whether a JSX child node is whitespace padding that React would
Expand All @@ -12,8 +12,10 @@ trim away during rendering.
A child is considered whitespace padding when it is a `JSXText` node whose
content is empty after applying React's whitespace normalization
(see [collapseMultilineText](collapseMultilineText.md), modelled after Babel's
`cleanJSXElementLiteralChild`). This is the whitespace that appears between
JSX tags purely for formatting.
`cleanJSXElementLiteralChild`) **and** it contains a newline. This is the
whitespace that appears between JSX tags purely for formatting.

For the looser "any whitespace-only text" check, see [isWhitespaceText](isWhitespaceText.md).

## Parameters

Expand Down
2 changes: 1 addition & 1 deletion packages/jsx/docs/functions/isWhitespaceText.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function isWhitespaceText(node: JSXChild): boolean;

Check whether a JSX child node is any whitespace-only text.

This is a looser variant of [isWhitespace](isWhitespace.md); it matches every
This is a looser variant of [isPaddingWhitespace](isPaddingWhitespace.md); it matches every
`JSXText` node whose raw content is empty after trimming, regardless of
whether it contains a newline.

Expand Down
22 changes: 16 additions & 6 deletions packages/jsx/docs/functions/resolveAttributeValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@
# Function: resolveAttributeValue()

```ts
function resolveAttributeValue(context: RuleContext, attribute: TSESTreeJSXAttributeLike): AttributeValue;
function resolveAttributeValue(
context: RuleContext,
attribute: TSESTreeJSXAttributeLike,
name?: string,
): AttributeValue;
```

Resolve the value of a JSX attribute (or spread attribute) into a
Resolve the value of a JSX attribute (or spread attribute) into an
AttributeValue descriptor that can be inspected further.

This is the low-level building block; it operates on a single attribute
node that the caller has already located. For the higher-level "find by
name and resolve" combo, see [getAttributeValue](getAttributeValue.md).

When the attribute is a `JSXSpreadAttribute`, passing `name` (typically the
same name the attribute was found by) makes `toStatic()` return the static
value of that named property, eliminating the need to branch on
`kind === "spreadProps"` at the call site.

## Parameters

| Parameter | Type | Description |
| ----------- | -------------------------- | ---------------------------------------------------- |
| `context` | `RuleContext` | The ESLint rule context (needed for scope look-ups). |
| `attribute` | `TSESTreeJSXAttributeLike` | A `JSXAttribute` or `JSXSpreadAttribute` node. |
| Parameter | Type | Description |
| ----------- | -------------------------- | -------------------------------------------------------------------------- |
| `context` | `RuleContext` | The ESLint rule context (needed for scope look-ups). |
| `attribute` | `TSESTreeJSXAttributeLike` | A `JSXAttribute` or `JSXSpreadAttribute` node. |
| `name?` | `string` | Optional property name used to resolve `toStatic()` for spread attributes. |

## Returns

Expand Down
Loading
Loading