Skip to content

Commit 3935d6f

Browse files
authored
refactor: code optimization (#1205)
1 parent a2b83d6 commit 3935d6f

23 files changed

+303
-217
lines changed

apps/website/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
"class-variance-authority": "^0.7.1",
1919
"clsx": "^2.1.1",
2020
"effect": "^3.17.9",
21-
"fumadocs-core": "15.7.3",
21+
"fumadocs-core": "15.7.5",
2222
"fumadocs-docgen": "3.0.0",
2323
"fumadocs-mdx": "11.8.1",
24-
"fumadocs-twoslash": "3.1.6",
24+
"fumadocs-twoslash": "3.1.7",
2525
"fumadocs-typescript": "4.0.6",
26-
"fumadocs-ui": "15.7.3",
26+
"fumadocs-ui": "15.7.5",
2727
"lucide-react": "^0.542.0",
2828
"next": "^15.5.2",
2929
"next-view-transitions": "^0.3.4",

packages/plugins/eslint-plugin-react-dom/src/utils/find-custom-component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import type { CustomComponentNormalized, CustomComponentPropNormalized } from "@eslint-react/shared";
22

3+
/**
4+
* Finds a custom component by name from the provided array of components.
5+
*
6+
* @param name - The name of the component to find
7+
* @param components - Array of normalized custom components to search through
8+
* @returns The matching component if found, undefined otherwise
9+
*/
310
export function findCustomComponent(name: string, components: CustomComponentNormalized[]) {
411
return components
512
.findLast((c) => c.name === name || c.re.test(name));
613
}
714

15+
/**
16+
* Finds a custom component prop by its "as" name.
17+
*
18+
* @param name - The name to match against the prop's "as" property
19+
* @param props - Array of normalized custom component props to search through
20+
* @returns The matching prop if found, undefined otherwise
21+
*/
822
export function findCustomComponentProp(name: string, props: CustomComponentPropNormalized[]) {
923
return props
1024
.findLast((a) => a.as === name);

packages/shared/docs/functions/coerceESLintSettings.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88

99
> **coerceESLintSettings**(`settings`): `PartialDeep`\<`undefined` \| \{ `react-x?`: `unknown`; \}\>
1010
11+
Coerces unknown input to ESLintSettings type
12+
1113
## Parameters
1214

1315
### settings
1416

1517
`unknown`
1618

19+
The settings object to coerce
20+
1721
## Returns
1822

1923
`PartialDeep`\<`undefined` \| \{ `react-x?`: `unknown`; \}\>

packages/shared/docs/functions/coerceSettings.md

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,41 @@
88

99
> **coerceSettings**(`settings`): `object`
1010
11+
Coerces unknown input to ESLintReactSettings type
12+
1113
## Parameters
1214

1315
### settings
1416

1517
`unknown`
1618

19+
The settings object to coerce
20+
1721
## Returns
1822

1923
### additionalComponents?
2024

2125
> `optional` **additionalComponents**: `object`[]
2226
23-
An array of user-defined components
24-
25-
#### Description
26-
27-
This is used to inform the ESLint React plugins how to treat these components during checks.
27+
User-defined components configuration
28+
Informs ESLint React how to treat these components during validation
2829

2930
#### Example
3031

3132
```ts
32-
`[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
33+
[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }] }]
3334
```
3435

3536
### additionalHooks?
3637

3738
> `optional` **additionalHooks**: `object`
3839
39-
A object to define additional hooks that are equivalent to the built-in React Hooks.
40-
41-
#### Description
42-
43-
ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
40+
Custom hooks that should be treated as equivalent to built-in React Hooks
4441

4542
#### Example
4643

4744
```ts
48-
`{ useEffect: ["useIsomorphicLayoutEffect"] }`
45+
{ useEffect: ["useIsomorphicLayoutEffect"] }
4946
```
5047

5148
#### additionalHooks.use?
@@ -128,51 +125,49 @@ ESLint React will recognize these aliases as equivalent to the built-in hooks in
128125

129126
> `optional` **importSource**: `string`
130127
131-
The source where React is imported from.
132-
133-
#### Description
134-
135-
This allows to specify a custom import location for React when not using the official distribution.
128+
The source where React is imported from
129+
Allows specifying a custom import location for React
136130

137131
#### Default
138132

139-
`"react"`
133+
```ts
134+
"react"
135+
```
140136

141137
#### Example
142138

143139
```ts
144-
`"@pika/react"`
140+
"@pika/react"
145141
```
146142

147143
### polymorphicPropName?
148144

149145
> `optional` **polymorphicPropName**: `string`
150146
151-
The name of the prop that is used for polymorphic components.
152-
153-
#### Description
154-
155-
This is used to determine the type of the component.
147+
The prop name used for polymorphic components
148+
Used to determine the component's type
156149

157150
#### Example
158151

159152
```ts
160-
`"as"`
153+
"as"
161154
```
162155

163156
### version?
164157

165158
> `optional` **version**: `string`
166159
167-
React version to use, "detect" means auto detect React version from the project's dependencies.
168-
If `importSource` is specified, an equivalent version of React should be provided here.
160+
React version to use
161+
"detect" means auto-detect React version from project dependencies
169162

170163
#### Example
171164

172165
```ts
173-
`"18.3.1"`
166+
"18.3.1"
174167
```
175168

176169
#### Default
177170

178-
`"detect"`
171+
```ts
172+
"detect"
173+
```

packages/shared/docs/functions/decodeESLintSettings.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88

99
> **decodeESLintSettings**(`settings`): `undefined` \| \{ `react-x?`: `unknown`; \}
1010
11+
Decodes and validates ESLint settings, using defaults if invalid
12+
1113
## Parameters
1214

1315
### settings
1416

1517
`unknown`
1618

19+
The settings object to decode
20+
1721
## Returns
1822

1923
`undefined` \| \{ `react-x?`: `unknown`; \}

packages/shared/docs/functions/decodeSettings.md

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,41 @@
88

99
> **decodeSettings**(`settings`): `object`
1010
11+
Decodes and validates ESLint React settings, using defaults if invalid
12+
1113
## Parameters
1214

1315
### settings
1416

1517
`unknown`
1618

19+
The settings object to decode
20+
1721
## Returns
1822

1923
### additionalComponents?
2024

2125
> `optional` **additionalComponents**: `object`[]
2226
23-
An array of user-defined components
24-
25-
#### Description
26-
27-
This is used to inform the ESLint React plugins how to treat these components during checks.
27+
User-defined components configuration
28+
Informs ESLint React how to treat these components during validation
2829

2930
#### Example
3031

3132
```ts
32-
`[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
33+
[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }] }]
3334
```
3435

