-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: rc-util remove all the .js suffix file #610
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
概述演练这次代码变更涉及多个文件的删除和少量文件的微调。主要删除的文件包括与DOM操作、React组件生命周期、实用函数和调试相关的模块。变更范围广泛,涵盖了工具函数、混合器、测试文件和一些核心实用方法。大多数删除似乎是为了精简代码库或重构现有实现。 变更
诗歌
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (6)
tests/utils.test.ts (1)
199-202
: 提示:在测试列表的浅拷贝场景时,建议继续关注对空值、未定义值的行为表现。此段代码确保了在合并对象时,对一些值为
undefined
的属性不会意外丢失或覆盖,测试覆盖面较好。若有更多场景,比如null
或复杂对象嵌套,可以考虑扩充测试用例,以进一步提高健壮性。src/ref.ts (1)
33-33
: 建议审视对 ESLint 规则的禁用该注释用于临时禁用
react-hooks/exhaustive-deps
,避免不必要的依赖警告。若这是预期行为,可保留;如非必要,建议删除或使用更细粒度的 ESLint 配置规则来避免对全局依赖校验的抑制。src/test/domHook.ts (3)
4-4
: 对ElementClass
类型使用(...params: any[]) => void
的泛型适应性建议进一步提升。
虽然使用any[]
能提高灵活性,但类型过于宽泛可能导致丢失参数类型信息。可考虑通过范型(generics)来更精确地限制参数类型,以便在调用方获得更好的类型推断和安全性。
15-18
: 建议在读取原始 Descriptor 时考虑对空值的显式处理。
若Object.getOwnPropertyDescriptor
返回undefined
,目前逻辑通过NO_EXIST
占位解决,但若有更深入的属性继承/原型链情况时,需确认是否有额外处理需求。
69-73
: 尾随逗号在函数声明位置影响不大,可根据团队规范选择去除以保持风格统一。
示例修正(如需一致性):-export function spyElementPrototype( - Element: ElementClass, - propName: string, - property: Property, -) { +export function spyElementPrototype( + Element: ElementClass, + propName: string, + property: Property +) {tests/hooks.test.tsx (1)
309-310
: 修复空数组解构的潜在 lint 问题此处出现空数组解构 (
const [] = useMergedState(undefined);
) 可能引发静态分析警告。若无实际用途,考虑删去或改成更具语义意义的写法。- const [] = useMergedState(undefined); + useMergedState(undefined);🧰 Tools
🪛 Biome (1.9.4)
[error] 310-310: Unexpected empty array pattern.
(lint/correctness/noEmptyPattern)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (32)
src/Children/mapSelf.js
(0 hunks)src/ContainerRender.js
(0 hunks)src/Dom/addEventListener.js
(0 hunks)src/Dom/class.js
(0 hunks)src/Dom/css.js
(0 hunks)src/Dom/support.js
(0 hunks)src/PortalWrapper.tsx
(0 hunks)src/PureRenderMixin.js
(0 hunks)src/createChainedFunction.js
(0 hunks)src/debug/diff.js
(0 hunks)src/deprecated.js
(0 hunks)src/getContainerRenderMixin.jsx
(0 hunks)src/guid.js
(0 hunks)src/hooks/useLayoutEffect.ts
(1 hunks)src/proxyObject.ts
(1 hunks)src/ref.ts
(1 hunks)src/setStyle.ts
(1 hunks)src/switchScrollingEffect.js
(0 hunks)src/test/domHook.ts
(3 hunks)src/unsafeLifecyclesPolyfill.js
(0 hunks)src/utils/set.ts
(2 hunks)src/warn.js
(0 hunks)tests/composeProps.test.ts
(2 hunks)tests/debug.test.js
(0 hunks)tests/domHook.test.ts
(1 hunks)tests/hooks-17.test.tsx
(2 hunks)tests/hooks.test.tsx
(14 hunks)tests/index.test.js
(0 hunks)tests/switchScrollingEffect.test.ts
(0 hunks)tests/toArray.test.tsx
(4 hunks)tests/utils.test.ts
(3 hunks)tests/warning.test.ts
(0 hunks)
💤 Files with no reviewable changes (20)
- src/deprecated.js
- src/guid.js
- src/Children/mapSelf.js
- tests/index.test.js
- tests/warning.test.ts
- src/warn.js
- src/ContainerRender.js
- src/createChainedFunction.js
- src/PureRenderMixin.js
- src/switchScrollingEffect.js
- src/Dom/support.js
- src/Dom/addEventListener.js
- tests/switchScrollingEffect.test.ts
- src/PortalWrapper.tsx
- src/unsafeLifecyclesPolyfill.js
- src/Dom/class.js
- src/getContainerRenderMixin.jsx
- src/debug/diff.js
- tests/debug.test.js
- src/Dom/css.js
✅ Files skipped from review due to trivial changes (4)
- src/hooks/useLayoutEffect.ts
- src/utils/set.ts
- src/setStyle.ts
- src/proxyObject.ts
🧰 Additional context used
🪛 Biome (1.9.4)
tests/hooks.test.tsx
[error] 310-310: Unexpected empty array pattern.
(lint/correctness/noEmptyPattern)
🔇 Additional comments (30)
tests/utils.test.ts (2)
175-175
: 建议:测试循环引用的要点十分清晰,验证成功。
此处对循环引用的测试用例能有效避免合并函数产生死循环,逻辑清晰且实现有意义。
220-222
: 建议:加强类对象与合并逻辑的测试覆盖。
用户类 User
定义了类型,清晰易读。合并函数在遇到自定义类实例时保持原引用,可确保不破坏原有对象的功能及属性。若需要进一步保证类实例中的原型链或方法完整,可以考虑添加更多单元测试。
tests/composeProps.test.ts (2)
9-14
: 添加 onDemo: undefined
有助于在测试中验证合并逻辑
从测试场景看,onDemo
会被后续的 patchProps
覆盖成函数,不存在运行时报错的风险。整体实现正常。
38-43
: 确保 onDemo
能被正确合并与调用
此段改动与前一个测试用例原则相同。在调用 composeProps
前后,可有效验证 onDemo
是否被正确覆盖并执行。
tests/toArray.test.tsx (5)
6-6
: 在组件声明中使用 Readonly<React.PropsWithChildren>
提升类型安全性!
这使组件的属性更具可读性,并能在编译期捕获潜在的子元素类型错误。
13-13
: 为 ulRef
指定 UL
类型可获得更精准的类型提示!
借助 React.createRef<UL>()
,可以在后续操作 ulRef.current
时充分利用类型检查的优势。
28-28
: 重复与上一处相同的改动。
将 ulRef
的类型标注为 UL
同样有助于保证类型正确性。
43-43
: 重复与上一处相同的改动。
将 ulRef
的类型标注为 UL
同样有助于保证类型正确性。
67-67
: 重复与上一处相同的改动。
将 ulRef
的类型标注为 UL
同样有助于保证类型正确性。
src/test/domHook.ts (3)
5-5
: 扩大 Property
类型签名对函数场景的兼容性值得肯定,但请注意避免滥用 any[]
。
当前写法能提供对回调/功能函数的支持,但若能结合具体用例限制函数参数类型,会进一步提升可维护性并减少潜在类型错误。
25-25
: 调用 spyProp
时建议补充返回值类型或输出行为测试。
虽然此处将 spyProp
视作函数,并通过 call
方式执行,但若返回值与预期不符或产生副作用,可能需要更细化的测试覆盖来保证逻辑健壮性。
58-62
: 保留和还原原有属性的实现看上去正确。
此处通过 Object.defineProperty
恢复原 Descriptor
,覆盖逻辑合理且有助于避免修改原型后对其他测试或模块造成影响。
tests/domHook.test.ts (1)
5-10
: 函数签名类型更明确,增强了可维护性
更新后的 spyTest
函数为参数提供了更严格的类型注解,有助于在单测中提前发现类型错误,推荐保持此改动。
tests/hooks-17.test.tsx (2)
20-23
: 使用 React.FC 并添加可选 props 类型声明
此处显式定义 Demo
的 id
类型为可选字符串,能够在组件属性传递时得到更好的类型提示。
25-27
: 严格限定函数参数类型
为 matchId
函数的参数添加 HTMLElement
和 string
类型,能提前过滤非法调用,提升测试的健壮性。
tests/hooks.test.tsx (15)
28-29
: 在函数组件上使用泛型类型声明
通过 React.FC<Readonly<{ open?: boolean; data?: string }>>
明确了 props
类型结构,便于后续维护。
53-61
: 抽离 defaultValue 与 value 的类型定义
此处使用 defaultValue
和 value
来控制输入,利用 useMergedState<string>
能简化可选参数的逻辑并提高安全性。
137-137
: 无状态组件的类型增强
Demo: React.FC = () => {}
让组件更加语义化,便于理解与重构。
152-155
: 测试函数增加类型定义
给 test
方法添加 name: string
及默认函数签名,避免使用时出现隐式的 any 类型,有助于在重构时减少潜在问题。
157-161
: 将 Demo 定义为泛型组件,规范 onChange 参数
清晰地定义了 onChange 的回调签名,可在测试中准确模拟事件并断言调用参数。
213-217
: 将 Demo 组件类型化,确保 value 的递交流程
此处针对 value?: number
的声明,可更好地追踪 state 流转,避免类型误用。
254-258
: 受控/非受控切换更易追踪
通过 Test: React.FC<Readonly<{ value?: number }>>
,可在用例中准确地验证 value 传入状态并确保 onChange 的正确性。
284-288
: 在点击事件中自动读取最新外部值
使用 Test: React.FC<Readonly<{ value?: number }>>
能确保外部传入的受控值类型正确,减少运行时错误。
321-324
: 进一步增强默认值逻辑
此处对 FC
组件使用 defaultValue
并在 useLayoutEffect
内设置依赖,使得逻辑清晰、类型安全。
364-366
: 在 Demo 中使用 useRef 与 useLayoutEffect
显式类型声明能帮助你在多次渲染时更好地跟踪 timesRef
的变化,提高可读性。
393-394
: 使用泛型为 useState 提供类型
Demo: React.FC = () => {}
中添加了 useState<number>
,可减少浮动类型带来的潜在 bug,且与逻辑保持一致。
439-440
: 销毁阶段异步 setState
Demo: React.FC = () => {}
中针对卸载后的定时回调,测试代码能捕获在组件卸载后不再进行 setState 的场景,避免内存泄露。
465-466
: 在 useId 示例中添加 props 类型
为 Demo
组件提供可选 id
参数,使测试逻辑能同时覆盖带 id 与不带 id 的情况。
470-470
: 函数签名增强:指定可选容器类型
对 matchId(container: HTMLElement, id: string)
的严格限定防止类型推断错误,并有助于在测试中快速发现不匹配的调用。
530-530
: SSR 环境下的 useLayoutEffect
通过 Demo: React.FC = () => {}
实验性验证 SSR 时不会触发警告,可见测试兼顾前后端一致性,推荐保留此实现。
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/[email protected] |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #610 +/- ##
==========================================
+ Coverage 89.90% 90.13% +0.22%
==========================================
Files 41 36 -5
Lines 991 912 -79
Branches 320 313 -7
==========================================
- Hits 891 822 -69
+ Misses 97 88 -9
+ Partials 3 2 -1 ☔ View full report in Codecov by Sentry. |
babel 配置调整一下,新版本不需要使用 babel runtime 了 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
package.json
(1 hunks)src/PortalWrapper.tsx
(3 hunks)src/hooks/useEvent.ts
(2 hunks)src/test/domHook.ts
(3 hunks)tests/Portal.test.tsx
(1 hunks)tests/setStyle.test.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- tests/setStyle.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/test/domHook.ts
- src/PortalWrapper.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
src/hooks/useEvent.ts
[error] 5-5: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
🔇 Additional comments (7)
tests/Portal.test.tsx (3)
195-196
: 变量命名更具描述性,提升代码可读性。
将 domContainer
替换为 curDomContainer
让人更容易理解容器在该测试场景中的作用,逻辑上无任何问题。
200-200
: 显式使用 React.FC
更好地利用了 TypeScript 的类型系统。
在此处指定函数组件类型,能够得到更完善的类型检查与提示,有助于维护大型项目的类型安全。
208-208
: 逻辑实现完善,满足测试需求。
通过将 curDomContainer
传递给 Portal
的 getContainer
,能够更准确地控制容器位置,符合测试场景的预期。
src/hooks/useEvent.ts (1)
17-17
: 导出方式更新合理。
此导出方式能更好地保持与项目其他文件的结构一致性,导入时也更加直观。
package.json (3)
28-28
: 代码检查脚本更新符合预期!
将 lint 脚本从 .js
更新为 .tsx,.ts
完全符合此 PR 向 TypeScript 迁移的目标。
Line range hint 41-68
: 请验证 TypeScript 相关配置的完整性
项目已具备完整的 TypeScript 开发环境:
- 已安装必要的
@types
声明文件 - 配置了最新版本的 TypeScript (v5.3.2)
- 支持 React 18 和实验性的 React 19
建议进行以下验证:
✅ Verification successful
TypeScript 配置已完善且源码已完全迁移至 TypeScript
项目的 TypeScript 开发环境配置完整且合理:
- tsconfig.json 包含了必要的编译选项:
- 支持最新的 ECMAScript 特性 (target: esnext)
- 正确配置了 JSX 支持
- 配置了模块解析和路径别名
- 启用了类型声明文件生成
- 所有源代码文件都已使用 .ts/.tsx 格式
- 完整的 TypeScript 工具链配置:
- 配置了 TypeScript 代码检查 (eslint)
- 包含了完整的测试套件
- 使用 father 进行 TypeScript 构建
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 检查是否存在 tsconfig.json 文件和其他必要的 TS 配置
echo "验证 TypeScript 配置文件..."
fd -e json -e js tsconfig
# 检查是否还有遗留的 .js 文件
echo "检查是否还有 .js 文件..."
fd -e js -E node_modules -E lib -E es
Length of output: 177
Script:
#!/bin/bash
# 检查 tsconfig.json 的具体配置内容
echo "检查 tsconfig.json 配置内容..."
cat tsconfig.json
# 检查是否有 TypeScript 源文件
echo "检查 TypeScript 源文件..."
fd -e ts -e tsx -E node_modules -E lib -E es
# 检查是否配置了 TypeScript 相关的测试和构建脚本
echo "检查 package.json 中的 TypeScript 相关配置..."
cat package.json | jq '.scripts'
Length of output: 2447
Line range hint 40-41
: 建议审查 Babel 运行时依赖
根据 PR 评论,新版本可能不再需要 Babel 运行时。建议验证是否仍需要 @babel/runtime
依赖。
✅ Verification successful
建议移除 @babel/runtime 依赖
根据检查结果,项目使用了 father 作为构建工具,且源码中没有直接使用 @babel/runtime。@babel/runtime 的引用仅存在于 node_modules 中的第三方依赖。由于:
- 项目使用 father 进行构建,它已经内置了必要的 Babel 配置
- 源码中没有直接使用 @babel/runtime 的 helpers
- 第三方依赖各自管理自己的 runtime 依赖
因此可以安全移除 package.json 中的 @babel/runtime 依赖。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 检查 Babel 配置和使用情况
echo "检查 Babel 配置..."
fd -e js -e json babel.config
fd -e js -e json .babelrc
# 检查是否有使用 @babel/runtime 的导入
echo "检查 @babel/runtime 的使用..."
rg "@babel/runtime" -t js -t ts -t tsx
Length of output: 224
Script:
#!/bin/bash
# 检查 Babel 配置文件
echo "检查 Babel 相关配置文件..."
find . -type f -name "babel*" -o -name ".babelrc*"
# 检查 package.json 中的构建脚本和依赖
echo "检查 package.json 中的构建配置..."
cat package.json | grep -A 10 '"scripts":'
cat package.json | grep -A 10 '"devDependencies":'
# 检查是否有使用 @babel/runtime 的导入(修正文件类型)
echo "检查 @babel/runtime 的使用..."
rg "@babel/runtime" -t js -t jsx -t ts
Length of output: 6820
Script:
#!/bin/bash
# 检查项目根目录下的构建配置
echo "检查项目构建配置..."
find . -maxdepth 1 -type f -name ".fatherrc.*" -o -name "father.config.*"
# 检查是否使用 father-build
echo "检查 father-build 配置..."
cat package.json | jq '.dependencies + .devDependencies | keys[] | select(contains("father"))'
# 检查 @babel/runtime 的实际引用(修正搜索命令)
echo "检查源码中的 @babel/runtime 引用..."
find . -type f -name "*.js" -o -name "*.jsx" -o -name "*.ts" -o -name "*.tsx" | xargs grep -l "@babel/runtime" 2>/dev/null
Length of output: 38765
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
.fatherrc.ts (1)
6-8
: 在 Father 配置中仅指定 Chrome 85 兼容目标可能影响跨浏览器支持
建议同时配置其他常见浏览器的目标版本,以便在更广泛的环境中保持良好的兼容性。这样不仅能兼顾不同用户的使用场景,也能减少后续在编译配置上的重复维护工作。
合并了再说! |
Ant Design v6 tasks ant-design/ant-design#52115
rc-util 删除 .js 后缀的文件
将 .js 后缀的测试用例重构为 .ts
Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
新特性
PortalWrapper
组件的滚动效果管理逻辑进行了简化,直接设置文档主体的溢出样式。文档
样式