refactor: 优化eslint配置,提升代码质量 (#1341)

* feat: 统一并标准化eslint

* lint: napcat.webui

* lint: napcat.webui

* lint: napcat.core

* build: fix

* lint: napcat.webui

* refactor: 重构eslint

* Update README.md
This commit is contained in:
时瑾
2025-11-03 16:30:45 +08:00
committed by GitHub
parent d5b8f886d6
commit 06f6a542f5
651 changed files with 37981 additions and 37587 deletions

View File

@@ -1,11 +1,11 @@
import { Chip } from '@heroui/chip'
import { Tooltip } from '@heroui/tooltip'
import { motion } from 'motion/react'
import React, { useState } from 'react'
import toast from 'react-hot-toast'
import { TbSquareRoundedChevronRightFilled } from 'react-icons/tb'
import { Chip } from '@heroui/chip';
import { Tooltip } from '@heroui/tooltip';
import { motion } from 'motion/react';
import React, { useState } from 'react';
import toast from 'react-hot-toast';
import { TbSquareRoundedChevronRightFilled } from 'react-icons/tb';
import type { LiteralValue, ParsedSchema } from '@/utils/zod'
import type { LiteralValue, ParsedSchema } from '@/utils/zod';
interface DisplayStructProps {
schema: ParsedSchema | ParsedSchema[]
@@ -13,84 +13,86 @@ interface DisplayStructProps {
const SchemaType = ({
type,
value
value,
}: {
type: string
value?: LiteralValue
}) => {
let name = type
let name = type;
switch (type) {
case 'union':
name = '联合类型'
break
name = '联合类型';
break;
case 'value':
name = '固定值'
break
name = '固定值';
break;
}
let chipColor: 'primary' | 'success' | 'primary' | 'warning' | 'secondary' =
'primary'
'primary';
switch (type) {
case 'enum':
chipColor = 'warning'
break
chipColor = 'warning';
break;
case 'union':
chipColor = 'secondary'
break
chipColor = 'secondary';
break;
case 'array':
chipColor = 'primary'
break
chipColor = 'primary';
break;
case 'object':
chipColor = 'success'
break
chipColor = 'success';
break;
}
return (
<Chip size="sm" color={chipColor} variant="flat">
<Chip size='sm' color={chipColor} variant='flat'>
{name}
{type === 'value' && (
<span className="px-1 rounded-full bg-primary-400 text-white ml-1">
<span className='px-1 rounded-full bg-primary-400 text-white ml-1'>
{value}
</span>
)}
</Chip>
)
}
);
};
const SchemaLabel: React.FC<{
schema: ParsedSchema
}> = ({ schema }) => (
<>
{Array.isArray(schema.type) ? (
schema.type.map((type) => (
<SchemaType key={type} type={type} value={schema?.value} />
))
) : (
<SchemaType type={schema.type} value={schema?.value} />
)}
{Array.isArray(schema.type)
? (
schema.type.map((type) => (
<SchemaType key={type} type={type} value={schema?.value} />
))
)
: (
<SchemaType type={schema.type} value={schema?.value} />
)}
{schema.optional && (
<Chip size="sm" color="default" variant="flat">
<Chip size='sm' color='default' variant='flat'>
</Chip>
)}
{schema.description && (
<span className="text-xs text-default-400">{schema.description}</span>
<span className='text-xs text-default-400'>{schema.description}</span>
)}
</>
)
);
const SchemaContainer: React.FC<{
schema: ParsedSchema
children: React.ReactNode
}> = ({ schema, children }) => {
const [expanded, setExpanded] = useState(false)
const [expanded, setExpanded] = useState(false);
const toggleExpand = () => setExpanded(!expanded)
const toggleExpand = () => setExpanded(!expanded);
return (
<div className="mb-2">
<div className='mb-2'>
<div
onClick={toggleExpand}
className="md:cursor-pointer flex items-center gap-1"
className='md:cursor-pointer flex items-center gap-1'
>
<motion.div
initial={{ rotate: 0 }}
@@ -98,13 +100,13 @@ const SchemaContainer: React.FC<{
>
<TbSquareRoundedChevronRightFilled />
</motion.div>
<Tooltip content="点击复制" placement="top" showArrow>
<Tooltip content='点击复制' placement='top' showArrow>
<span
className="border-b border-transparent border-dashed hover:border-primary-400"
className='border-b border-transparent border-dashed hover:border-primary-400'
onClick={(e) => {
e.stopPropagation()
navigator.clipboard.writeText(schema.name || '')
toast.success('已复制')
e.stopPropagation();
navigator.clipboard.writeText(schema.name || '');
toast.success('已复制');
}}
>
{schema.name}
@@ -113,30 +115,32 @@ const SchemaContainer: React.FC<{
<SchemaLabel schema={schema} />
</div>
<motion.div
className="ml-5 overflow-hidden"
className='ml-5 overflow-hidden'
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: expanded ? 1 : 0, height: expanded ? 'auto' : 0 }}
>
<div className="h-2"></div>
<div className='h-2' />
{children}
</motion.div>
</div>
)
}
);
};
const RenderSchema: React.FC<{ schema: ParsedSchema }> = ({ schema }) => {
if (schema.type === 'object') {
return (
<SchemaContainer schema={schema}>
{schema.children && schema.children.length > 0 ? (
schema.children.map((child, i) => (
<RenderSchema key={child.name || i} schema={child} />
))
) : (
<div>{`{}`}</div>
)}
{schema.children && schema.children.length > 0
? (
schema.children.map((child, i) => (
<RenderSchema key={child.name || i} schema={child} />
))
)
: (
<div>{'{}'}</div>
)}
</SchemaContainer>
)
);
}
if (schema.type === 'array' || schema.type === 'union') {
@@ -146,37 +150,37 @@ const RenderSchema: React.FC<{ schema: ParsedSchema }> = ({ schema }) => {
<RenderSchema key={child.name || i} schema={child} />
))}
</SchemaContainer>
)
);
}
if (schema.type === 'enum' && Array.isArray(schema.enum)) {
return (
<SchemaContainer schema={schema}>
<div className="flex gap-1 items-center">
<div className='flex gap-1 items-center'>
{schema.enum?.map((value, i) => (
<Chip
key={value?.toString() || i}
size="sm"
variant="flat"
color="success"
size='sm'
variant='flat'
color='success'
>
{value?.toString()}
</Chip>
))}
</div>
</SchemaContainer>
)
);
}
return (
<div className="mb-2 flex items-center gap-1 pl-5">
<Tooltip content="点击复制" placement="top" showArrow>
<div className='mb-2 flex items-center gap-1 pl-5'>
<Tooltip content='点击复制' placement='top' showArrow>
<span
className="border-b border-transparent border-dashed hover:border-primary-400 md:cursor-pointer"
className='border-b border-transparent border-dashed hover:border-primary-400 md:cursor-pointer'
onClick={(e) => {
e.stopPropagation()
navigator.clipboard.writeText(schema.name || '')
toast.success('已复制')
e.stopPropagation();
navigator.clipboard.writeText(schema.name || '');
toast.success('已复制');
}}
>
{schema.name}
@@ -184,19 +188,21 @@ const RenderSchema: React.FC<{ schema: ParsedSchema }> = ({ schema }) => {
</Tooltip>
<SchemaLabel schema={schema} />
</div>
)
}
);
};
const DisplayStruct: React.FC<DisplayStructProps> = ({ schema }) => {
return (
<div className="p-4 bg-content2 rounded-lg bg-opacity-50">
{Array.isArray(schema) ? (
schema.map((s, i) => <RenderSchema key={s.name || i} schema={s} />)
) : (
<RenderSchema schema={schema} />
)}
<div className='p-4 bg-content2 rounded-lg bg-opacity-50'>
{Array.isArray(schema)
? (
schema.map((s, i) => <RenderSchema key={s.name || i} schema={s} />)
)
: (
<RenderSchema schema={schema} />
)}
</div>
)
}
);
};
export default DisplayStruct
export default DisplayStruct;