【架构优化】拆分 scriptview.parseConfig 的模式校验、掩码列表校验并合并重复的排序比较函数

未关闭
#440 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@fx-kurumi 已经在做这个了。

开始于 2026年11月13日。

  • #442 来自 @fx-kurumi —— 未关闭

评估

难度
3/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
tooling

调研方向

Start with parseConfig in internal/scriptview/scriptview.go, where the mode checks, the masks/hide validation and the two slices.SortFunc comparators sit together. Extract the checks into the helper functions the issue names and merge the comparators, then confirm the existing TestConfig* and TestRefresh* tests still pass. Note that PR #442 is already open against this issue, so coordinate with it before starting a parallel change.

由索引模型根据 Issue 内容生成。

描述

现状问题

internal/scriptview/scriptview.go 的 parseConfig 约 50 行,同时做了四件事:JSON 解码、执行/刷新模式校验与 argv 空字节检查、masks/hide 列表合法性与去重校验、两个列表的排序。其中两段 slices.SortFunc 的比较函数几乎一样(只是长度升序/降序相反),重复书写,阅读时不容易看出两者的差别。

重构方案

  • 拆出 validateConfigMode(config Config) error:刷新/执行两种模式的互斥校验 + argv 空字节检查;
  • 拆出 validateMaskLists(lists ...[]string) error:每个列表的 ValidMask 与去重检查;
  • 两处排序比较函数合并为 maskOrder(longestFirst bool) func(a, b string) int;
  • parseConfig 只保留解码与依次调用,错误文案、返回值、排序结果均保持不变。

影响范围

仅 internal/scriptview/scriptview.go 与对应测试文件,不改导出接口与行为。

验证方式

  • 现有 TestConfig* / TestRefresh* 测试全部通过;
  • 新增单测覆盖 maskOrder 的两种顺序(含同长度按字典序)和 validateMaskLists 的重复/非法项;
  • gofmt、go vet ./internal/scriptview/、go test ./internal/scriptview/ 通过。
主要语言
Go
星标
141
派生
28
平均合并
1 天 15 小时
30 天内合并 PR
113

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Tencent/LoopForge 的其他 Issue

查看 Tencent/LoopForge 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。