autoresearch iter 22: delete lint suppressions that suppress nothing

24 of the 96 nolint directives were dead: they covered findings that no
longer exist. A stale suppression is not inert — it silently claims any
future finding for that linter in that scope, so a real problem raised
there would vanish without anyone noticing. Explanatory prose was kept as
ordinary comments.

Two directives proved load-bearing under the project gate even though
nolintlint reported them unused, and removing them exposed verified
contextcheck false positives: App.Run does forward a sigCtx derived from
the caller's context to Start, and the migration lock renewal must keep
its own deadline because the task context may already be canceled. Both
were restored, narrowed to the live linter, and given the reason the
originals lacked.
This commit is contained in:
ryan
2026-08-29 09:54:33 +08:00
parent b6f2221280
commit ad8384182c
14 changed files with 14 additions and 38 deletions
-2
View File
@@ -39,8 +39,6 @@ import (
) )
// newWaveletApp creates a core.App wired with Wavelet platform infrastructure, domain plugins, and profile drivers. // newWaveletApp creates a core.App wired with Wavelet platform infrastructure, domain plugins, and profile drivers.
//
//nolint:contextcheck
func newWaveletApp(profile core.Profile) *core.App { func newWaveletApp(profile core.Profile) *core.App {
app := core.NewApp( app := core.NewApp(
core.WithProfile(profile), core.WithProfile(profile),
+1 -3
View File
@@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// Package cmd provides CLI command entry points. // Package cmd provides CLI command entry points.
//
//nolint:unused
package cmd package cmd
import ( import (
@@ -14,7 +12,7 @@ import (
"strings" "strings"
) )
//nolint:unused // startup banner formatting utilities // startup banner formatting utilities
type startupState struct { type startupState struct {
mode string mode string
listensForHTTP bool listensForHTTP bool
+1 -7
View File
@@ -303,8 +303,6 @@ func (a *App) RunMigrations() error {
// 2. Dispatches database migrations via MigrationEngine. // 2. Dispatches database migrations via MigrationEngine.
// 3. Filters and starts drivers matching the active Profile. // 3. Filters and starts drivers matching the active Profile.
// 4. Emits "app:ready" on the EventBus. // 4. Emits "app:ready" on the EventBus.
//
//nolint:contextcheck
func (a *App) Start(ctx ...context.Context) error { func (a *App) Start(ctx ...context.Context) error {
a.mu.Lock() a.mu.Lock()
if a.running { if a.running {
@@ -386,8 +384,6 @@ func (a *App) Start(ctx ...context.Context) error {
// 2. Stops all started drivers in LIFO (reverse) order. // 2. Stops all started drivers in LIFO (reverse) order.
// 3. Disposes the Context (running registered OnDispose callbacks in LIFO order). // 3. Disposes the Context (running registered OnDispose callbacks in LIFO order).
// 4. Emits "app:stopped" on the EventBus. // 4. Emits "app:stopped" on the EventBus.
//
//nolint:contextcheck
func (a *App) Stop(ctx ...context.Context) error { func (a *App) Stop(ctx ...context.Context) error {
a.mu.Lock() a.mu.Lock()
if !a.running { if !a.running {
@@ -448,7 +444,7 @@ func (a *App) Stop(ctx ...context.Context) error {
// Run starts the application and blocks until an OS signal (SIGINT, SIGTERM) or context cancellation is received, // Run starts the application and blocks until an OS signal (SIGINT, SIGTERM) or context cancellation is received,
// then executes graceful shutdown. // then executes graceful shutdown.
// //
//nolint:contextcheck //nolint:contextcheck // Run forwards a sigCtx derived from the caller's context to Start; the rule cannot follow the variadic parameter
func (a *App) Run(ctx ...context.Context) error { func (a *App) Run(ctx ...context.Context) error {
var parent context.Context var parent context.Context
switch { switch {
@@ -505,8 +501,6 @@ func (a *App) ExecuteCLI(args ...string) error {
} }
// ExecuteCLIWithContext parses CLI arguments, configures the profile, and runs the application with the given context. // ExecuteCLIWithContext parses CLI arguments, configures the profile, and runs the application with the given context.
//
//nolint:contextcheck
func (a *App) ExecuteCLIWithContext(ctx context.Context, args ...string) error { func (a *App) ExecuteCLIWithContext(ctx context.Context, args ...string) error {
cliArgs := args cliArgs := args
if len(cliArgs) == 0 { if len(cliArgs) == 0 {
@@ -327,7 +327,7 @@ func GetPostgresInfo(ctx context.Context) model.DatabaseInfoResponse {
// OpenSQLiteExportFile opens the active SQLite database file together with its stat info. // OpenSQLiteExportFile opens the active SQLite database file together with its stat info.
func OpenSQLiteExportFile() (*os.File, os.FileInfo, error) { func OpenSQLiteExportFile() (*os.File, os.FileInfo, error) {
//nolint:gosec // export db file path is trusted // export db file path is trusted
f, err := os.Open(sqliteDatabasePath()) f, err := os.Open(sqliteDatabasePath())
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("%s: %w", errs.ErrOpenDatabaseFileFailed, err) return nil, nil, fmt.Errorf("%s: %w", errs.ErrOpenDatabaseFileFailed, err)
+3 -5
View File
@@ -10,7 +10,7 @@ import (
// fnv1a returns the 32-bit FNV-1a hash of a string // fnv1a returns the 32-bit FNV-1a hash of a string
// //
//nolint:mnd // FNV-1a 算法位移常量 // FNV-1a 算法位移常量
func fnv1a(str string) uint32 { func fnv1a(str string) uint32 {
var hash uint32 = 2166136261 var hash uint32 = 2166136261
for i := 0; i < len(str); i++ { for i := 0; i < len(str); i++ {
@@ -22,7 +22,7 @@ func fnv1a(str string) uint32 {
// fnv1aResume resumes FNV-1a hashing from a given state // fnv1aResume resumes FNV-1a hashing from a given state
// //
//nolint:mnd // FNV-1a 算法位移常量 // FNV-1a 算法位移常量
func fnv1aResume(state uint32, str string) uint32 { func fnv1aResume(state uint32, str string) uint32 {
h := state h := state
for i := 0; i < len(str); i++ { for i := 0; i < len(str); i++ {
@@ -33,15 +33,13 @@ func fnv1aResume(state uint32, str string) uint32 {
} }
// hashShift computes FNV-1a mix additions // hashShift computes FNV-1a mix additions
//
//nolint:mnd
func hashShift(h uint32) uint32 { func hashShift(h uint32) uint32 {
return (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24) return (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24)
} }
// prngFromHash generates a hex string of specified length using an initial hash state // prngFromHash generates a hex string of specified length using an initial hash state
// //
//nolint:mnd // xorshift 算法位移常量 // xorshift 算法位移常量
func prngFromHash(initialHash uint32, length int) string { func prngFromHash(initialHash uint32, length int) string {
state := initialHash state := initialHash
var result strings.Builder var result strings.Builder
@@ -68,7 +68,7 @@ func (p *CustomPusher) Send(ctx context.Context, cfg Config, _ string, body map[
bodyBytes, _ := io.ReadAll(io.LimitReader(resp.Body, maxCustomResponseBytes)) bodyBytes, _ := io.ReadAll(io.LimitReader(resp.Body, maxCustomResponseBytes))
upstreamResp := strings.TrimSpace(string(bodyBytes)) upstreamResp := strings.TrimSpace(string(bodyBytes))
if resp.StatusCode < 200 || resp.StatusCode >= 300 { //nolint:mnd if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return upstreamResp, fmt.Errorf("custom: http status %s", resp.Status) return upstreamResp, fmt.Errorf("custom: http status %s", resp.Status)
} }
@@ -34,8 +34,6 @@ type telegramErrorResponse struct {
} }
// Send 执行 Telegram 消息发送 // Send 执行 Telegram 消息发送
//
//nolint:cyclop
func (p *TelegramPusher) Send(ctx context.Context, cfg Config, target string, body map[string]any, template string, _ map[string]any) (string, error) { func (p *TelegramPusher) Send(ctx context.Context, cfg Config, target string, body map[string]any, template string, _ map[string]any) (string, error) {
if cfg.Secret == "" { if cfg.Secret == "" {
return "", errors.New("telegram: Bot Token (Secret) is required") return "", errors.New("telegram: Bot Token (Secret) is required")
@@ -899,8 +899,6 @@ type EventTrigger struct{}
var DefaultTrigger = &EventTrigger{} var DefaultTrigger = &EventTrigger{}
// Trigger receives event metadata and processes the event notification dispatch asynchronously. // Trigger receives event metadata and processes the event notification dispatch asynchronously.
//
//nolint:contextcheck
func (t *EventTrigger) Trigger(ctx context.Context, meta model.EventMetadata, body map[string]any) { func (t *EventTrigger) Trigger(ctx context.Context, meta model.EventMetadata, body map[string]any) {
asyncCtx := context.WithoutCancel(ctx) asyncCtx := context.WithoutCancel(ctx)
util.Go(func() { util.Go(func() {
@@ -55,8 +55,6 @@ type batchDownloadRequest struct {
// @Failure 401 {object} response.Any "未登录" // @Failure 401 {object} response.Any "未登录"
// @Failure 500 {object} response.Any "内部错误" // @Failure 500 {object} response.Any "内部错误"
// @Router /api/v1/upload [post] // @Router /api/v1/upload [post]
//
//nolint:revive
func UploadFile(c *gin.Context) { func UploadFile(c *gin.Context) {
c.Header("X-Content-Type-Options", "nosniff") c.Header("X-Content-Type-Options", "nosniff")
c.Header("Content-Security-Policy", "sandbox") c.Header("Content-Security-Policy", "sandbox")
@@ -108,7 +108,6 @@ func (h *MigrationHandler) Execute(ctx context.Context, payload []byte) (*contra
_ = cache.Delete(cleanupCtx, lockKey) _ = cache.Delete(cleanupCtx, lockKey)
}() }()
//nolint:contextcheck,gosec
util.Go(func() { util.Go(func() {
ticker := time.NewTicker(renewalInterval) ticker := time.NewTicker(renewalInterval)
defer ticker.Stop() defer ticker.Stop()
@@ -116,6 +115,7 @@ func (h *MigrationHandler) Execute(ctx context.Context, payload []byte) (*contra
select { select {
case <-ticker.C: case <-ticker.C:
renewCtx, cancel := context.WithTimeout(context.Background(), cleanupTimeout) renewCtx, cancel := context.WithTimeout(context.Background(), cleanupTimeout)
//nolint:contextcheck // renewal must carry its own deadline; the task context may already be canceled
_ = cache.Set(renewCtx, lockKey, "locked", time.Hour) _ = cache.Set(renewCtx, lockKey, "locked", time.Hour)
cancel() cancel()
case <-stopRenewal: case <-stopRenewal:
+2 -2
View File
@@ -20,7 +20,7 @@ const (
errPasswordEncryptFailed = "密码加密失败" errPasswordEncryptFailed = "密码加密失败"
//nolint:gosec // error message, not hardcoded credentials //nolint:gosec // error message, not hardcoded credentials
errPasswordUpdateFailed = "密码更新失败" errPasswordUpdateFailed = "密码更新失败"
//nolint:gosec // error message, not hardcoded credentials // error message, not hardcoded credentials
errPasswordEmpty = "password cannot be empty" errPasswordEmpty = "password cannot be empty"
) )
@@ -35,7 +35,7 @@ const (
errAdminCannotDelete = "管理员账号无法被删除" errAdminCannotDelete = "管理员账号无法被删除"
errCannotDeleteSelf = "不能删除当前登录用户" errCannotDeleteSelf = "不能删除当前登录用户"
errServiceUsernameEmpty = "user: username cannot be empty" errServiceUsernameEmpty = "user: username cannot be empty"
//nolint:gosec // error message, not hardcoded credentials // error message, not hardcoded credentials
errServiceOldPasswordIncorrect = "user: incorrect old password" errServiceOldPasswordIncorrect = "user: incorrect old password"
//nolint:gosec // error message, not hardcoded credentials //nolint:gosec // error message, not hardcoded credentials
errServicePasswordTooShort = "密码长度至少为 8 位" errServicePasswordTooShort = "密码长度至少为 8 位"
@@ -7,7 +7,7 @@ import "context"
// TaskResult 任务执行结果 // TaskResult 任务执行结果
// //
//nolint:revive // TaskResult 保留完整名称以避免与通用 Result 混淆 // TaskResult 保留完整名称以避免与通用 Result 混淆
type TaskResult struct { type TaskResult struct {
Message string // 结果摘要,如 "共清理 120 个文件,耗时 3.2s" Message string // 结果摘要,如 "共清理 120 个文件,耗时 3.2s"
Detail string // 可选的详细结果 JSON Detail string // 可选的详细结果 JSON
@@ -26,7 +26,7 @@ type PayloadValidator interface {
// 开发者只需实现 Execute 方法编写业务逻辑,在方法内通过 driver_asynq_worker.AppendLog(ctx, ...) 追加执行日志。 // 开发者只需实现 Execute 方法编写业务逻辑,在方法内通过 driver_asynq_worker.AppendLog(ctx, ...) 追加执行日志。
// 任务的创建、状态更新、错误记录、重试计数全部由框架透明处理。 // 任务的创建、状态更新、错误记录、重试计数全部由框架透明处理。
// //
//nolint:revive // TaskHandler 保留完整名称以避免与通用 Handler 混淆 // TaskHandler 保留完整名称以避免与通用 Handler 混淆
type TaskHandler interface { type TaskHandler interface {
// Execute 执行任务业务逻辑 // Execute 执行任务业务逻辑
// - ctx: 已注入 Trace Span 和 taskID 的上下文 // - ctx: 已注入 Trace Span 和 taskID 的上下文
@@ -10,7 +10,7 @@ import (
// TaskParam 任务参数定义 // TaskParam 任务参数定义
// //
//nolint:revive // TaskParam 保留完整名称以避免与通用 Param 混淆 // TaskParam 保留完整名称以避免与通用 Param 混淆
type TaskParam struct { type TaskParam struct {
Name string `json:"name"` // 参数键名 Name string `json:"name"` // 参数键名
Label string `json:"label"` // 显示名称 Label string `json:"label"` // 显示名称
@@ -22,7 +22,7 @@ type TaskParam struct {
// TaskMeta 任务元数据 // TaskMeta 任务元数据
// //
//nolint:revive // TaskMeta 保留完整名称以避免与通用 Meta 混淆 // TaskMeta 保留完整名称以避免与通用 Meta 混淆
type TaskMeta struct { type TaskMeta struct {
Type string `json:"type"` Type string `json:"type"`
AsynqTask string `json:"asynq_task"` AsynqTask string `json:"asynq_task"`
@@ -12,8 +12,6 @@ import (
) )
// TaskExecutionStatus 任务执行状态 // TaskExecutionStatus 任务执行状态
//
//nolint:revive
type TaskExecutionStatus string type TaskExecutionStatus string
// Task execution status constants. // Task execution status constants.
@@ -25,8 +23,6 @@ const (
) )
// TaskExecution 任务执行记录 // TaskExecution 任务执行记录
//
//nolint:revive
type TaskExecution struct { type TaskExecution struct {
ID uint64 `json:"id,string" gorm:"primaryKey"` ID uint64 `json:"id,string" gorm:"primaryKey"`
TaskID string `json:"task_id" gorm:"size:128;uniqueIndex;not null"` TaskID string `json:"task_id" gorm:"size:128;uniqueIndex;not null"`
@@ -92,8 +88,6 @@ func GetLatestTaskExecutionByTaskType(ctx context.Context, taskType string) (*Ta
} }
// TaskExecutionCleanupStats describes task execution log cleanup results. // TaskExecutionCleanupStats describes task execution log cleanup results.
//
//nolint:revive
type TaskExecutionCleanupStats struct { type TaskExecutionCleanupStats struct {
HighFrequencyDeleted int64 HighFrequencyDeleted int64
LowFrequencyDeleted int64 LowFrequencyDeleted int64