Skip to content

Commit ab03ec5

Browse files
authored
chore: enable eslint-plugin-react-hooks and @eslint-react/eslint-plugin (#60)
1 parent 50fd4cb commit ab03ec5

File tree

19 files changed

+257
-186
lines changed

19 files changed

+257
-186
lines changed

.changeset/quick-zoos-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@alauda/doom": patch
3+
---
4+
5+
chore: enable `eslint-plugin-react-hooks` and `@eslint-react/eslint-plugin`, fix related reports

eslint.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// @ts-check
22

33
import eslint from '@eslint/js'
4+
import react from '@eslint-react/eslint-plugin'
45
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
56
import { importX } from 'eslint-plugin-import-x'
7+
import * as reactHooks from 'eslint-plugin-react-hooks'
68
import { config, configs } from 'typescript-eslint'
79

810
export default config(
@@ -12,9 +14,15 @@ export default config(
1214
eslint.configs.recommended,
1315
importX.flatConfigs.recommended,
1416
importX.flatConfigs.typescript,
17+
react.configs.recommended,
18+
reactHooks.configs['recommended-latest'],
1519
{
1620
files: ['**/*.{ts,tsx}'],
17-
extends: [configs.eslintRecommended, configs.strictTypeChecked],
21+
extends: [
22+
configs.eslintRecommended,
23+
configs.strictTypeChecked,
24+
react.configs['recommended-type-checked'],
25+
],
1826
languageOptions: {
1927
parserOptions: {
2028
projectService: true,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"clean-pkg-json": "^1.3.0",
122122
"eslint-import-resolver-typescript": "^4.4.2",
123123
"eslint-plugin-import-x": "^4.15.0",
124+
"eslint-plugin-react-hooks": "^5.2.0",
124125
"nano-staged": "^0.8.0",
125126
"npm-run-all2": "^8.0.4",
126127
"prettier": "^3.5.3",

src/global/SiteOverrides/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ export const SiteOverrides = () => {
7171
requestAnimationFrame(() => {
7272
document.title = newTitle
7373
})
74-
}, [title])
74+
}, [
75+
articleTitle,
76+
frontmatter.title,
77+
frontmatter.titleSuffix,
78+
pageType,
79+
siteData,
80+
title,
81+
])
7582

7683
useEffect(() => {
7784
if (!logoText) {

src/global/VersionsNav/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const VersionsNav_ = () => {
106106
}
107107

108108
void fetchVersions().catch(noop)
109-
}, [])
109+
}, [version, versionsBase])
110110

111111
// hack way to detect nav menu recreation on theme change
112112
useEffect(() => {
@@ -120,6 +120,7 @@ const VersionsNav_ = () => {
120120
})
121121
const newNavMenu = getNavMenu()
122122
if (newNavMenu !== navMenu) {
123+
// eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
123124
setNavMenu(newNavMenu)
124125
} else if (navMenu.parentNode) {
125126
observer.observe(navMenu.parentNode, { childList: true })

src/runtime/components/ExternalSiteLink.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ const ExternalSiteLink_ = ({
3131
}: ExternalSiteLinkProps) => {
3232
const isPrint = useIsPrint()
3333

34-
const site = useMemo(() => virtual.sites?.find((s) => s.name === name), [])
34+
const site = useMemo(
35+
() => virtual.sites?.find((s) => s.name === name),
36+
[name],
37+
)
3538
const lang = useLang()
3639

3740
if (!site) {

src/runtime/components/K8sCrd.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const K8sCrdSchemaPart = ({
4242
}, [])
4343

4444
useEffect(() => {
45+
// eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
4546
setOpen(expandAll)
4647
}, [expandAll])
4748

@@ -73,8 +74,18 @@ export const K8sCrdSchemaPart = ({
7374
title={
7475
<>
7576
{name}
76-
{type && <code>{type}</code>}
77-
{required && <Badge>required</Badge>}
77+
{type && (
78+
<>
79+
{' '}
80+
<code>{type}</code>
81+
</>
82+
)}
83+
{required && (
84+
<>
85+
{' '}
86+
<Badge>required</Badge>
87+
</>
88+
)}
7889
</>
7990
}
8091
open={open}
@@ -122,8 +133,7 @@ export const K8sCrdSchema = ({
122133
<Markdown>{description}</Markdown>
123134
<div className="flex items-center">
124135
<span>
125-
<code>{version}</code>
126-
<Badge>version</Badge>
136+
<code>{version}</code> <Badge>version</Badge>
127137
</span>
128138
{!isPrint && properties != null && (
129139
<Button
@@ -171,7 +181,7 @@ export const K8sCrd = ({ name, crdPath }: K8sCrdProps) => {
171181
}
172182
return crd.metadata.name === name
173183
}) || [],
174-
[],
184+
[crdPath, name],
175185
)
176186

177187
if (!crd) {
@@ -182,8 +192,7 @@ export const K8sCrd = ({ name, crdPath }: K8sCrdProps) => {
182192
return (
183193
<>
184194
<X.p>
185-
<code>{crd.spec.group}</code>
186-
<Badge>group</Badge>
195+
<code>{crd.spec.group}</code> <Badge>group</Badge>
187196
</X.p>
188197
{crd.spec.versions.map((version) => (
189198
<K8sCrdSchema

src/runtime/components/K8sPermissionTable.tsx

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,33 +84,32 @@ const RolesPermission = ({
8484
})
8585
}
8686

87+
const allFunctionResources = Object.values(functionResourcesMap).reduce<
88+
Partial<Record<string, FunctionResource>>
89+
>(
90+
(acc, curr) =>
91+
Object.assign(
92+
acc,
93+
...curr.map((fr) => ({ [fr.metadata.name]: fr })),
94+
) as Partial<Record<string, FunctionResource>>,
95+
{},
96+
)
97+
8798
export const K8sPermissionTable = ({ functions }: K8sPermissionTableProps) => {
88-
const allFunctionResources = useMemo(
99+
const functionResources = useMemo(
89100
() =>
90-
Object.values(functionResourcesMap).reduce<
91-
Partial<Record<string, FunctionResource>>
92-
>(
93-
(acc, curr) =>
94-
Object.assign(
95-
acc,
96-
...curr.map((fr) => ({ [fr.metadata.name]: fr })),
97-
) as Partial<Record<string, FunctionResource>>,
98-
{},
99-
),
100-
[],
101+
functions.flatMap((name) => {
102+
const matched = allFunctionResources[name]
103+
if (!matched) {
104+
console.error(`FunctionResource \`${name}\` not found!\n`)
105+
return []
106+
}
107+
return matched
108+
}),
109+
// eslint-disable-next-line react-hooks/exhaustive-deps
110+
functions,
101111
)
102112

103-
const functionResources = useMemo(() => {
104-
return functions.flatMap((name) => {
105-
const matched = allFunctionResources[name]
106-
if (!matched) {
107-
console.error(`FunctionResource \`${name}\` not found!\n`)
108-
return []
109-
}
110-
return matched
111-
})
112-
}, [...functions])
113-
114113
const roleTemplates = useMemo(
115114
() =>
116115
sortBy(Object.values(roleTemplatesMap).flat(), [

src/runtime/components/Mermaid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const Mermaid = ({ className, children }: MermaidProps) => {
3232
}
3333

3434
void render()
35-
}, [children, isDark])
35+
}, [children, id, isDark])
3636

3737
return (
3838
<div

src/runtime/components/OpenAPIPath.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,19 @@ export const OpenAPIParameters = ({
5353
typeNode = <RefLink $ref={type.$ref} />
5454
}
5555
return (
56+
// eslint-disable-next-line @eslint-react/no-array-index-key
5657
<X.li key={index}>
57-
<code>{paramObj.name}</code>(<em>in {paramObj.in}</em>): {typeNode}
58-
{paramObj.required && <Badge>required</Badge>}
59-
<Markdown>{paramObj.description}</Markdown>
58+
<code>{paramObj.name}</code> (<em>in {paramObj.in}</em>): {typeNode}
59+
{paramObj.required && (
60+
<>
61+
{' '}
62+
<Badge>required</Badge>
63+
</>
64+
)}
65+
<>
66+
{' '}
67+
<Markdown>{paramObj.description}</Markdown>
68+
</>
6069
</X.li>
6170
)
6271
})}
@@ -195,7 +204,7 @@ export const OpenAPIPath = ({
195204
}
196205
}
197206
return []
198-
}, [])
207+
}, [openapiPath_, page.routePath, path])
199208

200209
if (!pathItem || !openapi) {
201210
console.error(`No OpenAPI path definition found for ${path}`)

0 commit comments

Comments
 (0)