3536
### additionalHooks?
3637

3738
> `optional` **additionalHooks**: `object`
3839
39-
A object to define additional hooks that are equivalent to the built-in React Hooks.
40-
41-
#### Description
42-
43-
ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
40+
Custom hooks that should be treated as equivalent to built-in React Hooks
4441

4542
#### Example
4643

4744
```ts
48-
`{ useEffect: ["useIsomorphicLayoutEffect"] }`
45+
{ useEffect: ["useIsomorphicLayoutEffect"] }
4946
```
5047

5148
#### additionalHooks.use?
@@ -128,51 +125,49 @@ ESLint React will recognize these aliases as equivalent to the built-in hooks in
128125

129126
> `optional` **importSource**: `string`
130127
131-
The source where React is imported from.
132-
133-
#### Description
134-
135-
This allows to specify a custom import location for React when not using the official distribution.
128+
The source where React is imported from
129+
Allows specifying a custom import location for React
136130

137131
#### Default
138132

139-
`"react"`
133+
```ts
134+
"react"
135+
```
140136

141137
#### Example
142138

143139
```ts
144-
`"@pika/react"`
140+
"@pika/react"
145141
```
146142

147143
### polymorphicPropName?
148144

149145
> `optional` **polymorphicPropName**: `string`
150146
151-
The name of the prop that is used for polymorphic components.
152-
153-
#### Description
154-
155-
This is used to determine the type of the component.
147+
The prop name used for polymorphic components
148+
Used to determine the component's type
156149

