fix(lint): exclude common fire-and-forget patterns from errcheck

This commit is contained in:
Deivid Soto 2026-03-30 23:34:36 +02:00
parent 104820f4fe
commit c0fd8d3818
8 changed files with 25 additions and 12 deletions

View file

@ -29,7 +29,21 @@ linters:
- G104 # Allow unhandled errors in fire-and-forget (notifications)
errcheck:
exclude-functions:
- (*os/exec.Cmd).Start # Fire-and-forget for notifications
- (*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
- (*compress/gzip.Reader).Close
- (*archive/tar.Reader).Close
- (net.Conn).Close # Best-effort cleanup
- os.Remove # Best-effort cleanup of temp files
- os.RemoveAll
- os.Unsetenv # Test-only, always succeeds
- fmt.Fprintf # Terminal output — error never actionable
- fmt.Printf
- fmt.Println
- (*github.com/fatih/color.Color).Fprintf
- (*github.com/fatih/color.Color).Printf
- (*github.com/fatih/color.Color).Println
exhaustive:
default-signifies-exhaustive: true
misspell:

View file

@ -69,7 +69,7 @@ func (t *WSTransport) Connect(ctx context.Context) error {
conn, wsResp, err := dialer.DialContext(ctx, wsURLWithKey, header)
if wsResp != nil && wsResp.Body != nil {
defer wsResp.Body.Close() //nolint:errcheck
defer wsResp.Body.Close()
}
if err != nil {
return fmt.Errorf("ws dial: %w", err)

View file

@ -21,7 +21,7 @@ func TestDiscoverE2E(t *testing.T) {
if err != nil {
t.Skipf("Port %s not reachable, skipping", port)
}
_ = conn.Close()
conn.Close()
}
t.Run("Discover", func(t *testing.T) {

View file

@ -171,7 +171,7 @@ func Save(cfg Config, path string) error {
}
if err := os.Rename(tmpPath, path); err != nil {
_ = os.Remove(tmpPath)
os.Remove(tmpPath)
return fmt.Errorf("rename config: %w", err)
}

View file

@ -93,7 +93,7 @@ func TestLoadPreservesDefaults(t *testing.T) {
path := filepath.Join(tmp, "config.toml")
// Write partial config (only auth section)
_ = os.WriteFile(path, []byte(`[auth]
os.WriteFile(path, []byte(`[auth]
api_key = "tc_partial"
`), 0o644)
@ -193,7 +193,7 @@ func TestParseSpeed(t *testing.T) {
func TestLoadInvalidTOML(t *testing.T) {
tmp := t.TempDir()
path := filepath.Join(tmp, "config.toml")
_ = os.WriteFile(path, []byte(`not valid toml [[[`), 0o644)
os.WriteFile(path, []byte(`not valid toml [[[`), 0o644)
_, err := Load(path)
if err == nil {

View file

@ -43,7 +43,7 @@ func TestDirOverrideEnv(t *testing.T) {
func TestDirXDGOverride(t *testing.T) {
// Clear the custom env so XDG takes effect
_ = os.Unsetenv("UNARR_CONFIG_DIR")
os.Unsetenv("UNARR_CONFIG_DIR")
t.Setenv("XDG_CONFIG_HOME", "/xdg/config")
dir := Dir()

View file

@ -97,8 +97,7 @@ func DownloadFFprobe() (string, error) {
if err != nil {
return "", fmt.Errorf("download failed: %w", err)
}
defer resp.Body.Close() //nolint:errcheck // best-effort close
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("download failed: HTTP %d", resp.StatusCode)
}
@ -167,7 +166,7 @@ func extractFromZip(data []byte, target string) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("cannot extract %s from archive: %w", target, err)
}
defer rc.Close() //nolint:errcheck // best-effort close
defer rc.Close()
return io.ReadAll(rc)
}
}

View file

@ -113,7 +113,7 @@ func plexLibraryPaths() []string {
if err != nil {
return nil
}
defer resp.Body.Close() //nolint:errcheck // best-effort close
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil
@ -200,7 +200,7 @@ func jellyfinLibraryPaths(baseURL string) []string {
if err != nil {
return nil
}
defer resp.Body.Close() //nolint:errcheck // best-effort close
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil