Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quick-zoos-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alauda/doom": patch
---

chore: enable `eslint-plugin-react-hooks` and `@eslint-react/eslint-plugin`, fix related reports
10 changes: 9 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// @ts-check

import eslint from '@eslint/js'
import react from '@eslint-react/eslint-plugin'
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
import { importX } from 'eslint-plugin-import-x'
import * as reactHooks from 'eslint-plugin-react-hooks'
import { config, configs } from 'typescript-eslint'

export default config(
Expand All @@ -12,9 +14,15 @@ export default config(
eslint.configs.recommended,
importX.flatConfigs.recommended,
importX.flatConfigs.typescript,
react.configs.recommended,
reactHooks.configs['recommended-latest'],
{
files: ['**/*.{ts,tsx}'],
extends: [configs.eslintRecommended, configs.strictTypeChecked],
extends: [
configs.eslintRecommended,
configs.strictTypeChecked,
react.configs['recommended-type-checked'],
],
languageOptions: {
parserOptions: {
projectService: true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"clean-pkg-json": "^1.3.0",
"eslint-import-resolver-typescript": "^4.4.2",
"eslint-plugin-import-x": "^4.15.0",
"eslint-plugin-react-hooks": "^5.2.0",
"nano-staged": "^0.8.0",
"npm-run-all2": "^8.0.4",
"prettier": "^3.5.3",
Expand Down
9 changes: 8 additions & 1 deletion src/global/SiteOverrides/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ export const SiteOverrides = () => {
requestAnimationFrame(() => {
document.title = newTitle
})
}, [title])
}, [
articleTitle,
frontmatter.title,
frontmatter.titleSuffix,
pageType,
siteData,
title,
])

useEffect(() => {
if (!logoText) {
Expand Down
3 changes: 2 additions & 1 deletion src/global/VersionsNav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const VersionsNav_ = () => {
}

void fetchVersions().catch(noop)
}, [])
}, [version, versionsBase])

// hack way to detect nav menu recreation on theme change
useEffect(() => {
Expand All @@ -120,6 +120,7 @@ const VersionsNav_ = () => {
})
const newNavMenu = getNavMenu()
if (newNavMenu !== navMenu) {
// eslint-disable-next-line @eslint-react/hooks-extra/no-direct-set-state-in-use-effect
setNavMenu(newNavMenu)
} else if (navMenu.parentNode) {
observer.observe(navMenu.parentNode, { childList: true })
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/components/ExternalSiteLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const ExternalSiteLink_ = ({
}: ExternalSiteLinkProps) => {
const isPrint = useIsPrint()

const site = useMemo(() => virtual.sites?.find((s) => s.name === name), [])
const site = useMemo(
() => virtual.sites?.find((s) => s.name === name),
[name],
)
const lang = useLang()

if (!site) {
Expand Down
23 changes: 16 additions & 7 deletions src/runtime/components/K8sCrd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const K8sCrdSchemaPart = ({
}, [])

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

Expand Down Expand Up @@ -73,8 +74,18 @@ export const K8sCrdSchemaPart = ({
title={
<>
{name}
{type && <code>{type}</code>}
{required && <Badge>required</Badge>}
{type && (
<>
{' '}
<code>{type}</code>
</>
)}
{required && (
<>
{' '}
<Badge>required</Badge>
</>
)}
</>
}
open={open}
Expand Down Expand Up @@ -122,8 +133,7 @@ export const K8sCrdSchema = ({
<Markdown>{description}</Markdown>
<div className="flex items-center">
<span>
<code>{version}</code>
<Badge>version</Badge>
<code>{version}</code> <Badge>version</Badge>
</span>
{!isPrint && properties != null && (
<Button
Expand Down Expand Up @@ -171,7 +181,7 @@ export const K8sCrd = ({ name, crdPath }: K8sCrdProps) => {
}
return crd.metadata.name === name
}) || [],
[],
[crdPath, name],
)

if (!crd) {
Expand All @@ -182,8 +192,7 @@ export const K8sCrd = ({ name, crdPath }: K8sCrdProps) => {
return (
<>
<X.p>
<code>{crd.spec.group}</code>
<Badge>group</Badge>
<code>{crd.spec.group}</code> <Badge>group</Badge>
</X.p>
{crd.spec.versions.map((version) => (
<K8sCrdSchema
Expand Down
45 changes: 22 additions & 23 deletions src/runtime/components/K8sPermissionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,32 @@ const RolesPermission = ({
})
}

const allFunctionResources = Object.values(functionResourcesMap).reduce<
Partial<Record<string, FunctionResource>>
>(
(acc, curr) =>
Object.assign(
acc,
...curr.map((fr) => ({ [fr.metadata.name]: fr })),
) as Partial<Record<string, FunctionResource>>,
{},
)

export const K8sPermissionTable = ({ functions }: K8sPermissionTableProps) => {
const allFunctionResources = useMemo(
const functionResources = useMemo(
() =>
Object.values(functionResourcesMap).reduce<
Partial<Record<string, FunctionResource>>
>(
(acc, curr) =>
Object.assign(
acc,
...curr.map((fr) => ({ [fr.metadata.name]: fr })),
) as Partial<Record<string, FunctionResource>>,
{},
),
[],
functions.flatMap((name) => {
const matched = allFunctionResources[name]
if (!matched) {
console.error(`FunctionResource \`${name}\` not found!\n`)
return []
}
return matched
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
functions,
)

const functionResources = useMemo(() => {
return functions.flatMap((name) => {
const matched = allFunctionResources[name]
if (!matched) {
console.error(`FunctionResource \`${name}\` not found!\n`)
return []
}
return matched
})
}, [...functions])

const roleTemplates = useMemo(
() =>
sortBy(Object.values(roleTemplatesMap).flat(), [
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/Mermaid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Mermaid = ({ className, children }: MermaidProps) => {
}

void render()
}, [children, isDark])
}, [children, id, isDark])

return (
<div
Expand Down
17 changes: 13 additions & 4 deletions src/runtime/components/OpenAPIPath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ export const OpenAPIParameters = ({
typeNode = <RefLink $ref={type.$ref} />
}
return (
// eslint-disable-next-line @eslint-react/no-array-index-key
<X.li key={index}>
<code>{paramObj.name}</code>(<em>in {paramObj.in}</em>): {typeNode}
{paramObj.required && <Badge>required</Badge>}
<Markdown>{paramObj.description}</Markdown>
<code>{paramObj.name}</code> (<em>in {paramObj.in}</em>): {typeNode}
{paramObj.required && (
<>
{' '}
<Badge>required</Badge>
</>
)}
<>
{' '}
<Markdown>{paramObj.description}</Markdown>
</>
</X.li>
)
})}
Expand Down Expand Up @@ -195,7 +204,7 @@ export const OpenAPIPath = ({
}
}
return []
}, [])
}, [openapiPath_, page.routePath, path])

if (!pathItem || !openapi) {
console.error(`No OpenAPI path definition found for ${path}`)
Expand Down
18 changes: 9 additions & 9 deletions src/runtime/components/OpenAPIRef.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export const OpenAPIProperties = ({
}) => {
return (
<X.ul>
{Object.entries(properties).map(([name, property], index) => (
<X.li key={index}>
{Object.entries(properties).map(([name, property]) => (
<X.li key={name}>
<OpenAPIProperty name={name} property={property} openapi={openapi} />
</X.li>
))}
Expand Down Expand Up @@ -172,15 +172,10 @@ export const OpenAPIRef = ({
}
}
return []
}, [])

if (!schemaItem || !openapi) {
console.error(`No OpenAPI schema definition found for ${schema}\n`)
return null
}
}, [openapiPath_, schema])

const refs = useMemo(() => {
if (collectRefs) {
if (collectRefs && openapi) {
return getRefsForSchema(
openapi,
schema,
Expand All @@ -189,6 +184,11 @@ export const OpenAPIRef = ({
}
}, [collectRefs, openapi, page.routePath, schema])

if (!schemaItem || !openapi) {
console.error(`No OpenAPI schema definition found for ${schema}\n`)
return null
}

return (
<>
<HeadingTitle uid={uid} slug={schema} level={2}>
Expand Down
Loading