Skip to content

Commit ccd69e1

Browse files
Rel1cxCopilot
andauthored
feat: new jsx element and attribute resolution for dom rules (#1219)
Signed-off-by: REL1CX <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 48b7c6d commit ccd69e1

Some content is hidden

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

45 files changed

+690
-1197
lines changed

apps/website/content/docs/configuration/configure-analyzer.mdx

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -56,38 +56,6 @@ Example with `polymorphicPropName` set to `as`:
5656
// Evaluated as an h3 element
5757
```
5858

59-
### `additionalComponents` (Experimental)
60-
61-
<Callout type="info">
62-
Consider using `polymorphicPropName` instead when possible, as it's simpler
63-
and more efficient.
64-
</Callout>
65-
66-
<Callout type="warn">
67-
Experimental feature that may lack stability and documentation.
68-
</Callout>
69-
70-
Maps components and their attributes for comprehensive analysis. Supports default attribute values.
71-
72-
Example configuration:
73-
74-
```json
75-
[
76-
{
77-
"name": "EmbedContent",
78-
"as": "iframe",
79-
"attributes": [
80-
{
81-
"name": "sandbox",
82-
"defaultValue": ""
83-
}
84-
]
85-
}
86-
]
87-
```
88-
89-
This makes `<EmbedContent src="https://eslint-react.xyz" />{:tsx}` evaluate as `<iframe src="https://eslint-react.xyz" sandbox="" />{:tsx}`.
90-
9159
### `additionalHooks` (Experimental)
9260

9361
<Callout type="warn">
@@ -127,20 +95,6 @@ export default [
12795
useEffect: ["useIsomorphicLayoutEffect"],
12896
useLayoutEffect: ["useIsomorphicLayoutEffect"],
12997
},
130-
131-
// (Experimental) Configure mapping for custom components and their attributes for more comprehensive analysis
132-
additionalComponents: [
133-
{
134-
name: "Link",
135-
as: "a",
136-
attributes: [{ name: "to", as: "href" }],
137-
},
138-
{
139-
name: "EmbedContent",
140-
as: "iframe",
141-
attributes: [{ name: "sandbox", defaultValue: "" }],
142-
},
143-
],
14498
},
14599
},
146100
},

apps/website/content/docs/configuration/configure-analyzer.tsx

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,6 @@ const properties = {
3838
/>
3939
),
4040
},
41-
additionalComponents: {
42-
type: "CustomComponent[]",
43-
description: <Link href="#additionalcomponents">An array of components and its attributes mapping ⤵</Link>,
44-
default: "[]",
45-
typeDescription: (
46-
<CodeBlock
47-
code={dedent`
48-
type CustomComponent = {
49-
name: string;
50-
as?: string;
51-
attributes?: {
52-
name: string;
53-
as?: string;
54-
defaultValue?: string;
55-
}[]
56-
}
57-
`}
58-
lang="ts"
59-
/>
60-
),
61-
},
6241
polymorphicPropName: {
6342
type: "string",
6443
description: <Link href="#polymorphicpropname">The prop your code uses to create polymorphic components ⤵</Link>,

apps/website/content/docs/configuration/configure-enhanced-additional-components.mdx

Lines changed: 0 additions & 69 deletions
This file was deleted.

apps/website/content/docs/configuration/meta.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"!configure-language-preference",
66
"configure-project-config",
77
"!---Advanced Configuration---",
8-
"!enhanced-additional-components",
98
"!using-custom-parsers"
109
]
1110
}

packages/core/docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
## Type Aliases
2424

25+
- [AttributeValue](type-aliases/AttributeValue.md)
2526
- [Component](type-aliases/Component.md)
2627
- [ComponentDetectionHint](type-aliases/ComponentDetectionHint.md)
2728
- [ComponentEffectPhaseKind](type-aliases/ComponentEffectPhaseKind.md)
@@ -113,7 +114,6 @@
113114
- [findParentAttribute](functions/findParentAttribute.md)
114115
- [getAttribute](functions/getAttribute.md)
115116
- [getAttributeName](functions/getAttributeName.md)
116-
- [getAttributeValue](functions/getAttributeValue.md)
117117
- [getComponentFlagFromInitPath](functions/getComponentFlagFromInitPath.md)
118118
- [getComponentNameFromId](functions/getComponentNameFromId.md)
119119
- [getElementType](functions/getElementType.md)
@@ -151,6 +151,7 @@
151151
- [isRenderPropLoose](functions/isRenderPropLoose.md)
152152
- [isThisSetState](functions/isThisSetState.md)
153153
- [isUseEffectCallLoose](functions/isUseEffectCallLoose.md)
154+
- [resolveAttributeValue](functions/resolveAttributeValue.md)
154155
- [stringifyJsx](functions/stringifyJsx.md)
155156
- [useComponentCollector](functions/useComponentCollector.md)
156157
- [useComponentCollectorLegacy](functions/useComponentCollectorLegacy.md)

packages/core/docs/functions/getAttribute.md

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,32 @@
66

77
# Function: getAttribute()
88

9-
> **getAttribute**(`context`, `name`, `attributes`, `initialScope?`): `undefined` \| `JSXAttribute` \| `JSXSpreadAttribute`
10-
11-
Searches for a specific JSX attribute by name in a list of attributes
12-
Returns the last matching attribute (rightmost in JSX)
9+
> **getAttribute**(`context`, `attributes`, `initialScope?`): (`name`) => `undefined` \| `TSESTreeJSXAttributeLike`
1310
1411
## Parameters
1512

1613
### context
1714

1815
`RuleContext`
1916

20-
ESLint rule context
21-
22-
### name
23-
24-
`string`
25-
26-
The name of the attribute to find
27-
2817
### attributes
2918

30-
(`JSXAttribute` \| `JSXSpreadAttribute`)[]
31-
32-
Array of JSX attributes to search through
19+
`TSESTreeJSXAttributeLike`[]
3320

3421
### initialScope?
3522

3623
`Scope`
3724

38-
Optional scope for resolving variables
39-
4025
## Returns
4126

42-
`undefined` \| `JSXAttribute` \| `JSXSpreadAttribute`
27+
> (`name`): `undefined` \| `TSESTreeJSXAttributeLike`
28+
29+
### Parameters
30+
31+
#### name
32+
33+
`string`
34+
35+
### Returns
4336

44-
The found attribute or undefined
37+
`undefined` \| `TSESTreeJSXAttributeLike`

packages/core/docs/functions/getAttributeValue.md

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / resolveAttributeValue
6+
7+
# Function: resolveAttributeValue()
8+
9+
> **resolveAttributeValue**(`context`, `attribute`): \{ `kind`: `"boolean"`; `node?`: `undefined`; `toStatic`: `true`; \} \| \{ `kind`: `"literal"`; `node`: `BigIntLiteral` \| `BooleanLiteral` \| `NullLiteral` \| `NumberLiteral` \| `RegExpLiteral` \| `StringLiteral`; `toStatic`: `null` \| `string` \| `number` \| `bigint` \| `boolean` \| [`RegExp`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp); \} \| \{ `kind`: `"expression"`; `node`: `JSXEmptyExpression` \| `Expression`; `toStatic`: `unknown`; \} \| \{ `kind`: `"element"`; `node`: `JSXElement`; `toStatic`: `undefined`; \} \| \{ `kind`: `"spreadChild"`; `node`: `JSXEmptyExpression` \| `Expression`; `toStatic`: `undefined`; \} \| \{ `kind`: `"spreadProps"`; `node`: `Expression`; `toStatic`: `unknown`; \}
10+
11+
## Parameters
12+
13+
### context
14+
15+
`RuleContext`
16+
17+
### attribute
18+
19+
`TSESTreeJSXAttributeLike`
20+
21+
## Returns
22+
23+
\{ `kind`: `"boolean"`; `node?`: `undefined`; `toStatic`: `true`; \} \| \{ `kind`: `"literal"`; `node`: `BigIntLiteral` \| `BooleanLiteral` \| `NullLiteral` \| `NumberLiteral` \| `RegExpLiteral` \| `StringLiteral`; `toStatic`: `null` \| `string` \| `number` \| `bigint` \| `boolean` \| [`RegExp`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp); \} \| \{ `kind`: `"expression"`; `node`: `JSXEmptyExpression` \| `Expression`; `toStatic`: `unknown`; \} \| \{ `kind`: `"element"`; `node`: `JSXElement`; `toStatic`: `undefined`; \} \| \{ `kind`: `"spreadChild"`; `node`: `JSXEmptyExpression` \| `Expression`; `toStatic`: `undefined`; \} \| \{ `kind`: `"spreadProps"`; `node`: `Expression`; `toStatic`: `unknown`; \}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / AttributeValue
6+
7+
# Type Alias: AttributeValue
8+
9+
> **AttributeValue** = \{ `kind`: `"boolean"`; `toStatic`: `true`; \} \| \{ `kind`: `"element"`; `node`: `TSESTree.JSXElement`; `toStatic`: `unknown`; \} \| \{ `kind`: `"literal"`; `node`: `TSESTree.Literal`; `toStatic`: `null` \| `string` \| `number` \| `bigint` \| `boolean` \| [`RegExp`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp); \} \| \{ `kind`: `"expression"`; `node`: `TSESTree.JSXExpressionContainer`\[`"expression"`\]; `toStatic`: `unknown`; \} \| \{ `kind`: `"spreadProps"`; `node`: `TSESTree.JSXSpreadAttribute`\[`"argument"`\]; `toStatic`: `unknown`; \} \| \{ `kind`: `"spreadChild"`; `node`: `TSESTree.JSXSpreadChild`\[`"expression"`\]; `toStatic`: `unknown`; \}
10+
11+
Represents possible JSX attribute value types that can be resolved

0 commit comments

Comments
 (0)