@eslint-react/jsx 5.17.1 → 5.17.3

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +194 -228
  2. package/dist/index.js +610 -657
  3. package/package.json +8 -7
package/dist/index.d.ts CHANGED
@@ -1,23 +1,7 @@
1
1
  import { TSESTreeJSXAttributeLike, TSESTreeJSXElementLike } from "@eslint-react/ast";
2
2
  import { TSESTree } from "@typescript-eslint/types";
3
3
  import { RuleContext } from "@eslint-react/eslint";
4
- //#region src/collapse-multiline-text.d.ts
5
- /**
6
- * Collapse a multiline JSX text string following React's whitespace rules.
7
- *
8
- * This mirrors Babel's `cleanJSXElementLiteralChild` algorithm:
9
- * 1. Split the raw text into lines.
10
- * 2. Find the last non-empty line.
11
- * 3. Trim leading spaces on non-first lines and trailing spaces on non-last lines.
12
- * 4. Collapse tabs into spaces.
13
- * 5. Append a single space after each non-last non-empty line.
14
- * @param text The raw JSX text string to collapse.
15
- * @returns The collapsed string, or `null` if the text contains only whitespace.
16
- * @see https://github.com/babel/babel/blob/main/packages/babel-types/src/utils/react/cleanJSXElementLiteralChild.ts
17
- */
18
- declare function collapseMultilineText(text: string): string | null;
19
- //#endregion
20
- //#region src/find-attribute.d.ts
4
+ //#region src/attribute-find.d.ts
21
5
  /**
22
6
  * Find a JSX attribute (or spread attribute containing the property) by name on a given element.
23
7
  *
@@ -26,15 +10,14 @@ declare function collapseMultilineText(text: string): string | null;
26
10
  *
27
11
  * Spread attributes are resolved when possible: if the spread argument is an identifier
28
12
  * that resolves to an object expression, the object's properties are searched for a matching key.
29
- * Nested object expressions and nested spread identifiers are also resolved.
13
+ * Nested object expressions and nested spread identifiers are also resolved
14
+ * (see {@link findSpreadProperty}).
30
15
  * @param context The ESLint rule context (needed for variable resolution in spread attributes).
31
16
  * @param element The `JSXElement` node to search.
32
17
  * @param name The attribute name to look for (ex: "className").
33
18
  * @returns The matching `JSXAttribute` or `JSXSpreadAttribute`, or `undefined` when not found.
34
19
  */
35
20
  declare function findAttribute(context: RuleContext, element: TSESTree.JSXElement, name: string): TSESTreeJSXAttributeLike | undefined;
36
- //#endregion
37
- //#region src/find-parent-attribute.d.ts
38
21
  /**
39
22
  * Walk up the AST from `node` to find the nearest ancestor that is a `JSXAttribute`
40
23
  * and (optionally) passes a predicate.
@@ -43,11 +26,76 @@ declare function findAttribute(context: RuleContext, element: TSESTree.JSXElemen
43
26
  * inside an expression container) and needs to know which JSX attribute it belongs to.
44
27
  * @param node The starting node for the upward search.
45
28
  * @param test Optional predicate to filter candidate `JSXAttribute` nodes. When omitted every `JSXAttribute` ancestor matches.
46
- * @returns The first matching `JSXAttribute` ancestor, or `null` if none is found before reaching the root.
29
+ * @returns The first matching `JSXAttribute` ancestor, or `undefined` if none is found before reaching the root.
30
+ */
31
+ declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | undefined;
32
+ /**
33
+ * Find the `Property` node that provides a given key inside a spread argument.
34
+ *
35
+ * This is the single resolution routine shared by {@link findAttribute} (existence
36
+ * checks) and the `spreadProps` variant of `resolveAttributeValue` (value extraction):
37
+ *
38
+ * - An `Identifier` argument is resolved to its initializer via variable
39
+ * resolution, following alias chains (`const b = a`) like `getStaticValue`
40
+ * does; an `ObjectExpression` argument is searched directly.
41
+ * - Properties are walked **in reverse** so that later entries win, matching
42
+ * JavaScript object semantics (`{ ...a, k: 1 }` -> the literal `k`).
43
+ * - Nested `SpreadElement`s (identifiers or inline object expressions) are
44
+ * searched recursively; a `seen` set guards against circular references.
45
+ * - Plain identifier keys and string literal keys are matched directly;
46
+ * computed keys are matched when they are statically evaluable
47
+ * (ex: `{ ["class" + "Name"]: 1 }`).
48
+ * @param context The ESLint rule context (needed for variable resolution).
49
+ * @param argument The spread argument expression to search.
50
+ * @param name The property name to look for.
51
+ * @param seen Internal set of already-visited nodes (cycle guard).
52
+ * @returns The matching `Property` node, or `undefined` when the key is not found.
53
+ */
54
+ declare function findSpreadProperty(context: RuleContext, argument: TSESTree.Expression, name: string, seen?: Set<TSESTree.Node>): TSESTree.Property | undefined;
55
+ //#endregion
56
+ //#region src/attribute-has.d.ts
57
+ /**
58
+ * Check whether a JSX element carries a given attribute (prop).
59
+ *
60
+ * This is a thin convenience wrapper around {@link findAttribute} for the
61
+ * common case where you only need a boolean answer.
62
+ *
63
+ * Spread attributes are taken into account: `<Comp {...{ disabled: true }} />`
64
+ * will report `true` for `"disabled"`.
65
+ * @param context The ESLint rule context (needed for variable resolution in spread attributes).
66
+ * @param element The `JSXElement` node to inspect.
67
+ * @param name The attribute name to look for (ex: "className").
68
+ * @returns `true` when the attribute is present on the element.
47
69
  */
48
- declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | null;
70
+ declare function hasAttribute(context: RuleContext, element: TSESTree.JSXElement, name: string): boolean;
71
+ /**
72
+ * Check whether a JSX element carries at least one of the given attributes.
73
+ *
74
+ * This is a batch variant of {@link hasAttribute} for the common pattern of
75
+ * short-circuiting on multiple prop names.
76
+ *
77
+ * Spread attributes are taken into account (see {@link findAttribute}).
78
+ * @param context The ESLint rule context (needed for variable resolution in spread attributes).
79
+ * @param element The `JSXElement` node to inspect.
80
+ * @param names The attribute names to look for.
81
+ * @returns `true` when at least one of the attributes is present.
82
+ */
83
+ declare function hasAnyAttribute(context: RuleContext, element: TSESTree.JSXElement, names: string[]): boolean;
84
+ /**
85
+ * Check whether a JSX element carries all of the given attributes (props).
86
+ *
87
+ * This is a batch variant of {@link hasAttribute} for the common pattern
88
+ * where a rule needs to verify that a set of required props are all present.
89
+ *
90
+ * Spread attributes are taken into account (see {@link findAttribute}).
91
+ * @param context The ESLint rule context (needed for variable resolution in spread attributes).
92
+ * @param element The `JSXElement` node to inspect.
93
+ * @param names The attribute names to look for.
94
+ * @returns `true` when every name in `names` is present on the element.
95
+ */
96
+ declare function hasEveryAttribute(context: RuleContext, element: TSESTree.JSXElement, names: string[]): boolean;
49
97
  //#endregion
50
- //#region src/get-attribute-name.d.ts
98
+ //#region src/attribute-name.d.ts
51
99
  /**
52
100
  * Get the stringified name of a `JSXAttribute` node.
53
101
  *
@@ -59,81 +107,84 @@ declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree
59
107
  * @returns The attribute name as a plain string.
60
108
  */
61
109
  declare function getAttributeName(node: TSESTree.JSXAttribute): string;
62
- //#endregion
63
- //#region src/get-attribute-static-value.d.ts
64
110
  /**
65
- * Find an attribute by name on a JSX element and collapse its value to a plain
66
- * JavaScript value in a single step.
111
+ * Check whether a node is a `JSXAttribute` with the given name.
67
112
  *
68
- * This is a convenience composition of {@link findAttribute} ->
69
- * {@link resolveAttributeValue} -> `toStatic()`, with automatic handling of the
70
- * `spreadProps` case (extracts the named property from the spread object).
113
+ * Only plain identifier names are matched (ex: `className`); namespaced
114
+ * attributes (ex: `xml:space`) do not match.
71
115
  *
72
- * Returns `null` when the attribute is absent, `undefined` when the value cannot
73
- * be statically determined (including empty expression containers), and the
74
- * resolved static value otherwise.
75
- * @param context The ESLint rule context.
76
- * @param element The `JSXElement` node to inspect.
77
- * @param name The attribute name to look up (ex: "className").
78
- * @returns The static value of the attribute, `null` when absent, or `undefined` when indeterminate.
116
+ * Supports both data-first and data-last (curried) call styles:
117
+ * - `isAttribute(node, "className")`
118
+ * - `isAttribute("className")(node)`.
119
+ * @param node The AST node to test.
120
+ * @param name The attribute name to match (ex: "className").
121
+ * @returns `true` when the node is a `JSXAttribute` named `name`.
79
122
  */
80
- declare function getAttributeStaticValue(context: RuleContext, element: TSESTree.JSXElement, name: string): unknown;
123
+ declare const isAttribute: {
124
+ (name: string): (node: TSESTree.Node) => node is TSESTree.JSXAttribute;
125
+ (node: TSESTree.Node, name: string): node is TSESTree.JSXAttribute;
126
+ };
81
127
  //#endregion
82
- //#region src/jsx-attribute-value.d.ts
128
+ //#region src/attribute-value.d.ts
83
129
  /**
84
130
  * Discriminated union representing the resolved value of a JSX attribute.
85
131
  *
86
- * Each variant carries the original AST `node` (where applicable) and a
87
- * `toStatic()` helper that attempts to collapse the value into a plain
88
- * JavaScript value at analysis time.
132
+ * Each variant carries the original AST `node` (where applicable the
133
+ * `boolean` variant has no value node and reports `null`) and a `toStatic()`
134
+ * helper that attempts to collapse the value into a plain JavaScript value
135
+ * at analysis time.
136
+ *
137
+ * `toStatic()` returns `undefined` whenever no static value is available;
138
+ * structural information is carried by `kind`, value information by `toStatic()`.
89
139
  */
90
- type JsxAttributeValue = JsxAttributeValueBoolean | JsxAttributeValueElement | JsxAttributeValueLiteral | JsxAttributeValueUnknown | JsxAttributeValueMissing | JsxAttributeValueSpreadChild | JsxAttributeValueSpreadProps;
91
- /** Boolean attribute with no value (ex: `<input disabled />`). */
92
- interface JsxAttributeValueBoolean {
140
+ type AttributeValue = {
93
141
  readonly kind: "boolean";
94
142
  readonly node: null;
95
143
  toStatic(): true;
96
- }
97
- /** JSX element used as an attribute value (ex: `<Slot icon=<Icon /> />`). */
98
- interface JsxAttributeValueElement {
99
- readonly kind: "element";
100
- readonly node: TSESTree.JSXElement;
101
- toStatic(): null;
102
- }
103
- /** Literal value (ex: `<img alt="photo" />`). */
104
- interface JsxAttributeValueLiteral {
144
+ } | {
105
145
  readonly kind: "literal";
106
146
  readonly node: TSESTree.Literal;
107
147
  toStatic(): TSESTree.Literal["value"];
108
- }
109
- /** Expression container value (ex: `<Comp value={expr} />`). */
110
- interface JsxAttributeValueUnknown {
148
+ } | {
111
149
  readonly kind: "unknown";
112
- readonly node: TSESTree.JSXExpressionContainer["expression"];
150
+ readonly node: TSESTree.Expression;
113
151
  toStatic(): unknown;
114
- }
115
- /** Empty expression container (ex: `<Comp value={} />`). */
116
- interface JsxAttributeValueMissing {
152
+ } | {
153
+ readonly kind: "element";
154
+ readonly node: TSESTree.JSXElement;
155
+ toStatic(): undefined;
156
+ } | {
117
157
  readonly kind: "missing";
118
158
  readonly node: TSESTree.JSXEmptyExpression;
119
- toStatic(): null;
120
- }
121
- /** Spread child expression (ex: `{...items}` as children). */
122
- interface JsxAttributeValueSpreadChild {
159
+ toStatic(): undefined;
160
+ } | {
123
161
  readonly kind: "spreadChild";
124
- getChildren(): unknown;
125
- readonly node: TSESTree.JSXSpreadChild["expression"];
126
- toStatic(): null;
127
- }
128
- /** Spread props (ex: `<Comp {...props} />`). */
129
- interface JsxAttributeValueSpreadProps {
162
+ readonly node: TSESTree.JSXSpreadChild;
163
+ toStatic(): undefined;
164
+ } | {
130
165
  readonly kind: "spreadProps";
131
166
  getProperty(name: string): unknown;
132
167
  readonly node: TSESTree.JSXSpreadAttribute["argument"];
133
- toStatic(): null;
134
- }
135
- //#endregion
136
- //#region src/get-attribute-value.d.ts
168
+ toStatic(): unknown;
169
+ };
170
+ /**
171
+ * Resolve the value of a JSX attribute (or spread attribute) into an
172
+ * {@link AttributeValue} descriptor that can be inspected further.
173
+ *
174
+ * This is the low-level building block; it operates on a single attribute
175
+ * node that the caller has already located. For the higher-level "find by
176
+ * name and resolve" combo, see {@link getAttributeValue}.
177
+ *
178
+ * When the attribute is a `JSXSpreadAttribute`, passing `name` (typically the
179
+ * same name the attribute was found by) makes `toStatic()` return the static
180
+ * value of that named property, eliminating the need to branch on
181
+ * `kind === "spreadProps"` at the call site.
182
+ * @param context The ESLint rule context (needed for scope look-ups).
183
+ * @param attribute A `JSXAttribute` or `JSXSpreadAttribute` node.
184
+ * @param name Optional property name used to resolve `toStatic()` for spread attributes.
185
+ * @returns A discriminated-union descriptor of the attribute's value.
186
+ */
187
+ declare function resolveAttributeValue(context: RuleContext, attribute: TSESTreeJSXAttributeLike, name?: string): AttributeValue;
137
188
  /**
138
189
  * Find an attribute by name on a JSX element and resolve its value in a single call.
139
190
  *
@@ -143,11 +194,28 @@ interface JsxAttributeValueSpreadProps {
143
194
  * @param context The ESLint rule context.
144
195
  * @param element The `JSXElement` node to search.
145
196
  * @param name The attribute name to look up (ex: "className").
146
- * @returns A {@link JsxAttributeValue} descriptor, or `null` when the attribute is not present on the element.
197
+ * @returns An {@link AttributeValue} descriptor, or `undefined` when the attribute is not present on the element.
198
+ */
199
+ declare function getAttributeValue(context: RuleContext, element: TSESTree.JSXElement, name: string): AttributeValue | undefined;
200
+ /**
201
+ * Find an attribute by name on a JSX element and collapse its value to a plain
202
+ * JavaScript value in a single step.
203
+ *
204
+ * This is a convenience composition of {@link findAttribute} ->
205
+ * {@link resolveAttributeValue} -> `toStatic()`, with automatic handling of the
206
+ * `spreadProps` case (extracts the named property from the spread object).
207
+ *
208
+ * Returns `undefined` both when the attribute is absent and when its value
209
+ * cannot be statically determined; use {@link findAttribute} or
210
+ * {@link hasAttribute} when presence itself matters.
211
+ * @param context The ESLint rule context.
212
+ * @param element The `JSXElement` node to inspect.
213
+ * @param name The attribute name to look up (ex: "className").
214
+ * @returns The static value of the attribute, or `undefined` when absent or indeterminate.
147
215
  */
