diff --git a/.auto/log.jsonl b/.auto/log.jsonl index 585bd01a..74e2d47c 100644 --- a/.auto/log.jsonl +++ b/.auto/log.jsonl @@ -4,3 +4,4 @@ {"run":3,"commit":"b76f707","metric":74,"metrics":{"golint_canonicalheader":8,"golint_errname":1,"golint_errorlint":12,"golint_forcetypeassert":3,"golint_gosec":0,"golint_intrange":3,"golint_modernize":5,"golint_nilnil":3,"golint_perfsprint":18,"golint_prealloc":3,"golint_recvcheck":7,"golint_usestdlibvars":3,"golint_wastedassign":7,"golint_total":73,"eslint_problems":1,"eslint_errors":0,"eslint_warnings":1,"tsc_errors":0,"measure_s":38},"status":"keep","description":"modernize 37→5(-32):interface{}→any、内置 max/min、slices/maps 辅助、strings.Cut/SplitSeq、strings.Builder(修复 mail.go O(n²) 拼接)。逐 hunk 核对语义等价;omitzero 冲突修复被自动跳过(wire 格式不变);手动清 4 处遗留 sort import + 2 处 QF1012。","timestamp":1786872502383,"segment":0,"confidence":17,"asi":{"hypothesis":"批量应用 modernize 自动修复(interface{}→any、max/min、slices.Sort/Contains、strings.Cut/SplitSeq、maps.Copy、strings.Builder)","insight":"golangci-lint --fix 会把 omitempty→omitzero 的冲突修复跳过(2个文件保留原 tag,wire 格式不变,好);但 fixer 会遗留未使用的 sort import,需手动清 4 处;mail.go 的 Builder 迁移附带暴露 2 个 QF1012,顺手用 fmt.Fprintf 修复。全部修复语义等价,已逐项核对 diff","next_action_hint":"剩余 modernize=5 应为 omitzero 冲突文件;下轮先处理 perfsprint(18):先看 --fix 是否安全再决定"}} {"run":4,"commit":"699e95f","metric":56,"metrics":{"golint_canonicalheader":8,"golint_errname":1,"golint_errorlint":12,"golint_forcetypeassert":3,"golint_gosec":0,"golint_intrange":3,"golint_modernize":5,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":3,"golint_recvcheck":7,"golint_usestdlibvars":3,"golint_wastedassign":7,"golint_total":55,"eslint_problems":1,"eslint_errors":0,"eslint_warnings":1,"tsc_errors":0,"measure_s":47},"status":"keep","description":"perfsprint 18→0:strconv.Itoa/FormatInt/FormatUint/FormatBool 替代 fmt.Sprintf、无动词 fmt.Errorf→errors.New、纯字符串拼接。全部语义等价(已核对 diff)。修正 fixer 遗留的 import 问题(引入 goimports 统一整理)。","timestamp":1786872884713,"segment":0,"confidence":3.0588235294117645,"asi":{"hypothesis":"perfsprint --fix:%d→strconv.Itoa/FormatInt、%t→FormatBool、%s+const→拼接、无动词 Errorf→errors.New","insight":"重要:golangci-lint v2 fixer 的 import 管理不可靠(删除/添加 import 会出错,53 个文件中 5 处报 undefined)+ 遗留未用 import。已安装 goimports(repo make format 本来就需要它),对改动文件统一 goimports -w 修复。后续只要用 --fix 就要记得跑 goimports -w","next_action_hint":"剩余大头:errorlint(12)、canonicalheader(8)(usestdlibvars 同类)、recvcheck(7)、wastedassign(7)。errorlint 需手工逐处判断;先做 canonicalheader+usestdlibvars(自动可修复但要核对)"}} {"run":5,"commit":"d0414b4","metric":45,"metrics":{"golint_canonicalheader":0,"golint_errname":1,"golint_errorlint":12,"golint_forcetypeassert":3,"golint_gosec":0,"golint_intrange":3,"golint_modernize":5,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":3,"golint_recvcheck":7,"golint_usestdlibvars":0,"golint_wastedassign":7,"golint_total":44,"eslint_problems":1,"eslint_errors":0,"eslint_warnings":1,"tsc_errors":0,"measure_s":38},"status":"keep","description":"canonicalheader 8→0 + usestdlibvars 3→0:header key 改为 Go 规范大小写(wire 格式本就如此,纯代码修正)、HTTP 方法常量替代字符串字面量。","timestamp":1786873098921,"segment":0,"confidence":2.1724137931034484,"asi":{"hypothesis":"canonicalheader+usestdlibvars --fix:Header key 统一规范大小写、GET/OPTIONS 等方法常量","insight":"GitHub header 修正前后的 wire 格式完全一致(Go 在 Set 时本来就会规范化),纯代码层面修正,零行为风险;下次遇到同类 100% 安全","next_action_hint":"剩余:errorlint(12) 需逐处人工判断(其中 3 处 err != context.Canceled、2 处 %v wrap、若干 ==/类型断言);recvcheck(7) 是模型接收者一致性;wastedassign(7) 删 TODO 赋值;intrange(3)/modernize(5)/nilnil(3)/prealloc(3)/forcetypeassert(3)/errname(1)/eslint(1)"}} +{"run":6,"commit":"ce28f63","metric":38,"metrics":{"golint_canonicalheader":0,"golint_errname":1,"golint_errorlint":12,"golint_forcetypeassert":3,"golint_gosec":0,"golint_intrange":3,"golint_modernize":5,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":3,"golint_recvcheck":7,"golint_usestdlibvars":0,"golint_wastedassign":0,"golint_total":37,"eslint_problems":1,"eslint_errors":0,"eslint_warnings":1,"tsc_errors":0,"measure_s":47},"status":"keep","description":"wastedassign 7→0:删除 7 处死初始化(snapshot.go 三连、push 三件套 content、format.go numStr),改 var 声明,零行为变化。","timestamp":1786873485497,"segment":0,"confidence":2.978723404255319,"asi":{"hypothesis":"wastedassign 7→0:删除 7 处死初始化(x := \"\" 后所有分支都赋值)改为 var 声明","insight":"replace 工具会归一化 replacement_text 的前导空白;对需要缩进的编辑直接用 sed/gofmt -w 处理更稳","next_action_hint":"剩余:errorlint(12)、recvcheck(7)、modernize(5)、intrange(3)、nilnil(3)、prealloc(3)、forcetypeassert(3)、errname(1)、eslint(1)"}} diff --git a/internal/apps/openflare/zone/legacy_import.go b/internal/apps/openflare/zone/legacy_import.go index 351f377e..ed7c09f3 100644 --- a/internal/apps/openflare/zone/legacy_import.go +++ b/internal/apps/openflare/zone/legacy_import.go @@ -292,7 +292,7 @@ func rebindSQL(query string, postgres bool) string { var b strings.Builder b.Grow(len(query) + len(query)/4) n := 0 - for i := 0; i < len(query); i++ { + for i := range len(query) { if query[i] == '?' { n++ b.WriteByte('$') diff --git a/internal/integration/githubrelease/client.go b/internal/integration/githubrelease/client.go index 505f459d..0195002d 100644 --- a/internal/integration/githubrelease/client.go +++ b/internal/integration/githubrelease/client.go @@ -100,7 +100,7 @@ type Release struct { Name string `json:"name,omitempty"` Draft bool `json:"draft"` Prerelease bool `json:"prerelease"` - PublishedAt time.Time `json:"published_at,omitempty"` + PublishedAt time.Time `json:"published_at,omitzero"` } // Asset contains the immutable target metadata returned by a resolve call. @@ -109,7 +109,7 @@ type Asset struct { Name string `json:"asset_name"` State string `json:"state"` Size int64 `json:"size"` - UpdatedAt time.Time `json:"updated_at,omitempty"` + UpdatedAt time.Time `json:"updated_at,omitzero"` Digest string `json:"digest,omitempty"` } @@ -533,7 +533,7 @@ func validTag(tag string) bool { strings.HasPrefix(tag, "/") || strings.HasSuffix(tag, "/") || strings.HasSuffix(tag, ".") { return false } - for _, component := range strings.Split(tag, "/") { + for component := range strings.SplitSeq(tag, "/") { if component == "" || strings.HasPrefix(component, ".") || strings.HasSuffix(component, ".lock") { return false } @@ -635,10 +635,7 @@ func verifyDeclaredDigest(declaredDigest string, checksum string) error { } func safeAssetNames(assets []Asset) []string { - count := len(assets) - if count > maxAssetErrorNames { - count = maxAssetErrorNames - } + count := min(len(assets), maxAssetErrorNames) names := make([]string, 0, count) for _, asset := range assets[:count] { name := safeText(asset.Name, maxSafeAssetNameLen) diff --git a/internal/repository/analytics/access_log_stats.go b/internal/repository/analytics/access_log_stats.go index 9527ec87..6192e843 100644 --- a/internal/repository/analytics/access_log_stats.go +++ b/internal/repository/analytics/access_log_stats.go @@ -50,7 +50,7 @@ func GetDailyTrend(ctx context.Context, days int) ([]DailyTrend, error) { defer func() { _ = rows.Close() }() trendMap := make(map[string]uint64, days) - for i := 0; i < days; i++ { + for i := range days { dateStr := time.Now().AddDate(0, 0, -i).Format("2006-01-02") trendMap[dateStr] = 0 } diff --git a/internal/repository/logstore/postgres_store.go b/internal/repository/logstore/postgres_store.go index 0ae1bdcf..338b10d7 100644 --- a/internal/repository/logstore/postgres_store.go +++ b/internal/repository/logstore/postgres_store.go @@ -1536,7 +1536,7 @@ func (s *userAccessLogGormStore) GetDailyTrend(ctx context.Context, days int) ([ counts[r.Date] = r.Cnt } out := make([]analyticsmodel.DailyTrend, 0, days) - for i := 0; i < days; i++ { + for i := range days { d := start.AddDate(0, 0, i).Format("2006-01-02") out = append(out, analyticsmodel.DailyTrend{Date: d, Count: counts[d]}) } diff --git a/pkg/cap/cap.go b/pkg/cap/cap.go index 240d12ff..904dffc2 100644 --- a/pkg/cap/cap.go +++ b/pkg/cap/cap.go @@ -215,7 +215,7 @@ func VerifyChallengeSolutions(token string, solutions []int, secret []byte, expe } tokenFnv := fnv1a(token) - for i := 0; i < payload.Count; i++ { + for i := range payload.Count { idxStr := strconv.Itoa(i + 1) saltSeed := fnv1aResume(tokenFnv, idxStr) targetSeed := fnv1aResume(saltSeed, "d") diff --git a/pkg/cap/prng.go b/pkg/cap/prng.go index 46df81dc..0a21dd1e 100644 --- a/pkg/cap/prng.go +++ b/pkg/cap/prng.go @@ -13,7 +13,7 @@ import ( //nolint:mnd // FNV-1a 算法位移常量 func fnv1a(str string) uint32 { var hash uint32 = 2166136261 - for i := 0; i < len(str); i++ { + for i := range len(str) { hash ^= uint32(str[i]) hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24) } @@ -25,7 +25,7 @@ func fnv1a(str string) uint32 { //nolint:mnd // FNV-1a 算法位移常量 func fnv1aResume(state uint32, str string) uint32 { h := state - for i := 0; i < len(str); i++ { + for i := range len(str) { h ^= uint32(str[i]) h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24) } diff --git a/pkg/logger/ringbuffer.go b/pkg/logger/ringbuffer.go index 89761e76..89fe211c 100644 --- a/pkg/logger/ringbuffer.go +++ b/pkg/logger/ringbuffer.go @@ -47,7 +47,7 @@ func (r *LogRingBuffer) Write(p []byte) (int, error) { data := string(p) start := 0 - for i := 0; i < len(data); i++ { + for i := range len(data) { if data[i] == '\n' { line := data[start:i] start = i + 1 @@ -114,7 +114,7 @@ func (r *LogRingBuffer) Query(cursor int, limit int) ([]LogEntry, bool) { // 将 ring buffer 中的有效条目按顺序收集 ordered := make([]LogEntry, 0, r.count) - for i := 0; i < r.count; i++ { + for i := range r.count { pos := (oldestPos + i) % r.cap ordered = append(ordered, r.entries[pos]) } diff --git a/pkg/util/version_compare.go b/pkg/util/version_compare.go index 3e53d269..36cbf58d 100644 --- a/pkg/util/version_compare.go +++ b/pkg/util/version_compare.go @@ -4,7 +4,7 @@ import "strconv" func compareVersionNumbers(left, right VersionInfo) int { maxLen := max(len(right.Numbers), len(left.Numbers)) - for index := 0; index < maxLen; index++ { + for index := range maxLen { leftValue := 0 rightValue := 0 if index < len(left.Numbers) { @@ -35,7 +35,7 @@ func compareGitDescribeDistance(left, right VersionInfo) int { func compareGitDescribeTails(left, right VersionInfo) int { maxLen := max(len(right.GitDescribeTail), len(left.GitDescribeTail)) - for index := 0; index < maxLen; index++ { + for index := range maxLen { if index >= len(left.GitDescribeTail) { return -1 } @@ -64,7 +64,7 @@ func comparePrereleaseIdentifiers(left, right VersionInfo) int { } maxLen := max(len(right.Prerelease), len(left.Prerelease)) - for index := 0; index < maxLen; index++ { + for index := range maxLen { if index >= len(left.Prerelease) { return -1 }