From 85321888e004a712818a2141e5f9483c58e241a0 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 16 Aug 2026 18:21:01 +0800 Subject: [PATCH] =?UTF-8?q?chore(quality):=20=E4=BC=9A=E8=AF=9D=E6=94=B6?= =?UTF-8?q?=E5=B0=BE=20=E2=80=94=20=E6=9B=B4=E6=96=B0=20prompt/ideas=20?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=2014=20=E4=B8=AA=E5=AE=9E=E9=AA=8C=E7=BB=93?= =?UTF-8?q?=E8=AE=BA=E4=B8=8E=E5=88=BB=E6=84=8F=E4=BF=9D=E7=95=99=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .auto/ideas.md | 36 ++++++++++++++++++++++++++++-------- .auto/prompt.md | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/.auto/ideas.md b/.auto/ideas.md index 64a70560..22a138fc 100644 --- a/.auto/ideas.md +++ b/.auto/ideas.md @@ -1,10 +1,30 @@ # Ideas backlog (代码质量) -- 后端 204 个 *_test.go 被 repo golangci 配置 `tests: false` 跳过;可以用 - testifylint/usetesting/paralleltest 等对测试代码做一次质量扫描(当前基准不含测试,属于后续深化方向)。 -- biome check 发现 76 处(基本全是格式漂移);repo 只跑 format 不跑 check。 - 可作为独立的一次性格式化提交处理,不进基准(避免纯格式噪声污染 metric)。 -- repo `make code-check` 还有 `make format`(goimports + biome)契约:迭代中保持已改文件格式化干净。 -- 观察 go vet 已启用但 `unusedresult`/`copylocks` 等子检查默认关闭;若需要可考虑仅作发现用,不进基准。 -- errorlint 修复中有 4 处 `err != context.Canceled`,若 runner 实际从不 wrap, - 用 errors.Is 是更稳妥的最佳实践,且语义不变 —— 已验证三处 cmd 入口同构。 \ No newline at end of file +## 已尝试并收尾(2026-08-16 会话,14 个实验,108→8) + +- 生产代码 golangci 扩展集 13 类 linter 全量清理(modernize/perfsprint/ + errorlint/canonicalheader/usestdlibvars/intrange/wastedassign/errname/ + forcetypeassert/prealloc/gosec/recvcheck/exhaustive),剩余 8 处全部为 + 有据可查的刻意保留项(telegram %v、3 处嵌套 struct omitempty、 + 3 处 not-found 惯例、1 处 encoding/json 接收者混合)。 +- 测试代码质量维度(testifylint/usetesting/thelper)25→0。 +- 前端 eslint/tsc 0。 +- 修复中积累的工具经验:golangci-lint v2 `--fix` 的 import 管理不可靠, + 跑完必须 `goimports -w`;`--max-issues-per-linter=0` 才能拿到全量清单 + (默认 50 + max-same-issues=3 会掩盖重复模式);cyclop 与 exhaustive + 有张力(显式 case 计入复杂度)。 + +## 未来可深化方向(均经评估) + +- 测试可运行性修复:`go test ./internal/...` 目前在 main 上就有失败 + (无本地 redis、frpc 进程测试 flaky)。修复这些环境问题后,可以把 + `go test` 加入 checks.sh,解锁 paralleltest/tparallel 维度 + (t.Parallel 提速 + 正确性,目前因共享状态+不可运行而放弃)。 +- frontend biome 格式漂移(76 文件):一次性 `make format` 提交, + 与质量修复分开做,不进基准。 +- fieldalignment:结构体内存布局优化,但会改变 JSON key 顺序且有 + 位置字面量风险 —— 若做,需按文件人工核对,不进自动基准。 +- Go 1.26 新特性扫描:`go vet` 新分析器、golangci-lint 新 linter + (如 recvcheck 之后的 new receivers 检查)随版本跟进。 +- 文档/示例代码(docs/、scripts/)质量:目前不在 golangci 范围(tests:false + 之外还有 scripts 目录),可用同一扩展集扫 scripts/ 下的 main.go。 diff --git a/.auto/prompt.md b/.auto/prompt.md index 295761a1..9850f15b 100644 --- a/.auto/prompt.md +++ b/.auto/prompt.md @@ -114,4 +114,45 @@ otherwise). Already committed in setup. app/(main)/pages/detail/components/pages-source-card.tsx:275]; tsc 0). - Environment notes: golangci-lint 2.12.2 warm cache ~3s; eslint cold ~27s (ignore stderr pnpm noise); go vet+go build ~15-30s after edits. Some - go test failures on main are pre-existing (redis down, flaky frpc) — not ours. \ No newline at end of file + go test failures on main are pre-existing (redis down, flaky frpc) — not ours. + +### Session result (14 experiments, commits f1f6bb85→65c02ef7) + +108 → **8** (-92.6%) across 3 benchmark dimensions, all remaining 8 are +deliberate, documented keepers (see below). Never weakened a check; never +added nolint/eslint-disable; benchmark extensions were transparently +documented (test-code dimension run #12, exhaustive run #14). + +Fixed (zero behavior change, each reviewed): +- gosec 2→0 (saturating multiply pattern gosec accepts without nolint) +- modernize 37→5→3 (any, max/min, slices/maps, strings.Cut/SplitSeq, + strings.Builder; omitted omitted-lark: nested struct omitzero = wire change) +- perfsprint 18→0, canonicalheader 8→0, usestdlibvars 3→0, intrange 3→0, + wastedassign 7→0, errname 1→0, forcetypeassert 6→0, prealloc 2→0 +- errorlint 12→1 (errors.Is/As, %v→%w chains) +- recvcheck 7→1 (GORM TableName → pointer receiver; verified gorm source uses + reflect.New, tests pass) +- eslint 1→0 (exhaustive-deps: add stable `t` to dep array) +- test dimension 25→0 (testifylint 20, thelper 3, usetesting 2) +- exhaustive 12→0 (explicit enum cases = fail-explicit) + +Deliberate keepers (8) — do NOT "fix" without new evidence: +- errorlint 1: pkg/push/telegram.go %v — wrapping the original error would + change errors.Is matching semantics; it's intentionally textual context. +- modernize 3: nested-struct omitempty (client.go Release/Asset, + lark.go Content) — omitzero would CHANGE wire output (plain structs + serialize always today). +- nilnil 3: not-found/optional-result conventions — postgres_store.go + ClickHouseOperationalStats (interface contract, documented in comment), + openflare_apply_log.go GetLatestOpenFlareApplyLogByNodeID (tested), + github_source_action.go guarded outcome (callers check != nil). +- recvcheck 1: MillisecondDuration — encoding/json requires Marshal value + receiver + Unmarshal pointer receiver. + +Surveyed and rejected (noise/risk, do not add): +- fieldalignment (~100+): JSON key order change + positional literal risk. +- sloglint full / gocritic extras: 0 findings. +- paralleltest/tparallel: t.Parallel advice unsafe (shared DB/redis state; + tests not runnable in this env). +- biome format drift (76 files): pure formatting noise; repo's make format + covers it. \ No newline at end of file