148
- declare function getAttributeValue(context: RuleContext, element: TSESTree.JSXElement, name: string): JsxAttributeValue | null;
216
+ declare function getAttributeStaticValue(context: RuleContext, element: TSESTree.JSXElement, name: string): unknown;
149
217
  //#endregion
150
- //#region src/get-children.d.ts
218
+ //#region src/children.d.ts
151
219
  /**
152
220
  * Get the meaningful children of a JSX element or fragment.
153
221
  *
@@ -155,68 +223,12 @@ declare function getAttributeValue(context: RuleContext, element: TSESTree.JSXEl
155
223
  * 1. Iterate over `element.children`.
156
224
  * 2. Skip `JSXText` nodes that clean to nothing (padding whitespace).
157
225
  * 3. Skip `JSXExpressionContainer` nodes whose expression is empty.
158
- * 4. Skip `JSXEmptyExpression` nodes.
226
+ * 4. Skip empty string expressions (`{""}`), which produce no DOM node.
159
227
  * 5. Collect everything else.
160
228
  * @param element A `JSXElement` or `JSXFragment` node.
161
229
  * @returns An array of children nodes that contribute to rendered output.
162
230
  */
163
231
  declare function getChildren(element: TSESTreeJSXElementLike): TSESTree.JSXChild[];
164
- //#endregion
165
- //#region src/get-element-type.d.ts
166
- /**
167
- * Get the string representation of a JSX element's type.
168
- *
169
- * - `<div>` -> `"div"`
170
- * - `<Foo.Bar>` -> `"Foo.Bar"`
171
- * - `<React.Fragment>` -> `"React.Fragment"`
172
- * - `<></>` -> `""`.
173
- * @param node A `JSXElement` or `JSXFragment` node.
174
- * @returns The fully-qualified element type string.
175
- */
176
- declare function getElementFullType(node: TSESTreeJSXElementLike): string;
177
- /**
178
- * Get the self name (last dot-separated segment) of a JSX element type.
179
- *
180
- * - `<Foo.Bar.Baz>` -> `"Baz"`
181
- * - `<div>` -> `"div"`
182
- * - `<></>` -> `""`.
183
- * @param node A `JSXElement` or `JSXFragment` node.
184
- * @returns The last segment of the element type, or `""` for fragments.
185
- */
186
- declare function getElementSelfType(node: TSESTreeJSXElementLike): string;
187
- //#endregion
188
- //#region src/has-any-attribute.d.ts
189
- /**
190
- * Check whether a JSX element carries at least one of the given attributes.
191
- *
192
- * This is a batch variant of {@link hasAttribute} for the common pattern of
193
- * short-circuiting on multiple prop names.
194
- *
195
- * Spread attributes are taken into account (see {@link findAttribute}).
196
- * @param context The ESLint rule context (needed for variable resolution in spread attributes).
197
- * @param element The `JSXElement` node to inspect.
198
- * @param names The attribute names to look for.
199
- * @returns `true` when at least one of the attributes is present.
200
- */
201
- declare function hasAnyAttribute(context: RuleContext, element: TSESTree.JSXElement, names: string[]): boolean;
202
- //#endregion
203
- //#region src/has-attribute.d.ts
204
- /**
205
- * Check whether a JSX element carries a given attribute (prop).
206
- *
207
- * This is a thin convenience wrapper around {@link findAttribute} for the
208
- * common case where you only need a boolean answer.
209
- *
210
- * Spread attributes are taken into account: `<Comp {...{ disabled: true }} />`
211
- * will report `true` for `"disabled"`.
212
- * @param context The ESLint rule context (needed for variable resolution in spread attributes).
213
- * @param element The `JSXElement` node to inspect.
214
- * @param name The attribute name to look for (ex: "className").
215
- * @returns `true` when the attribute is present on the element.
216
- */
217
- declare function hasAttribute(context: RuleContext, element: TSESTree.JSXElement, name: string): boolean;
218
- //#endregion
219
- //#region src/has-children.d.ts
220
232
  /**
221
233
  * Check whether a JSX element (or fragment) has meaningful children, that is,
222
234
  * at least one child that is not purely whitespace text or an empty string expression.
@@ -241,41 +253,7 @@ declare function hasAttribute(context: RuleContext, element: TSESTree.JSXElement
241
253
  */
242
254
  declare function hasChildren(element: TSESTreeJSXElementLike): boolean;
243
255
  //#endregion
244
- //#region src/has-every-attribute.d.ts
245
- /**
246
- * Check whether a JSX element carries all of the given attributes (props).
247
- *
248
- * This is a batch variant of {@link hasAttribute} for the common pattern
249
- * where a rule needs to verify that a set of required props are all present.
250
- *
251
- * Spread attributes are taken into account (see {@link findAttribute}).
252
- * @param context The ESLint rule context (needed for variable resolution in spread attributes).
253
- * @param element The `JSXElement` node to inspect.
254
- * @param names The attribute names to look for.
255
- * @returns `true` when every name in `names` is present on the element.
256
- */
257
- declare function hasEveryAttribute(context: RuleContext, element: TSESTree.JSXElement, names: string[]): boolean;
258
- //#endregion
259
- //#region src/is-attribute.d.ts
260
- /**
261
- * Check whether a node is a `JSXAttribute` with the given name.
262
- *
263
- * Only plain identifier names are matched (ex: `className`); namespaced
264
- * attributes (ex: `xml:space`) do not match.
265
- *
266
- * Supports both data-first and data-last (curried) call styles:
267
- * - `isAttribute(node, "className")`
268
- * - `isAttribute("className")(node)`.
269
- * @param node The AST node to test.
270
- * @param name The attribute name to match (ex: "className").
271
- * @returns `true` when the node is a `JSXAttribute` named `name`.
272
- */
273
- declare const isAttribute: {
274
- (name: string): (node: TSESTree.Node) => node is TSESTree.JSXAttribute;
275
- (node: TSESTree.Node, name: string): node is TSESTree.JSXAttribute;
276
- };
277
- //#endregion
278
- //#region src/is-element.d.ts
256
+ //#region src/element-is.d.ts
279
257
  /**
280
258
  * A test that determines whether a JSX element matches.
281
259
  *
@@ -299,8 +277,6 @@ type ElementTest = string | readonly string[] | ((elementType: string, node: TSE
299
277
  * @returns `true` when the node is a matching JSX element.
300
278
  */
301
279
  declare function isElement(node: TSESTree.Node | null | undefined, test?: ElementTest): node is TSESTreeJSXElementLike;
302
- //#endregion
303
- //#region src/is-fragment-element.d.ts
304
280
  /**
305
281
  * Check whether a node is a React Fragment element.
306
282
  *
@@ -315,8 +291,6 @@ declare function isElement(node: TSESTree.Node | null | undefined, test?: Elemen
315
291
  * @returns `true` when the node represents a React Fragment.
316
292
  */
317
293
  declare function isFragmentElement(node: TSESTree.Node, jsxFragmentFactory?: string): node is TSESTreeJSXElementLike;
318
- //#endregion
319
- //#region src/is-host-element.d.ts
320
294
  /**
321
295
  * Check whether a node is a host (intrinsic / DOM) element.
322
296
  *
@@ -328,7 +302,45 @@ declare function isFragmentElement(node: TSESTree.Node, jsxFragmentFactory?: str
328
302
  */
329
303
  declare function isHostElement(node: TSESTree.Node): node is TSESTree.JSXElement;
330
304
  //#endregion
331
- //#region src/is-whitespace.d.ts
305
+ //#region src/element-type.d.ts
306
+ /**
307
+ * Get the string representation of a JSX element's type.
308
+ *
309
+ * - `<div>` -> `"div"`
310
+ * - `<Foo.Bar>` -> `"Foo.Bar"`
311
+ * - `<React.Fragment>` -> `"React.Fragment"`
312
+ * - `<xml:space>` -> `"xml:space"`
313
+ * - `<></>` -> `""`.
314
+ * @param node A `JSXElement` or `JSXFragment` node.
315
+ * @returns The fully-qualified element type string.
316
+ */
317
+ declare function getElementFullType(node: TSESTreeJSXElementLike): string;
318
+ /**
319
+ * Get the self name (last dot-separated segment) of a JSX element type.
320
+ *
321
+ * - `<Foo.Bar.Baz>` -> `"Baz"`
322
+ * - `<div>` -> `"div"`
323
+ * - `<></>` -> `""`.
324
+ * @param node A `JSXElement` or `JSXFragment` node.
325
+ * @returns The last segment of the element type, or `""` for fragments.
326
+ */
327
+ declare function getElementSelfType(node: TSESTreeJSXElementLike): string;
328
+ //#endregion
329
+ //#region src/text.d.ts
330
+ /**
331
+ * Collapse a multiline JSX text string following React's whitespace rules.
332
+ *
333
+ * This mirrors Babel's `cleanJSXElementLiteralChild` algorithm:
334
+ * 1. Split the raw text into lines.
335
+ * 2. Find the last non-empty line.
336
+ * 3. Trim leading spaces on non-first lines and trailing spaces on non-last lines.
337
+ * 4. Collapse tabs into spaces.
338
+ * 5. Append a single space after each non-last non-empty line.
339
+ * @param text The raw JSX text string to collapse.
340
+ * @returns The collapsed string, or `null` if the text contains only whitespace.
341
+ * @see https://github.com/babel/babel/blob/main/packages/babel-types/src/utils/react/cleanJSXElementLiteralChild.ts
342
+ */
343
+ declare function collapseMultilineText(text: string): string | null;
332
344
  /**
333
345
  * Check whether a JSX child node is whitespace padding that React would
334
346
  * trim away during rendering.
@@ -336,16 +348,18 @@ declare function isHostElement(node: TSESTree.Node): node is TSESTree.JSXElement
336
348
  * A child is considered whitespace padding when it is a `JSXText` node whose
337
349
  * content is empty after applying React's whitespace normalization
338
350
  * (see {@link collapseMultilineText}, modelled after Babel's
339
- * `cleanJSXElementLiteralChild`). This is the whitespace that appears between
340
- * JSX tags purely for formatting.
351
+ * `cleanJSXElementLiteralChild`) **and** it contains a newline. This is the
352
+ * whitespace that appears between JSX tags purely for formatting.
353
+ *
354
+ * For the looser "any whitespace-only text" check, see {@link isWhitespaceText}.
341
355
  * @param node A JSX child node.
342
356
  * @returns `true` when the node is purely formatting whitespace.
343
357
  */
344
- declare function isWhitespace(node: TSESTree.JSXChild): boolean;
358
+ declare function isPaddingWhitespace(node: TSESTree.JSXChild): boolean;
345
359
  /**
346
360
  * Check whether a JSX child node is any whitespace-only text.
347
361
  *
348
- * This is a looser variant of {@link isWhitespace}; it matches every
362
+ * This is a looser variant of {@link isPaddingWhitespace}; it matches every
349
363
  * `JSXText` node whose raw content is empty after trimming, regardless of
350
364
  * whether it contains a newline.
351
365
  * @param node A JSX child node.
@@ -364,52 +378,4 @@ declare function isWhitespaceText(node: TSESTree.JSXChild): boolean;
364
378
  */
