Skip to content

Commit be06e03

Browse files
authored
fix: rewrite react api detection to better align with eslint-plugin-react-hook (#1074)
1 parent 17fbc4e commit be06e03

File tree

65 files changed

+1046
-578
lines changed

Some content is hidden

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

65 files changed

+1046
-578
lines changed

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default [
3232

3333
Defines the React version for semantic analysis.
3434

35-
- `"detect"`: Auto-detects from project dependencies (defaults to `19.1.0` if undetectable)
35+
- `detect`: Auto-detects from project dependencies (defaults to `19.1.0` if undetectable)
3636
- `string`: Explicit version specification (e.g., `"18.3.1"`)
3737

3838
### `importSource`
@@ -45,20 +45,6 @@ Example for using `@pika/react` instead of `react`:
4545
import React from "@pika/react";
4646
```
4747

48-
### `skipImportCheck`
49-
50-
Controls whether to verify the import source when identifying React APIs.
51-
52-
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.
53-
54-
```ts
55-
import { memo } from "unrelated-library";
56-
57-
const NonComponentFunction = memo(() => {
58-
// When skipImportCheck: false, this isn't recognized as React's memo
59-
});
60-
```
61-
6248
### `polymorphicPropName`
6349

6450
Defines the prop used for polymorphic components. Helps rules determine element types for semantic context.
@@ -73,10 +59,13 @@ Example with `polymorphicPropName` set to `as`:
7359
### `additionalComponents` (Experimental)
7460

7561
<Callout type="info">
76-
Consider using `polymorphicPropName` instead when possible, as it's simpler and more efficient.
62+
Consider using `polymorphicPropName` instead when possible, as it's simpler
63+
and more efficient.
7764
</Callout>
7865

79-
<Callout type="warn">Experimental feature that may lack stability and documentation.</Callout>
66+
<Callout type="warn">
67+
Experimental feature that may lack stability and documentation.
68+
</Callout>
8069

8170
Maps components and their attributes for comprehensive analysis. Supports default attribute values.
8271

@@ -102,9 +91,10 @@ This makes `<EmbedContent src="https://eslint-react.xyz" />{:tsx}` evaluate as `
10291
### `additionalHooks` (Experimental)
10392

10493
<Callout type="warn">
105-
Intended for edge cases. We suggest to use this option **very sparingly, if at all**. Generally saying, we recommend
106-
most custom Hooks do not vary the built-in React Hooks, and instead provide a higher-level API that is more focused
107-
around a specific use case.
94+
Intended for edge cases. We suggest to use this option **very sparingly, if at
95+
all**. Generally saying, we recommend most custom Hooks do not vary the
96+
built-in React Hooks, and instead provide a higher-level API that is more
97+
focused around a specific use case.
10898
</Callout>
10999

110100
Alias variants to built-in React Hooks for rule compatibility:

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ export function AnalyzerPropertyTypeTable() {
1919
description: <Link href="#importsource">The source where React is imported from ⤵</Link>,
2020
default: '"react"',
2121
},
22-
skipImportCheck: {
23-
type: "boolean",
24-
description: (
25-
<Link href="#skipimportcheck">
26-
When determining whether an API originates from React, bypass the import source check. ⤵
27-
</Link>
28-
),
29-
default: "true",
30-
},
3122
polymorphicPropName: {
3223
type: "string",
3324
description: (

apps/website/content/docs/presets.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ title: Presets
55
The following presets are available in `@eslint-react/eslint-plugin`:
66

77
<Callout type="info">
8-
For ESLint Legacy Config (`.eslintrc.*`), add a `-legacy` suffix to the preset name (e.g. `recommended-legacy`).
8+
For ESLint Legacy Config (`.eslintrc.*`), add a `-legacy` suffix to the preset
9+
name (e.g. `recommended-legacy`).
910
</Callout>
1011

1112
## Bare Bones

apps/website/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
"@chevrotain/regexp-to-ast": "^11.0.3",
1414
"bsky-react-post": "^0.1.7",
1515
"clsx": "^2.1.1",
16-
"fumadocs-core": "15.2.6",
16+
"fumadocs-core": "15.2.7",
1717
"fumadocs-docgen": "2.0.0",
18-
"fumadocs-mdx": "11.5.8",
19-
"fumadocs-twoslash": "3.1.0",
18+
"fumadocs-mdx": "11.6.0",
19+
"fumadocs-twoslash": "3.1.1",
2020
"fumadocs-typescript": "4.0.2",
21-
"fumadocs-ui": "15.2.6",
21+
"fumadocs-ui": "15.2.7",
2222
"lucide-react": "^0.488.0",
2323
"next": "^15.3.0",
2424
"next-view-transitions": "^0.3.4",

apps/website/source.config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { remarkMermaid } from "@theguild/remark-mermaid";
12
import { rehypeCodeDefaultOptions } from "fumadocs-core/mdx-plugins";
23
import { remarkDocGen, remarkInstall } from "fumadocs-docgen";
34
import { defineConfig, defineDocs } from "fumadocs-mdx/config";
45
import { transformerTwoslash } from "fumadocs-twoslash";
5-
import { remarkMermaid } from "@theguild/remark-mermaid";
66

77
export const docs = defineDocs({
88
dir: "content/docs",
@@ -14,7 +14,25 @@ export default defineConfig({
1414
rehypeCodeOptions: {
1515
experimentalJSEngine: true,
1616
inline: "tailing-curly-colon",
17-
langs: ["js", "ts", "jsx", "tsx", "html", "md", "mdx", "css", "json", "yaml"],
17+
langs: [
18+
"bash",
19+
"css",
20+
"html",
21+
"js",
22+
"json",
23+
"jsx",
24+
"lisp",
25+
"log",
26+
"md",
27+
"mdx",
28+
"regexp",
29+
"sh",
30+
"shell",
31+
"ts",
32+
"tsx",
33+
"yaml",
34+
"diff",
35+
],
1836
lazy: true,
1937
themes: {
2038
dark: "github-dark",

eslint.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import url from "node:url";
33
import markdown from "@eslint/markdown";
44
import * as configs from "@local/configs/eslint";
55
import pluginLocal from "@local/eslint-plugin-local";
6-
import configFlatGitignore from "eslint-config-flat-gitignore";
6+
import gitIgnores from "eslint-config-flat-gitignore";
77
import pluginVitest from "eslint-plugin-vitest";
88
import { globalIgnores } from "eslint/config";
99
import tseslint from "typescript-eslint";
@@ -22,7 +22,6 @@ const GLOB_TEST = [
2222
const GLOB_CONFIG = ["*.config.{ts,tsx,cts,mts}", "**/*.config.{ts,tsx,cts,mts}"];
2323
const GLOB_SCRIPT = ["scripts/**/*.{ts,cts,mts}"];
2424
const GLOB_IGNORES = [
25-
...configFlatGitignore().ignores,
2625
"apps",
2726
"docs",
2827
"test",
@@ -36,6 +35,7 @@ const packagesTsConfigs = [
3635
];
3736

3837
export default tseslint.config(
38+
gitIgnores(),
3939
globalIgnores(GLOB_IGNORES),
4040
{
4141
extends: [
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) / isReactAPI
6+
7+
# isReactAPI
8+
9+
## Type Aliases
10+
11+
- [ReturnType](type-aliases/ReturnType.md)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[**@eslint-react/core**](../../../../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../../../../README.md) / [isReactAPI](../README.md) / ReturnType
6+
7+
# Type Alias: ReturnType()
8+
9+
> **ReturnType** = \{(`context`, `node`): `boolean`; (`context`): (`node`) => `boolean`; \}
10+
11+
## Call Signature
12+
13+
> (`context`, `node`): `boolean`
14+
15+
### Parameters
16+
17+
#### context
18+
19+
`RuleContext`
20+
21+
#### node
22+
23+
`undefined` | `null` | `Node`
24+
25+
### Returns
26+
27+
`boolean`
28+
29+
## Call Signature
30+
31+
> (`context`): (`node`) => `boolean`
32+
33+
### Parameters
34+
35+
#### context
36+
37+
`RuleContext`
38+
39+
### Returns
40+
41+
> (`node`): `boolean`
42+
43+
#### Parameters
44+
45+
##### node
46+
47+
`undefined` | `null` | `Node`
48+
49+
#### Returns
50+
51+
`boolean`

packages/core/docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
## Namespaces
88

9+
- [isReactAPI](@eslint-react/namespaces/isReactAPI/README.md)
910
- [useComponentCollector](@eslint-react/namespaces/useComponentCollector/README.md)
1011
- [useComponentCollectorLegacy](@eslint-react/namespaces/useComponentCollectorLegacy/README.md)
1112
- [useHookCollector](@eslint-react/namespaces/useHookCollector/README.md)

packages/core/docs/functions/isReactAPI.md

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,14 @@
66

77
# Function: isReactAPI()
88

9-
## Call Signature
9+
> **isReactAPI**(`api`): [`ReturnType`](../@eslint-react/namespaces/isReactAPI/type-aliases/ReturnType.md)
1010
11-
> **isReactAPI**(`name`): `ReturnType`
11+
## Parameters
1212

13-
### Parameters
14-
15-
#### name
16-
17-
`string`
18-
19-
### Returns
20-
21-
`ReturnType`
22-
23-
## Call Signature
24-
25-
> **isReactAPI**(`objectName`, `propertyName`): `ReturnType`
26-
27-
### Parameters
28-
29-
#### objectName
30-
31-
`string`
32-
33-
#### propertyName
13+
### api
3414

3515
`string`
3616

37-
### Returns
17+
## Returns
3818

39-
`ReturnType`
19+
[`ReturnType`](../@eslint-react/namespaces/isReactAPI/type-aliases/ReturnType.md)

0 commit comments

Comments
 (0)