@eslint-react/jsx 5.16.1 → 5.17.1
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.
- package/dist/index.d.ts +112 -93
- package/dist/index.js +575 -82
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { TSESTree } from "@typescript-eslint/types";
|
|
|
3
3
|
import { RuleContext } from "@eslint-react/eslint";
|
|
4
4
|
//#region src/collapse-multiline-text.d.ts
|
|
5
5
|
/**
|
|
6
|
-
* Collapse a multiline JSX text string following React's whitespace rules
|
|
6
|
+
* Collapse a multiline JSX text string following React's whitespace rules.
|
|
7
7
|
*
|
|
8
8
|
* This mirrors Babel's `cleanJSXElementLiteralChild` algorithm:
|
|
9
9
|
* 1. Split the raw text into lines.
|
|
@@ -11,15 +11,15 @@ import { RuleContext } from "@eslint-react/eslint";
|
|
|
11
11
|
* 3. Trim leading spaces on non-first lines and trailing spaces on non-last lines.
|
|
12
12
|
* 4. Collapse tabs into spaces.
|
|
13
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
|
|
14
|
+
* @param text The raw JSX text string to collapse.
|
|
15
|
+
* @returns The collapsed string, or `null` if the text contains only whitespace.
|
|
16
16
|
* @see https://github.com/babel/babel/blob/main/packages/babel-types/src/utils/react/cleanJSXElementLiteralChild.ts
|
|
17
17
|
*/
|
|
18
18
|
declare function collapseMultilineText(text: string): string | null;
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/find-attribute.d.ts
|
|
21
21
|
/**
|
|
22
|
-
* Find a JSX attribute (or spread attribute containing the property) by name on a given element
|
|
22
|
+
* Find a JSX attribute (or spread attribute containing the property) by name on a given element.
|
|
23
23
|
*
|
|
24
24
|
* Returns the last matching attribute to mirror React's behavior where later props win,
|
|
25
25
|
* or `undefined` when the attribute is not present.
|
|
@@ -27,43 +27,43 @@ declare function collapseMultilineText(text: string): string | null;
|
|
|
27
27
|
* Spread attributes are resolved when possible: if the spread argument is an identifier
|
|
28
28
|
* that resolves to an object expression, the object's properties are searched for a matching key.
|
|
29
29
|
* Nested object expressions and nested spread identifiers are also resolved.
|
|
30
|
-
* @param context The ESLint rule context (needed for variable resolution in spread attributes)
|
|
31
|
-
* @param element The `JSXElement` node to search
|
|
32
|
-
* @param name The attribute name to look for (ex: "className")
|
|
33
|
-
* @returns The matching `JSXAttribute` or `JSXSpreadAttribute`, or `undefined` when not found
|
|
30
|
+
* @param context The ESLint rule context (needed for variable resolution in spread attributes).
|
|
31
|
+
* @param element The `JSXElement` node to search.
|
|
32
|
+
* @param name The attribute name to look for (ex: "className").
|
|
33
|
+
* @returns The matching `JSXAttribute` or `JSXSpreadAttribute`, or `undefined` when not found.
|
|
34
34
|
*/
|
|
35
35
|
declare function findAttribute(context: RuleContext, element: TSESTree.JSXElement, name: string): TSESTreeJSXAttributeLike | undefined;
|
|
36
36
|
//#endregion
|
|
37
37
|
//#region src/find-parent-attribute.d.ts
|
|
38
38
|
/**
|
|
39
39
|
* Walk up the AST from `node` to find the nearest ancestor that is a `JSXAttribute`
|
|
40
|
-
* and (optionally) passes a predicate
|
|
40
|
+
* and (optionally) passes a predicate.
|
|
41
41
|
*
|
|
42
42
|
* This is useful when a rule visitor enters a deeply nested node (ex: a `Literal`
|
|
43
43
|
* inside an expression container) and needs to know which JSX attribute it belongs to.
|
|
44
|
-
* @param node The starting node for the upward search
|
|
45
|
-
* @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
|
|
44
|
+
* @param node The starting node for the upward search.
|
|
45
|
+
* @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.
|
|
47
47
|
*/
|
|
48
48
|
declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | null;
|
|
49
49
|
//#endregion
|
|
50
50
|
//#region src/get-attribute-name.d.ts
|
|
51
51
|
/**
|
|
52
|
-
* Get the stringified name of a `JSXAttribute` node
|
|
52
|
+
* Get the stringified name of a `JSXAttribute` node.
|
|
53
53
|
*
|
|
54
54
|
* Handles both simple identifiers and namespaced names:
|
|
55
55
|
* - `className` -> `"className"`
|
|
56
56
|
* - `aria-label` -> `"aria-label"`
|
|
57
|
-
* - `xml:space` -> `"xml:space"
|
|
58
|
-
* @param node A `JSXAttribute` AST node
|
|
59
|
-
* @returns The attribute name as a plain string
|
|
57
|
+
* - `xml:space` -> `"xml:space"`.
|
|
58
|
+
* @param node A `JSXAttribute` AST node.
|
|
59
|
+
* @returns The attribute name as a plain string.
|
|
60
60
|
*/
|
|
61
61
|
declare function getAttributeName(node: TSESTree.JSXAttribute): string;
|
|
62
62
|
//#endregion
|
|
63
63
|
//#region src/get-attribute-static-value.d.ts
|
|
64
64
|
/**
|
|
65
65
|
* Find an attribute by name on a JSX element and collapse its value to a plain
|
|
66
|
-
* JavaScript value in a single step
|
|
66
|
+
* JavaScript value in a single step.
|
|
67
67
|
*
|
|
68
68
|
* This is a convenience composition of {@link findAttribute} ->
|
|
69
69
|
* {@link resolveAttributeValue} -> `toStatic()`, with automatic handling of the
|
|
@@ -72,60 +72,60 @@ declare function getAttributeName(node: TSESTree.JSXAttribute): string;
|
|
|
72
72
|
* Returns `null` when the attribute is absent, `undefined` when the value cannot
|
|
73
73
|
* be statically determined (including empty expression containers), and the
|
|
74
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
|
|
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.
|
|
79
79
|
*/
|
|
80
80
|
declare function getAttributeStaticValue(context: RuleContext, element: TSESTree.JSXElement, name: string): unknown;
|
|
81
81
|
//#endregion
|
|
82
82
|
//#region src/jsx-attribute-value.d.ts
|
|
83
83
|
/**
|
|
84
|
-
* Discriminated union representing the resolved value of a JSX attribute
|
|
84
|
+
* Discriminated union representing the resolved value of a JSX attribute.
|
|
85
85
|
*
|
|
86
86
|
* Each variant carries the original AST `node` (where applicable) and a
|
|
87
87
|
* `toStatic()` helper that attempts to collapse the value into a plain
|
|
88
88
|
* JavaScript value at analysis time.
|
|
89
89
|
*/
|
|
90
90
|
type JsxAttributeValue = JsxAttributeValueBoolean | JsxAttributeValueElement | JsxAttributeValueLiteral | JsxAttributeValueUnknown | JsxAttributeValueMissing | JsxAttributeValueSpreadChild | JsxAttributeValueSpreadProps;
|
|
91
|
-
/** Boolean attribute with no value (ex: `<input disabled />`) */
|
|
91
|
+
/** Boolean attribute with no value (ex: `<input disabled />`). */
|
|
92
92
|
interface JsxAttributeValueBoolean {
|
|
93
93
|
readonly kind: "boolean";
|
|
94
94
|
readonly node: null;
|
|
95
95
|
toStatic(): true;
|
|
96
96
|
}
|
|
97
|
-
/** JSX element used as an attribute value (ex: `<Slot icon=<Icon /> />`) */
|
|
97
|
+
/** JSX element used as an attribute value (ex: `<Slot icon=<Icon /> />`). */
|
|
98
98
|
interface JsxAttributeValueElement {
|
|
99
99
|
readonly kind: "element";
|
|
100
100
|
readonly node: TSESTree.JSXElement;
|
|
101
101
|
toStatic(): null;
|
|
102
102
|
}
|
|
103
|
-
/** Literal value (ex: `<img alt="photo" />`) */
|
|
103
|
+
/** Literal value (ex: `<img alt="photo" />`). */
|
|
104
104
|
interface JsxAttributeValueLiteral {
|
|
105
105
|
readonly kind: "literal";
|
|
106
106
|
readonly node: TSESTree.Literal;
|
|
107
107
|
toStatic(): TSESTree.Literal["value"];
|
|
108
108
|
}
|
|
109
|
-
/** Expression container value (ex: `<Comp value={expr} />`) */
|
|
109
|
+
/** Expression container value (ex: `<Comp value={expr} />`). */
|
|
110
110
|
interface JsxAttributeValueUnknown {
|
|
111
111
|
readonly kind: "unknown";
|
|
112
112
|
readonly node: TSESTree.JSXExpressionContainer["expression"];
|
|
113
113
|
toStatic(): unknown;
|
|
114
114
|
}
|
|
115
|
-
/** Empty expression container (ex: `<Comp value={} />`) */
|
|
115
|
+
/** Empty expression container (ex: `<Comp value={} />`). */
|
|
116
116
|
interface JsxAttributeValueMissing {
|
|
117
117
|
readonly kind: "missing";
|
|
118
118
|
readonly node: TSESTree.JSXEmptyExpression;
|
|
119
119
|
toStatic(): null;
|
|
120
120
|
}
|
|
121
|
-
/** Spread child expression (ex: `{...items}` as children) */
|
|
121
|
+
/** Spread child expression (ex: `{...items}` as children). */
|
|
122
122
|
interface JsxAttributeValueSpreadChild {
|
|
123
123
|
readonly kind: "spreadChild";
|
|
124
124
|
getChildren(): unknown;
|
|
125
125
|
readonly node: TSESTree.JSXSpreadChild["expression"];
|
|
126
126
|
toStatic(): null;
|
|
127
127
|
}
|
|
128
|
-
/** Spread props (ex: `<Comp {...props} />`) */
|
|
128
|
+
/** Spread props (ex: `<Comp {...props} />`). */
|
|
129
129
|
interface JsxAttributeValueSpreadProps {
|
|
130
130
|
readonly kind: "spreadProps";
|
|
131
131
|
getProperty(name: string): unknown;
|
|
@@ -135,21 +135,21 @@ interface JsxAttributeValueSpreadProps {
|
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region src/get-attribute-value.d.ts
|
|
137
137
|
/**
|
|
138
|
-
* Find an attribute by name on a JSX element and resolve its value in a single call
|
|
138
|
+
* Find an attribute by name on a JSX element and resolve its value in a single call.
|
|
139
139
|
*
|
|
140
140
|
* This is a convenience composition of {@link findAttribute} and
|
|
141
141
|
* {@link resolveAttributeValue} that eliminates the most common two-step
|
|
142
142
|
* pattern in lint rules.
|
|
143
|
-
* @param context The ESLint rule context
|
|
144
|
-
* @param element The `JSXElement` node to search
|
|
145
|
-
* @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
|
|
143
|
+
* @param context The ESLint rule context.
|
|
144
|
+
* @param element The `JSXElement` node to search.
|
|
145
|
+
* @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.
|
|
147
147
|
*/
|
|
148
148
|
declare function getAttributeValue(context: RuleContext, element: TSESTree.JSXElement, name: string): JsxAttributeValue | null;
|
|
149
149
|
//#endregion
|
|
150
150
|
//#region src/get-children.d.ts
|
|
151
151
|
/**
|
|
152
|
-
* Get the meaningful children of a JSX element or fragment
|
|
152
|
+
* Get the meaningful children of a JSX element or fragment.
|
|
153
153
|
*
|
|
154
154
|
* Mirrors Babel's `buildChildren` helper:
|
|
155
155
|
* 1. Iterate over `element.children`.
|
|
@@ -157,69 +157,69 @@ declare function getAttributeValue(context: RuleContext, element: TSESTree.JSXEl
|
|
|
157
157
|
* 3. Skip `JSXExpressionContainer` nodes whose expression is empty.
|
|
158
158
|
* 4. Skip `JSXEmptyExpression` nodes.
|
|
159
159
|
* 5. Collect everything else.
|
|
160
|
-
* @param element A `JSXElement` or `JSXFragment` node
|
|
161
|
-
* @returns An array of children nodes that contribute to rendered output
|
|
160
|
+
* @param element A `JSXElement` or `JSXFragment` node.
|
|
161
|
+
* @returns An array of children nodes that contribute to rendered output.
|
|
162
162
|
*/
|
|
163
163
|
declare function getChildren(element: TSESTreeJSXElementLike): TSESTree.JSXChild[];
|
|
164
164
|
//#endregion
|
|
165
165
|
//#region src/get-element-type.d.ts
|
|
166
166
|
/**
|
|
167
|
-
* Get the string representation of a JSX element's type
|
|
167
|
+
* Get the string representation of a JSX element's type.
|
|
168
168
|
*
|
|
169
169
|
* - `<div>` -> `"div"`
|
|
170
170
|
* - `<Foo.Bar>` -> `"Foo.Bar"`
|
|
171
171
|
* - `<React.Fragment>` -> `"React.Fragment"`
|
|
172
|
-
* - `<></>` -> `""
|
|
173
|
-
* @param node A `JSXElement` or `JSXFragment` node
|
|
174
|
-
* @returns The fully-qualified element type string
|
|
172
|
+
* - `<></>` -> `""`.
|
|
173
|
+
* @param node A `JSXElement` or `JSXFragment` node.
|
|
174
|
+
* @returns The fully-qualified element type string.
|
|
175
175
|
*/
|
|
176
176
|
declare function getElementFullType(node: TSESTreeJSXElementLike): string;
|
|
177
177
|
/**
|
|
178
|
-
* Get the self name (last dot-separated segment) of a JSX element type
|
|
178
|
+
* Get the self name (last dot-separated segment) of a JSX element type.
|
|
179
179
|
*
|
|
180
180
|
* - `<Foo.Bar.Baz>` -> `"Baz"`
|
|
181
181
|
* - `<div>` -> `"div"`
|
|
182
|
-
* - `<></>` -> `""
|
|
183
|
-
* @param node A `JSXElement` or `JSXFragment` node
|
|
184
|
-
* @returns The last segment of the element type, or `""` for fragments
|
|
182
|
+
* - `<></>` -> `""`.
|
|
183
|
+
* @param node A `JSXElement` or `JSXFragment` node.
|
|
184
|
+
* @returns The last segment of the element type, or `""` for fragments.
|
|
185
185
|
*/
|
|
186
186
|
declare function getElementSelfType(node: TSESTreeJSXElementLike): string;
|
|
187
187
|
//#endregion
|
|
188
188
|
//#region src/has-any-attribute.d.ts
|
|
189
189
|
/**
|
|
190
|
-
* Check whether a JSX element carries at least one of the given attributes
|
|
190
|
+
* Check whether a JSX element carries at least one of the given attributes.
|
|
191
191
|
*
|
|
192
192
|
* This is a batch variant of {@link hasAttribute} for the common pattern of
|
|
193
193
|
* short-circuiting on multiple prop names.
|
|
194
194
|
*
|
|
195
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
|
|
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
200
|
*/
|
|
201
201
|
declare function hasAnyAttribute(context: RuleContext, element: TSESTree.JSXElement, names: string[]): boolean;
|
|
202
202
|
//#endregion
|
|
203
203
|
//#region src/has-attribute.d.ts
|
|
204
204
|
/**
|
|
205
|
-
* Check whether a JSX element carries a given attribute (prop)
|
|
205
|
+
* Check whether a JSX element carries a given attribute (prop).
|
|
206
206
|
*
|
|
207
207
|
* This is a thin convenience wrapper around {@link findAttribute} for the
|
|
208
208
|
* common case where you only need a boolean answer.
|
|
209
209
|
*
|
|
210
210
|
* Spread attributes are taken into account: `<Comp {...{ disabled: true }} />`
|
|
211
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
|
|
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
216
|
*/
|
|
217
217
|
declare function hasAttribute(context: RuleContext, element: TSESTree.JSXElement, name: string): boolean;
|
|
218
218
|
//#endregion
|
|
219
219
|
//#region src/has-children.d.ts
|
|
220
220
|
/**
|
|
221
221
|
* Check whether a JSX element (or fragment) has meaningful children, that is,
|
|
222
|
-
* at least one child that is not purely whitespace text or an empty string expression
|
|
222
|
+
* at least one child that is not purely whitespace text or an empty string expression.
|
|
223
223
|
*
|
|
224
224
|
* A `JSXText` child whose `raw` content is empty after trimming is considered
|
|
225
225
|
* non-meaningful because it is typically a code-formatting artifact
|
|
@@ -236,38 +236,57 @@ declare function hasAttribute(context: RuleContext, element: TSESTree.JSXElement
|
|
|
236
236
|
* always equal to `getChildren(node).length > 0`: they differ for
|
|
237
237
|
* whitespace-only children that have no newline, such as `<div> </div>` or
|
|
238
238
|
* `<div>\t\t</div>`. Choose the API that matches your rule's intent.
|
|
239
|
-
* @param element A `JSXElement` or `JSXFragment` node
|
|
240
|
-
* @returns `true` when the element has at least one meaningful child
|
|
239
|
+
* @param element A `JSXElement` or `JSXFragment` node.
|
|
240
|
+
* @returns `true` when the element has at least one meaningful child.
|
|
241
241
|
*/
|
|
242
242
|
declare function hasChildren(element: TSESTreeJSXElementLike): boolean;
|
|
243
243
|
//#endregion
|
|
244
244
|
//#region src/has-every-attribute.d.ts
|
|
245
245
|
/**
|
|
246
|
-
* Check whether a JSX element carries all of the given attributes (props)
|
|
246
|
+
* Check whether a JSX element carries all of the given attributes (props).
|
|
247
247
|
*
|
|
248
248
|
* This is a batch variant of {@link hasAttribute} for the common pattern
|
|
249
249
|
* where a rule needs to verify that a set of required props are all present.
|
|
250
250
|
*
|
|
251
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
|
|
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
256
|
*/
|
|
257
257
|
declare function hasEveryAttribute(context: RuleContext, element: TSESTree.JSXElement, names: string[]): boolean;
|
|
258
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
|
|
259
278
|
//#region src/is-element.d.ts
|
|
260
279
|
/**
|
|
261
|
-
* A test that determines whether a JSX element matches
|
|
280
|
+
* A test that determines whether a JSX element matches.
|
|
262
281
|
*
|
|
263
282
|
* - `string` matches against the full element type (ex: "div", "React.Fragment")
|
|
264
283
|
* - `string[]` matches when the element type equals any of the given strings
|
|
265
|
-
* - `function` receives the element type string and returns a boolean
|
|
284
|
+
* - `function` receives the element type string and returns a boolean.
|
|
266
285
|
*/
|
|
267
286
|
type ElementTest = string | readonly string[] | ((elementType: string, node: TSESTreeJSXElementLike) => boolean);
|
|
268
287
|
/**
|
|
269
288
|
* Check whether a node is a `JSXElement` (or `JSXFragment`) and optionally
|
|
270
|
-
* matches a given test
|
|
289
|
+
* matches a given test.
|
|
271
290
|
*
|
|
272
291
|
* Modelled after
|
|
273
292
|
* [`hast-util-is-element`](https://github.com/syntax-tree/hast-util-is-element):
|
|
@@ -275,15 +294,15 @@ type ElementTest = string | readonly string[] | ((elementType: string, node: TSE
|
|
|
275
294
|
*
|
|
276
295
|
* When called without a test, the function acts as a simple type-guard
|
|
277
296
|
* for `JSXElement | JSXFragment`.
|
|
278
|
-
* @param node The AST node to test
|
|
279
|
-
* @param test Optional test to match the element type against
|
|
280
|
-
* @returns `true` when the node is a matching JSX element
|
|
297
|
+
* @param node The AST node to test.
|
|
298
|
+
* @param test Optional test to match the element type against.
|
|
299
|
+
* @returns `true` when the node is a matching JSX element.
|
|
281
300
|
*/
|
|
282
301
|
declare function isElement(node: TSESTree.Node | null | undefined, test?: ElementTest): node is TSESTreeJSXElementLike;
|
|
283
302
|
//#endregion
|
|
284
303
|
//#region src/is-fragment-element.d.ts
|
|
285
304
|
/**
|
|
286
|
-
* Check whether a node is a React Fragment element
|
|
305
|
+
* Check whether a node is a React Fragment element.
|
|
287
306
|
*
|
|
288
307
|
* Recognizes both the shorthand `<>...</>` syntax (`JSXFragment`) and the
|
|
289
308
|
* explicit `<Fragment>` / `<React.Fragment>` form (`JSXElement`).
|
|
@@ -291,70 +310,70 @@ declare function isElement(node: TSESTree.Node | null | undefined, test?: Elemen
|
|
|
291
310
|
* The comparison is performed against the self name (last dot-separated
|
|
292
311
|
* segment) of both the node and the configured factory, so `<React.Fragment>`
|
|
293
312
|
* matches `"React.Fragment"` and `<Fragment>` matches `"Fragment"`.
|
|
294
|
-
* @param node The AST node to test
|
|
295
|
-
* @param jsxFragmentFactory The configured fragment factory string (ex: "React.Fragment")
|
|
296
|
-
* @returns `true` when the node represents a React Fragment
|
|
313
|
+
* @param node The AST node to test.
|
|
314
|
+
* @param jsxFragmentFactory The configured fragment factory string (ex: "React.Fragment").
|
|
315
|
+
* @returns `true` when the node represents a React Fragment.
|
|
297
316
|
*/
|
|
298
317
|
declare function isFragmentElement(node: TSESTree.Node, jsxFragmentFactory?: string): node is TSESTreeJSXElementLike;
|
|
299
318
|
//#endregion
|
|
300
319
|
//#region src/is-host-element.d.ts
|
|
301
320
|
/**
|
|
302
|
-
* Check whether a node is a host (intrinsic / DOM) element
|
|
321
|
+
* Check whether a node is a host (intrinsic / DOM) element.
|
|
303
322
|
*
|
|
304
323
|
* A host element is a `JSXElement` whose tag name is a plain `JSXIdentifier`
|
|
305
324
|
* starting with a lowercase letter, the same heuristic React uses to
|
|
306
325
|
* distinguish `<div>` from `<MyComponent>`.
|
|
307
|
-
* @param node The AST node to test
|
|
308
|
-
* @returns `true` when the node is a `JSXElement` with a lowercase tag name
|
|
326
|
+
* @param node The AST node to test.
|
|
327
|
+
* @returns `true` when the node is a `JSXElement` with a lowercase tag name.
|
|
309
328
|
*/
|
|
310
329
|
declare function isHostElement(node: TSESTree.Node): node is TSESTree.JSXElement;
|
|
311
330
|
//#endregion
|
|
312
331
|
//#region src/is-whitespace.d.ts
|
|
313
332
|
/**
|
|
314
333
|
* Check whether a JSX child node is whitespace padding that React would
|
|
315
|
-
* trim away during rendering
|
|
334
|
+
* trim away during rendering.
|
|
316
335
|
*
|
|
317
336
|
* A child is considered whitespace padding when it is a `JSXText` node whose
|
|
318
337
|
* content is empty after applying React's whitespace normalization
|
|
319
338
|
* (see {@link collapseMultilineText}, modelled after Babel's
|
|
320
339
|
* `cleanJSXElementLiteralChild`). This is the whitespace that appears between
|
|
321
340
|
* JSX tags purely for formatting.
|
|
322
|
-
* @param node A JSX child node
|
|
323
|
-
* @returns `true` when the node is purely formatting whitespace
|
|
341
|
+
* @param node A JSX child node.
|
|
342
|
+
* @returns `true` when the node is purely formatting whitespace.
|
|
324
343
|
*/
|
|
325
344
|
declare function isWhitespace(node: TSESTree.JSXChild): boolean;
|
|
326
345
|
/**
|
|
327
|
-
* Check whether a JSX child node is any whitespace-only text
|
|
346
|
+
* Check whether a JSX child node is any whitespace-only text.
|
|
328
347
|
*
|
|
329
348
|
* This is a looser variant of {@link isWhitespace}; it matches every
|
|
330
349
|
* `JSXText` node whose raw content is empty after trimming, regardless of
|
|
331
350
|
* whether it contains a newline.
|
|
332
|
-
* @param node A JSX child node
|
|
333
|
-
* @returns `true` when the node is a whitespace-only `JSXText
|
|
351
|
+
* @param node A JSX child node.
|
|
352
|
+
* @returns `true` when the node is a whitespace-only `JSXText`.
|
|
334
353
|
*/
|
|
335
354
|
declare function isWhitespaceText(node: TSESTree.JSXChild): boolean;
|
|
336
355
|
/**
|
|
337
|
-
* Check whether a JSX child node is an empty string expression (`{""}`)
|
|
356
|
+
* Check whether a JSX child node is an empty string expression (`{""}`).
|
|
338
357
|
*
|
|
339
358
|
* React's reconciler and SSR renderer explicitly skip empty strings,
|
|
340
359
|
* producing no DOM node (see `ReactChildFiber.js` and `ReactFizzConfigDOM.js`).
|
|
341
360
|
* Such expressions are therefore treated as non-rendered children, in the same
|
|
342
361
|
* way as whitespace padding.
|
|
343
|
-
* @param node A JSX child node
|
|
344
|
-
* @returns `true` when the node is a `{""}` expression container
|
|
362
|
+
* @param node A JSX child node.
|
|
363
|
+
* @returns `true` when the node is a `{""}` expression container.
|
|
345
364
|
*/
|
|
346
365
|
declare function isEmptyStringExpression(node: TSESTree.JSXChild): boolean;
|
|
347
366
|
//#endregion
|
|
348
367
|
//#region src/jsx-detection-hint.d.ts
|
|
349
368
|
/**
|
|
350
|
-
* BitFlags for configuring JSX detection behavior
|
|
369
|
+
* BitFlags for configuring JSX detection behavior.
|
|
351
370
|
*
|
|
352
371
|
* Used by `isJsxLike` to control which AST node kinds are considered
|
|
353
372
|
* "JSX-like". Combine flags with the `|` operator.
|
|
354
373
|
*/
|
|
355
374
|
type JsxDetectionHint = bigint;
|
|
356
375
|
/**
|
|
357
|
-
* Hints for JSX detection
|
|
376
|
+
* Hints for JSX detection.
|
|
358
377
|
*/
|
|
359
378
|
declare const JsxDetectionHint: {
|
|
360
379
|
readonly None: 0n;
|
|
@@ -371,7 +390,7 @@ declare const JsxDetectionHint: {
|
|
|
371
390
|
readonly RequireBothBranchesOfConditionalExpressionToBeJsx: bigint;
|
|
372
391
|
};
|
|
373
392
|
/**
|
|
374
|
-
* Default JSX detection hint
|
|
393
|
+
* Default JSX detection hint.
|
|
375
394
|
*
|
|
376
395
|
* Skips number, bigint, boolean, string, and undefined literals,
|
|
377
396
|
* the value types that are commonly returned alongside JSX in React
|
|
@@ -382,15 +401,15 @@ declare const DEFAULT_JSX_DETECTION_HINT: JsxDetectionHint;
|
|
|
382
401
|
//#region src/resolve-attribute-value.d.ts
|
|
383
402
|
/**
|
|
384
403
|
* Resolve the value of a JSX attribute (or spread attribute) into a
|
|
385
|
-
* {@link JsxAttributeValue} descriptor that can be inspected further
|
|
404
|
+
* {@link JsxAttributeValue} descriptor that can be inspected further.
|
|
386
405
|
*
|
|
387
406
|
* This is the low-level building block; it operates on a single attribute
|
|
388
407
|
* node that the caller has already located. For the higher-level "find by
|
|
389
408
|
* name and resolve" combo, see {@link getAttributeValue}.
|
|
390
|
-
* @param context The ESLint rule context (needed for scope look-ups)
|
|
391
|
-
* @param attribute A `JSXAttribute` or `JSXSpreadAttribute` node
|
|
392
|
-
* @returns A discriminated-union descriptor of the attribute's value
|
|
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.
|
|
393
412
|
*/
|
|
394
413
|
declare function resolveAttributeValue(context: RuleContext, attribute: TSESTreeJSXAttributeLike): JsxAttributeValue;
|
|
395
414
|
//#endregion
|
|
396
|
-
export { DEFAULT_JSX_DETECTION_HINT, ElementTest, JsxAttributeValue, JsxDetectionHint, collapseMultilineText, findAttribute, findParentAttribute, getAttributeName, getAttributeStaticValue, getAttributeValue, getChildren, getElementFullType, getElementSelfType, hasAnyAttribute, hasAttribute, hasChildren, hasEveryAttribute, isElement, isEmptyStringExpression, isFragmentElement, isHostElement, isWhitespace, isWhitespaceText, resolveAttributeValue };
|
|
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 };
|