Skip to content

[linter-miner] feat(linters): add logfatallibrary linter to flag log.Fatal calls in library packages#45115

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
linter-miner/logfatallibrary-34272152660ce94b
Draft

[linter-miner] feat(linters): add logfatallibrary linter to flag log.Fatal calls in library packages#45115
github-actions[bot] wants to merge 1 commit into
mainfrom
linter-miner/logfatallibrary-34272152660ce94b

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Adds a new logfatallibrary linter under pkg/linters/logfatallibrary/ that detects log.Fatal, log.Fatalf, and log.Fatalln calls inside library (pkg/) packages.

Why

log.Fatal* functions internally call os.Exit(1), which:

  • Bypasses deferred cleanup (open files, database connections, in-flight requests)
  • Makes library code untestable in isolation — tests calling into such code can abort the entire test binary
  • Prevents callers from handling errors gracefully — there is no opportunity to recover or return an error

This is the log-package complement to the existing osexitinlibrary linter.

Evidence

The pattern of flagging implicit os.Exit calls in library code is consistent with the existing osexitinlibrary and panicinlibrarycode linters. The log.Fatal family causes the same problem and is frequently overlooked.

Changes

  • pkg/linters/logfatallibrary/logfatallibrary.go — analyzer implementation
  • pkg/linters/logfatallibrary/logfatallibrary_test.go — unit tests using analysistest
  • pkg/linters/logfatallibrary/testdata/src/logfatallibrary/logfatallibrary.go — fixture with flagged and safe cases
  • cmd/linters/main.go — registers the new analyzer

Verification

  • All tests pass: go test ./pkg/linters/logfatallibrary/...
  • Binary builds cleanly: go build ./cmd/linters

Generated by Linter Miner · 44.8 AIC · ⌖ 9.05 AIC · ⊞ 5.6K ·

  • expires on Jul 19, 2026, 9:50 AM UTC-08:00

Detects log.Fatal, log.Fatalf, and log.Fatalln calls in library (pkg/)
packages. These functions call os.Exit(1) internally, which:
- Bypasses deferred cleanup (e.g., open files, db connections)
- Makes the calling package untestable in isolation
- Prevents callers from handling errors gracefully

The linter mirrors osexitinlibrary but targets the log package's fatal
functions. cmd/ entry-points are excluded, as are test files and calls
suppressed with //nolint:logfatallibrary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added automation cookie Issue Monster Loves Cookies! go-linters labels Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation cookie Issue Monster Loves Cookies! go-linters

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants