Skip to content

Commit 879dabb

Browse files
committed
docs(configurations): update examples and type annotations
1 parent 8693f30 commit 879dabb

File tree

1 file changed

+74
-18
lines changed

1 file changed

+74
-18
lines changed

website/pages/docs/configurations.mdx

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,121 @@ ESLint React provides the following configurations:
88

99
### `version`
1010

11-
(type: `string`, default: `"detect"`)
11+
```ts
12+
export default "detect" satisfies string
13+
```
14+
15+
React version to perform the analysis, `"detect"` means auto detect React version from the project's dependencies.
1216

13-
React version to use, `"detect"` means auto detect React version from the project's dependencies.
17+
If failed to detect, it will use the `19.0.0` version.
1418

1519
### `importSource`
1620

17-
(type: `string`, default: `"react"`)
21+
```ts
22+
export default "react" satisfies string
23+
```
24+
25+
<Callout type="info">If `importSource` is specified, an equivalent version of React should be provided to the [`version`](#version) setting.</Callout>
1826

19-
The source where React is imported from.\
20-
This allows to specify a custom import location for React when not using the official distribution.\
21-
If `importSource` is specified, an equivalent version of React should be provided to the [`version`](#version) setting.
27+
The source where React is imported from.
2228

23-
(e.g. `@pika/react`, etc)
29+
This allows to specify a custom import location for React when not using the official distribution.
30+
31+
For example, if you are using `@pika/react` instead of `react`, you can set the `importSource` to `@pika/react`:
32+
33+
```tsx
34+
import React from "@pika/react";
35+
```
2436

2537
### `polymorphicPropName`
2638

27-
(type: `string`)
39+
```ts
40+
export default "as" satisfies string
41+
```
2842

2943
You can optionally use the `polymorphicPropName` setting to define the prop your code uses to create polymorphic components. This setting will be used determine the element type in rules that require semantic context.
3044

3145
For example, if you set the `polymorphicPropName` setting to `as` then this element:
3246

33-
`<Box as="h3">Configurations </Box>`
47+
```tsx
48+
<Box as="h3">Configurations</Box>
49+
```
3450

3551
will be evaluated as an `h3`.
3652

3753
If no `polymorphicPropName` is set, then the component will be evaluated as `Box`.
3854

3955
### `additionalComponents`
4056

41-
(type: `{ name: string; as: string; attributes: { name: string; as?: string; defaultValue?: string }[] }[]`)
57+
```ts
58+
interface ComponentAttributeEntry {
59+
name: string;
60+
as?: string;
61+
defaultValue?: string;
62+
}
63+
64+
interface ComponentEntry {
65+
name: string;
66+
as?: string;
67+
attributes: ComponentAttributeEntry[];
68+
}
69+
70+
export default [] satisfies ComponentEntry[]
71+
```
4272

4373
<Callout type="info">Before using `additionalComponents`, consider whether `polymorphicPropName` can be used instead, as it simpler and more efficient.</Callout>
4474

4575
<Callout type="warning">This is an experimental feature that can be unstable and lacks documentation.</Callout>
4676

4777
An array of components and its attributes mapping. It allows the related rules to do even more comprehensive analysis. You can also provide default values for attributes here, that will be used when that attribute is not present in the component.
4878

49-
For example, if you set the `additionalComponents` to `[{ name: "EmbedContent", as: "iframe", attributes: [{ name: "sandbox", defaultValue: "" }] }]` then this element:
79+
For example, if you set the `additionalComponents` to:
5080

51-
`<EmbedContent src="https://eslint-react.xyz" />`
81+
```json
82+
[{ name: "EmbedContent", as: "iframe", attributes: [{ name: "sandbox", defaultValue: "" }] }]
83+
```
5284

53-
will be evaluated as an `<iframe src="https://eslint-react.xyz" sandbox="" />`.
85+
then this element:
86+
87+
```tsx
88+
<EmbedContent src="https://eslint-react.xyz" />
89+
```
90+
91+
will be evaluated as an:
92+
93+
```tsx
94+
<iframe src="https://eslint-react.xyz" sandbox="" />
95+
```
5496

5597
So that both the `dom/no-missing-iframe-sandbox` and `dom/no-unsafe-iframe-sandbox` rules can perform checks on it.
5698

5799
### `additionalHooks`
58100

59-
(type: `[key: string]: string[]`)
101+
```ts
102+
export default { useLayoutEffect: ["useIsomorphicLayoutEffect"] } satisfies Record<ReactBuiltInHookName, string[]>
103+
```
60104

61-
<Callout type="warning">This is intended to cover edge cases. We suggest to use this option very sparingly, if at all.</Callout>
105+
<Callout type="warning">This is intended to cover edge cases. We suggest using the built-in React Hooks whenever possible.</Callout>
62106

63107
A object of aliases for React built-in Hooks. ESLint React will recognize these aliases as equivalent to the built-in Hooks in all its rules.
64108

65-
For example, if you set the `additionalHooks` to `{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }` then the React Hook in this code:
109+
For example, if you set the `additionalHooks` to:
66110

67-
`useIsomorphicLayoutEffect(() => { setCount(count + 1); }, [count]);`
111+
```json
112+
{ useLayoutEffect: ["useIsomorphicLayoutEffect"] }
113+
```
114+
115+
then the React Hook call:
116+
117+
```tsx
118+
useIsomorphicLayoutEffect(() => { setCount(count => count + 1); }, []);
119+
```
120+
121+
will be evaluated as an:
68122

69-
will be evaluated as a `useLayoutEffect` hook.
123+
```tsx
124+
useLayoutEffect(() => { setCount(count => count + 1); }, []);
125+
```
70126

71127
So that the `hooks-extra/no-direct-set-state-in-use-layout-effect` rule can perform checks on it.
72128

0 commit comments

Comments
 (0)