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:
时瑾 authored and GitHub committed 2025-11-03 16:30:45 +08:00
1 parent d5b8f886d6
commit 06f6a542f5
651 files changed
+37978 -37584

No files matched your search

+59 -59
View File
@@ -3,19 +3,19 @@ import {
HTMLMotionProps,
TargetAndTransition,
Transition,
motion
} from 'motion/react'
motion,
} from 'motion/react';
import {
forwardRef,
useCallback,
useEffect,
useImperativeHandle,
useMemo,
useState
} from 'react'
useState,
} from 'react';
function cn(...classes: (string | undefined | null | boolean)[]): string {
return classes.filter(Boolean).join(' ')
function cn (...classes: (string | undefined | null | boolean)[]): string {
return classes.filter(Boolean).join(' ');
}
export interface RotatingTextRef {
@@ -73,65 +73,65 @@ const RotatingText = forwardRef<RotatingTextRef, RotatingTextProps>(
},
ref
) => {
const [currentTextIndex, setCurrentTextIndex] = useState<number>(0)
const [currentTextIndex, setCurrentTextIndex] = useState<number>(0);
const splitIntoCharacters = (text: string): string[] => {
return Array.from(text)
}
return Array.from(text);
};
const elements = useMemo(() => {
const currentText: string = texts[currentTextIndex]
const currentText: string = texts[currentTextIndex];
if (splitBy === 'characters') {
const words = currentText.split(' ')
const words = currentText.split(' ');
return words.map((word, i) => ({
characters: splitIntoCharacters(word),
needsSpace: i !== words.length - 1
}))
needsSpace: i !== words.length - 1,
}));
}
if (splitBy === 'words') {
return currentText.split(' ').map((word, i, arr) => ({
characters: [word],
needsSpace: i !== arr.length - 1
}))
needsSpace: i !== arr.length - 1,
}));
}
if (splitBy === 'lines') {
return currentText.split('\n').map((line, i, arr) => ({
characters: [line],
needsSpace: i !== arr.length - 1
}))
needsSpace: i !== arr.length - 1,
}));
}
return currentText.split(splitBy).map((part, i, arr) => ({
characters: [part],
needsSpace: i !== arr.length - 1
}))
}, [texts, currentTextIndex, splitBy])
needsSpace: i !== arr.length - 1,
}));
}, [texts, currentTextIndex, splitBy]);
const getStaggerDelay = useCallback(
(index: number, totalChars: number): number => {
const total = totalChars
if (staggerFrom === 'first') return index * staggerDuration
if (staggerFrom === 'last') return (total - 1 - index) * staggerDuration
const total = totalChars;
if (staggerFrom === 'first') return index * staggerDuration;
if (staggerFrom === 'last') return (total - 1 - index) * staggerDuration;
if (staggerFrom === 'center') {
const center = Math.floor(total / 2)
return Math.abs(center - index) * staggerDuration
const center = Math.floor(total / 2);
return Math.abs(center - index) * staggerDuration;
}
if (staggerFrom === 'random') {
const randomIndex = Math.floor(Math.random() * total)
return Math.abs(randomIndex - index) * staggerDuration
const randomIndex = Math.floor(Math.random() * total);
return Math.abs(randomIndex - index) * staggerDuration;
}
return Math.abs((staggerFrom as number) - index) * staggerDuration
return Math.abs((staggerFrom as number) - index) * staggerDuration;
},
[staggerFrom, staggerDuration]
)
);
const handleIndexChange = useCallback(
(newIndex: number) => {
setCurrentTextIndex(newIndex)
if (onNext) onNext(newIndex)
setCurrentTextIndex(newIndex);
if (onNext) onNext(newIndex);
},
[onNext]
)
);
const next = useCallback(() => {
const nextIndex =
@@ -139,11 +139,11 @@ const RotatingText = forwardRef<RotatingTextRef, RotatingTextProps>(
? loop
? 0
: currentTextIndex
: currentTextIndex + 1
: currentTextIndex + 1;
if (nextIndex !== currentTextIndex) {
handleIndexChange(nextIndex)
handleIndexChange(nextIndex);
}
}, [currentTextIndex, texts.length, loop, handleIndexChange])
}, [currentTextIndex, texts.length, loop, handleIndexChange]);
const previous = useCallback(() => {
const prevIndex =
@@ -151,27 +151,27 @@ const RotatingText = forwardRef<RotatingTextRef, RotatingTextProps>(
? loop
? texts.length - 1
: currentTextIndex
: currentTextIndex - 1
: currentTextIndex - 1;
if (prevIndex !== currentTextIndex) {
handleIndexChange(prevIndex)
handleIndexChange(prevIndex);
}
}, [currentTextIndex, texts.length, loop, handleIndexChange])
}, [currentTextIndex, texts.length, loop, handleIndexChange]);
const jumpTo = useCallback(
(index: number) => {
const validIndex = Math.max(0, Math.min(index, texts.length - 1))
const validIndex = Math.max(0, Math.min(index, texts.length - 1));
if (validIndex !== currentTextIndex) {
handleIndexChange(validIndex)
handleIndexChange(validIndex);
}
},
[texts.length, currentTextIndex, handleIndexChange]
)
);
const reset = useCallback(() => {
if (currentTextIndex !== 0) {
handleIndexChange(0)
handleIndexChange(0);
}
}, [currentTextIndex, handleIndexChange])
}, [currentTextIndex, handleIndexChange]);
useImperativeHandle(
ref,
@@ -179,16 +179,16 @@ const RotatingText = forwardRef<RotatingTextRef, RotatingTextProps>(
next,
previous,
jumpTo,
reset
reset,
}),
[next, previous, jumpTo, reset]
)
);
useEffect(() => {
if (!auto) return
const intervalId = setInterval(next, rotationInterval)
return () => clearInterval(intervalId)
}, [next, rotationInterval, auto])
if (!auto) return;
const intervalId = setInterval(next, rotationInterval);
return () => clearInterval(intervalId);
}, [next, rotationInterval, auto]);
return (
<motion.span
@@ -200,7 +200,7 @@ const RotatingText = forwardRef<RotatingTextRef, RotatingTextProps>(
layout
transition={transition}
>
<span className="sr-only">{texts[currentTextIndex]}</span>
<span className='sr-only'>{texts[currentTextIndex]}</span>
<AnimatePresence
mode={animatePresenceMode}
initial={animatePresenceInitial}
@@ -213,7 +213,7 @@ const RotatingText = forwardRef<RotatingTextRef, RotatingTextProps>(
: 'flex flex-wrap whitespace-pre-wrap relative'
)}
layout
aria-hidden="true"
aria-hidden='true'
initial={initial as HTMLMotionProps<'div'>['initial']}
animate={animate as HTMLMotionProps<'div'>['animate']}
exit={exit as HTMLMotionProps<'div'>['exit']}
@@ -221,7 +221,7 @@ const RotatingText = forwardRef<RotatingTextRef, RotatingTextProps>(
{elements.map((wordObj, wordIndex, array) => {
const previousCharsCount = array
.slice(0, wordIndex)
.reduce((sum, word) => sum + word.characters.length, 0)
.reduce((sum, word) => sum + word.characters.length, 0);
return (
<span
key={wordIndex}
@@ -241,7 +241,7 @@ const RotatingText = forwardRef<RotatingTextRef, RotatingTextProps>(
(sum, word) => sum + word.characters.length,
0
)
)
),
}}
className={cn('inline-block', elementLevelClassName)}
>
@@ -249,17 +249,17 @@ const RotatingText = forwardRef<RotatingTextRef, RotatingTextProps>(
</motion.span>
))}
{wordObj.needsSpace && (
<span className="whitespace-pre"> </span>
<span className='whitespace-pre'> </span>
)}
</span>
)
);
})}
</motion.div>
</AnimatePresence>
</motion.span>
)
);
}
)
);
RotatingText.displayName = 'RotatingText'
export default RotatingText
RotatingText.displayName = 'RotatingText';
export default RotatingText;