157150
#### Example
158151

159152
```ts
160-
`"as"`
153+
"as"
161154
```
162155

163156
### version?
164157

165158
> `optional` **version**: `string`
166159
167-
React version to use, "detect" means auto detect React version from the project's dependencies.
168-
If `importSource` is specified, an equivalent version of React should be provided here.
160+
React version to use
161+
"detect" means auto-detect React version from project dependencies
169162

170163
#### Example
171164

172165
```ts
173-
`"18.3.1"`
166+
"18.3.1"
174167
```
175168

176169
#### Default
177170

178-
`"detect"`
171+
```ts
172+
"detect"
173+
```

packages/shared/docs/functions/getSettingsFromContext.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88

99
> **getSettingsFromContext**(`context`): [`ESLintReactSettingsNormalized`](../interfaces/ESLintReactSettingsNormalized.md)
1010
11+
Retrieves normalized ESLint React settings from the rule context
12+
Uses caching for performance optimization
13+
1114
## Parameters
1215

1316
### context
1417

1518
`RuleContext`
1619

20+
The ESLint rule context
21+
1722
## Returns
1823

1924
[`ESLintReactSettingsNormalized`](../interfaces/ESLintReactSettingsNormalized.md)

packages/shared/docs/functions/isESLintReactSettings.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88

99
> **isESLintReactSettings**(`settings`): `settings is { additionalComponents?: { as?: string; attributes?: { as?: string; defaultValue?: string; name: string }[]; name: string }[]; additionalHooks?: { use?: string[]; useActionState?: string[]; useCallback?: string[]; useContext?: string[]; useDebugValue?: string[]; useDeferredValue?: string[]; useEffect?: string[]; useFormStatus?: string[]; useId?: string[]; useImperativeHandle?: string[]; useInsertionEffect?: string[]; useLayoutEffect?: string[]; useMemo?: string[]; useOptimistic?: string[]; useReducer?: string[]; useRef?: string[]; useState?: string[]; useSyncExternalStore?: string[]; useTransition?: string[] }; importSource?: string; polymorphicPropName?: string; version?: string }`
1010
11+
Checks if the provided settings conform to ESLintReactSettings schema
12+
1113
## Parameters
1214

1315
### settings
1416

1517
`unknown`
1618

19+
The settings object to validate
20+
1721
## Returns
1822

1923
`settings is { additionalComponents?: { as?: string; attributes?: { as?: string; defaultValue?: string; name: string }[]; name: string }[]; additionalHooks?: { use?: string[]; useActionState?: string[]; useCallback?: string[]; useContext?: string[]; useDebugValue?: string[]; useDeferredValue?: string[]; useEffect?: string[]; useFormStatus?: string[]; useId?: string[]; useImperativeHandle?: string[]; useInsertionEffect?: string[]; useLayoutEffect?: string[]; useMemo?: string[]; useOptimistic?: string[]; useReducer?: string[]; useRef?: string[]; useState?: string[]; useSyncExternalStore?: string[]; useTransition?: string[] }; importSource?: string; polymorphicPropName?: string; version?: string }`

packages/shared/docs/functions/isESLintSettings.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88

99
> **isESLintSettings**(`settings`): settings is undefined \| \{ react-x?: unknown \}
1010
11+
Checks if the provided settings conform to ESLintSettings schema
12+
1113
## Parameters
1214

1315
### settings
1416

1517
`unknown`
1618

19+
The settings object to validate
20+
1721
## Returns
1822

1923
settings is undefined \| \{ react-x?: unknown \}

0 commit comments

Comments
 (0)