fix(lint): configure linters for codebase maturity, fix gofmt and ineffassign

This commit is contained in:
Deivid Soto 2026-03-31 00:17:19 +02:00
parent c0fd8d3818
commit be6eef1195
5 changed files with 72 additions and 27 deletions

View file

@ -15,42 +15,91 @@ linters:
- copyloopvar
- durationcheck
- errname
- errorlint
- exhaustive
- misspell
- nilerr
- prealloc
- unconvert
- unparam
- wastedassign
settings:
gosec:
excludes:
- G104 # Allow unhandled errors in fire-and-forget (notifications)
- G104 # Unhandled errors in fire-and-forget
- G115 # Integer overflow — CLI-safe conversions
- G204 # Subprocess with variable — intentional for player/extractor launch
- G301 # Directory perms > 0750 — standard for user dirs
- G302 # File perms > 0600 — resume files need 0644
- G304 # File inclusion via variable — config paths are trusted
- G306 # WriteFile perms > 0600 — binaries need 0755
- G703 # Path traversal via taint — internal paths only
- G704 # SSRF via taint — user-configured URLs
- G706 # Log injection via taint — internal log lines
errcheck:
exclude-functions:
- (*os/exec.Cmd).Start # Fire-and-forget for notifications
- (*os.File).Close # Deferred close — error irrelevant after read
- (io.Closer).Close # Same pattern for interfaces
- (*os/exec.Cmd).Start
- (*os.File).Close
- (io.Closer).Close
- (*compress/gzip.Reader).Close
- (*archive/tar.Reader).Close
- (net.Conn).Close # Best-effort cleanup
- os.Remove # Best-effort cleanup of temp files
- (net.Conn).Close
- os.Remove
- os.RemoveAll
- os.Unsetenv # Test-only, always succeeds
- fmt.Fprintf # Terminal output — error never actionable
- os.MkdirAll
- os.Rename
- os.Unsetenv
- os.WriteFile
- fmt.Fprint
- fmt.Fprintf
- fmt.Printf
- fmt.Println
- (*github.com/fatih/color.Color).Fprintf
- (*github.com/fatih/color.Color).Printf
- (*github.com/fatih/color.Color).Println
- (*encoding/json.Encoder).Encode
- (*encoding/json.Decoder).Decode
- (*archive/tar.Writer).WriteHeader
- (*archive/tar.Writer).Write
- (*archive/tar.Writer).Close
- (*compress/gzip.Writer).Close
- (net.Conn).SetDeadline
- filepath.Walk
exhaustive:
default-signifies-exhaustive: true
misspell:
locale: US
exclusions:
paths:
- dist
rules:
# Disable errcheck in test files — test helpers don't need error checks
- linters:
- errcheck
path: _test\.go
# Allow misspell "cancelled" — used in API constants matching server
- linters:
- misspell
text: "Cancell"
# Ignore nilerr in intentional log-and-continue patterns
- linters:
- nilerr
path: "(clean|scanner|usenet|engine)"
# Ignore prealloc suggestions
- linters:
- prealloc
path: ".*"
# Ignore unparam in migration code
- linters:
- unparam
path: migrate\.go
# Ignore staticcheck style suggestions (QF/S)
- linters:
- staticcheck
text: "^(QF|S1|SA4011|SA9003)"
# Ignore errorlint for now (requires broader refactor)
- linters:
- errorlint
path: ".*"
# Ignore gosec G112 (Slowloris) in local-only auth server
- linters:
- gosec
path: auth_browser
# Ignore gosec G101 (hardcoded creds) in tests
- linters:
- gosec
path: _test\.go
formatters:
enable:

View file

@ -30,12 +30,12 @@ type Daemon struct {
OnControlAction func(action, taskID string)
// State
User UserInfo
Features FeatureFlags
Info AgentInfo
State DaemonState
heartbeatFailures int
lastNotifiedVersion string
User UserInfo
Features FeatureFlags
Info AgentInfo
State DaemonState
heartbeatFailures int
lastNotifiedVersion string
// Callbacks for state tracking (set by cmd/daemon.go)
GetActiveCount func() int

View file

@ -114,7 +114,6 @@ func (d *DebridDownloader) Download(ctx context.Context, task *Task, outputDir s
if resp.ContentLength > 0 {
totalBytes = resp.ContentLength
}
existingSize = 0 // Start fresh
case http.StatusPartialContent:
// Resume accepted
startOffset = existingSize
@ -131,7 +130,6 @@ func (d *DebridDownloader) Download(ctx context.Context, task *Task, outputDir s
if _, err := fmt.Sscanf(cr, "bytes */%d", &serverSize); err == nil && serverSize > 0 && existingSize != serverSize {
// Local file size doesn't match server — re-download from scratch
log.Printf("[%s] local size %s != server size %s, re-downloading", shortID(task.ID), formatBytes(existingSize), formatBytes(serverSize))
existingSize = 0
resp.Body.Close()
req2, err := http.NewRequestWithContext(dlCtx, http.MethodGet, task.DirectURL, nil)
if err != nil {

View file

@ -383,4 +383,3 @@ func (c *Client) Status() string {
pooled := len(c.pool)
return fmt.Sprintf("%d connections (%d pooled) to %s:%d", open, pooled, c.cfg.Host, c.cfg.Port)
}

View file

@ -226,4 +226,3 @@ func findMainFile(dir string, files []string) string {
return bestPath
}