365
379
  declare function isEmptyStringExpression(node: TSESTree.JSXChild): boolean;
366
380
  //#endregion
367
- //#region src/jsx-detection-hint.d.ts
368
- /**
369
- * BitFlags for configuring JSX detection behavior.
370
- *
371
- * Used by `isJsxLike` to control which AST node kinds are considered
372
- * "JSX-like". Combine flags with the `|` operator.
373
- */
374
- type JsxDetectionHint = bigint;
375
- /**
376
- * Hints for JSX detection.
377
- */
378
- declare const JsxDetectionHint: {
379
- readonly None: 0n;
380
- readonly DoNotIncludeJsxWithNullValue: bigint;
381
- readonly DoNotIncludeJsxWithNumberValue: bigint;
382
- readonly DoNotIncludeJsxWithBigIntValue: bigint;
383
- readonly DoNotIncludeJsxWithStringValue: bigint;
384
- readonly DoNotIncludeJsxWithBooleanValue: bigint;
385
- readonly DoNotIncludeJsxWithUndefinedValue: bigint;
386
- readonly DoNotIncludeJsxWithEmptyArrayValue: bigint;
387
- readonly DoNotIncludeJsxWithCreateElementValue: bigint;
388
- readonly RequireAllArrayElementsToBeJsx: bigint;
389
- readonly RequireBothSidesOfLogicalExpressionToBeJsx: bigint;
390
- readonly RequireBothBranchesOfConditionalExpressionToBeJsx: bigint;
391
- };
392
- /**
393
- * Default JSX detection hint.
394
- *
395
- * Skips number, bigint, boolean, string, and undefined literals,
396
- * the value types that are commonly returned alongside JSX in React
397
- * components but are not themselves renderable elements.
398
- */
399
- declare const DEFAULT_JSX_DETECTION_HINT: JsxDetectionHint;
400
- //#endregion
401
- //#region src/resolve-attribute-value.d.ts
402
- /**
403
- * Resolve the value of a JSX attribute (or spread attribute) into a
404
- * {@link JsxAttributeValue} descriptor that can be inspected further.
405
- *
406
- * This is the low-level building block; it operates on a single attribute
407
- * node that the caller has already located. For the higher-level "find by
408
- * name and resolve" combo, see {@link getAttributeValue}.
409
- * @param context The ESLint rule context (needed for scope look-ups).
410
- * @param attribute A `JSXAttribute` or `JSXSpreadAttribute` node.
411
- * @returns A discriminated-union descriptor of the attribute's value.
412
- */
413
- declare function resolveAttributeValue(context: RuleContext, attribute: TSESTreeJSXAttributeLike): JsxAttributeValue;
414
- //#endregion
415
- export { DEFAULT_JSX_DETECTION_HINT, ElementTest, JsxAttributeValue, JsxDetectionHint, collapseMultilineText, findAttribute, findParentAttribute, getAttributeName, getAttributeStaticValue, getAttributeValue, getChildren, getElementFullType, getElementSelfType, hasAnyAttribute, hasAttribute, hasChildren, hasEveryAttribute, isAttribute, isElement, isEmptyStringExpression, isFragmentElement, isHostElement, isWhitespace, isWhitespaceText, resolveAttributeValue };
381
+ export { type ElementTest, collapseMultilineText, findAttribute, findParentAttribute, findSpreadProperty, getAttributeName, getAttributeStaticValue, getAttributeValue, getChildren, getElementFullType, getElementSelfType, hasAnyAttribute, hasAttribute, hasChildren, hasEveryAttribute, isAttribute, isElement, isEmptyStringExpression, isFragmentElement, isHostElement, isPaddingWhitespace, isWhitespaceText, resolveAttributeValue };