Skip to content

Commit 52f8ff3

Browse files
committed
docs: refine configurations docs
1 parent fd55fa5 commit 52f8ff3

File tree

1 file changed

+42
-83
lines changed

1 file changed

+42
-83
lines changed

apps/website/content/docs/configurations.mdx

Lines changed: 42 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,78 @@ title: Configurations
44

55
import { SettingsTypeTable } from "./configurations";
66

7-
ESLint React supports reading settings from the `react-x` key in the [`settings`](https://eslint.org/docs/latest/use/configure/configuration-files#configuring-shared-settings) object of your ESLint configuration file.
7+
ESLint React reads configurations from the `react-x` key within ESLint's [`settings`](https://eslint.org/docs/latest/use/configure/configuration-files#configuring-shared-settings) object. Configure these properties in your ESLint configuration file:
88

99
```ts title="eslint.config.js"
1010
export default [
1111
{
1212
files: ["**/*.ts", "**/*.tsx"],
1313
settings: {
1414
"react-x": {
15-
version: "19.0.0",
15+
version: "19.0.0", // React version for analysis
16+
// ...other configurations
1617
},
1718
},
1819
},
1920
];
2021
```
2122

22-
## Properties
23+
## Configuration Properties
2324

2425
<SettingsTypeTable />
2526

26-
## Descriptions
27+
## Property Specifications
2728

2829
### `version`
2930

30-
React version to perform the analysis, `"detect"` means auto detect React version from the project's dependencies.
31-
32-
If failed to detect, it will use the `19.0.0` version.
31+
Defines the React version for semantic analysis.
32+
- `"detect"`: Auto-detects from project dependencies (defaults to `19.0.0` if undetectable)
33+
- `string`: Explicit version specification (e.g., `"18.2.0"`)
3334

3435
### `importSource`
3536

36-
<Callout type="info">If `importSource` is specified, an equivalent version of React should be provided to the [`version`](#version) setting.</Callout>
37-
38-
The source where React is imported from.
37+
Customizes the React module import source. Useful for non-standard distributions.
3938

40-
This allows to specify a custom import location for React when not using the official distribution.
41-
42-
For example, if you are using `@pika/react` instead of `react`, you can set the `importSource` to `@pika/react`:
39+
Example for using `@pika/react` instead of `react`:
4340

4441
```ts
4542
import React from "@pika/react";
4643
```
4744

4845
### `skipImportCheck`
4946

50-
When determining whether an API originates from React, bypass the import source check.
51-
52-
By default, the rule checks only the shape of the API to determine if it is a React API. If `skipImportCheck` is set to `false`, both the shape and the import source will be checked.
47+
Controls whether to verify the import source when identifying React APIs.
5348

54-
This prevents false positives when using unrelated third-party libraries that have APIs similar to React.
55-
56-
For example, when `skipImportCheck` is set to `false`, the `memo` function from `unrelated-library` will not be recognized as React's `memo`.
49+
Default is `true` (checks only API shape). When `false`, both shape and import source are verified, preventing false positives from third-party libraries with similar APIs.
5750

5851
```ts
5952
import { memo } from "unrelated-library";
6053

6154
const NonComponentFunction = memo(() => {
62-
// ^^^^
63-
// - This will not be recognized as React's memo
55+
// When skipImportCheck: false, this isn't recognized as React's memo
6456
});
6557
```
6658

6759
### `polymorphicPropName`
6860

69-
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.
61+
Defines the prop used for polymorphic components. Helps rules determine element types for semantic context.
7062

71-
For example, if you set the `polymorphicPropName` setting to `as` then this element:
63+
Example with `polymorphicPropName` set to `as`:
7264

7365
```tsx
7466
<Box as="h3">Configurations</Box>
67+
// Evaluated as an h3 element
7568
```
7669

77-
will be evaluated as an `h3`.
78-
79-
If no `polymorphicPropName` is set, then the component will be evaluated as `Box`.
80-
81-
### `additionalComponents`
70+
### `additionalComponents` (Experimental)
8271

83-
<Callout type="info">Before using `additionalComponents`, consider whether `polymorphicPropName` can be used instead, as it simpler and more efficient.</Callout>
72+
<Callout type="info">Consider using `polymorphicPropName` instead when possible, as it's simpler and more efficient.</Callout>
8473

85-
<Callout type="warn">This is an experimental feature that can be unstable and lacks documentation.</Callout>
74+
<Callout type="warn">Experimental feature that may lack stability and documentation.</Callout>
8675

87-
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.
76+
Maps components and their attributes for comprehensive analysis. Supports default attribute values.
8877

89-
For example, if you set the `additionalComponents` to:
78+
Example configuration:
9079

9180
```json
9281
[
@@ -103,62 +92,31 @@ For example, if you set the `additionalComponents` to:
10392
]
10493
```
10594

106-
then this element:
95+
This makes `<EmbedContent src="https://eslint-react.xyz" />{:tsx}` evaluate as `<iframe src="https://eslint-react.xyz" sandbox="" />{:tsx}`.
10796

108-
```tsx
109-
<EmbedContent src="https://eslint-react.xyz" />
110-
```
97+
### `additionalHooks` (Experimental)
11198

112-
will be evaluated as an:
99+
<Callout type="warn">
100+
Intended for edge cases. We suggest to use this option **very sparingly, if at all**. Generally saying, we recommend most custom Hooks do not vary the built-in React Hooks, and instead provide a higher-level API that is more focused around a specific use case.
101+
</Callout>
113102

114-
```tsx
115-
<iframe src="https://eslint-react.xyz" sandbox="" />
116-
```
117-
118-
So that both the `dom/no-missing-iframe-sandbox` and `dom/no-unsafe-iframe-sandbox` rules can perform checks on it.
119-
120-
### `additionalHooks`
121-
122-
<Callout type="warn">This is intended to cover edge cases. We suggest using the built-in React Hooks whenever possible.</Callout>
103+
Alias variants to built-in React Hooks for rule compatibility:
123104

124-
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.
125-
126-
For example, if you set the `additionalHooks` to:
127-
128-
```json
129-
{
130-
useEffect: ["useIsomorphicLayoutEffect"]
105+
```js
106+
additionalHooks: {
107+
useEffect: ["useIsomorphicLayoutEffect"],
131108
useLayoutEffect: ["useIsomorphicLayoutEffect"]
132109
}
133110
```
134111

135-
then the React Hook call:
112+
Treats `useIsomorphicLayoutEffect` as both `useEffect` and `useLayoutEffect` in rule checks.
136113

137-
```ts
138-
useIsomorphicLayoutEffect(() => { setCount(count => count + 1); }, []);
139-
```
140-
141-
will be evaluated as:
142-
143-
```ts
144-
useEffect(() => { setCount(count => count + 1); }, []);
145-
```
146-
147-
and:
148-
149-
```ts
150-
useLayoutEffect(() => { setCount(count => count + 1); }, []);
151-
```
152-
153-
So that both the `hooks-extra/no-direct-set-state-in-use-effect` and `hooks-extra/no-direct-set-state-in-use-layout-effect` rules can perform checks on it.
154-
155-
## Examples
114+
## Complete Configuration Example
156115

157116
```ts title="eslint.config.js"
158117
import eslintReact from "@eslint-react/eslint-plugin";
159118

160119
export default [
161-
// ...
162120
{
163121
files: ["**/*.{ts,tsx}"],
164122
...eslintReact.configs["recommended-typescript"],
@@ -169,26 +127,27 @@ export default [
169127
polymorphicPropName: "as",
170128
additionalHooks: {
171129
useEffect: ["useIsomorphicLayoutEffect"],
172-
useLayoutEffect: ["useIsomorphicLayoutEffect"],
130+
useLayoutEffect: ["useIsomorphicLayoutEffect"]
173131
},
174132
additionalComponents: [
175133
{
176134
name: "Link",
177135
as: "a",
178136
attributes: [
179-
{ name: "to", as: "href" },
180-
],
137+
{ name: "to", as: "href" } // Maps 'to' prop to 'href' attribute
138+
]
181139
},
182140
{
183141
name: "EmbedContent",
184142
as: "iframe",
185143
attributes: [
186144
{ name: "sandbox", defaultValue: "" }
187-
],
188-
},
189-
],
190-
},
191-
},
192-
},
145+
]
146+
}
147+
]
148+
}
149+
}
150+
}
193151
];
194152
```
153+

0 commit comments

Comments
 (0)