[linter-miner] linter: add fprintstderrinlibrary — flag fmt.Fprint* to os.Stderr in library packages#39440
Closed
github-actions[bot] wants to merge 1 commit into
Closed
Conversation
Reports fmt.Fprintf/Fprintln/Fprint calls that write directly to os.Stderr in library (pkg/) packages. Library code should use pkg/logger for structured logging rather than writing raw text to the standard error stream. This linter complements the existing rawloginlib analyzer (which flags log.* calls) by covering the fmt.Fprint* family of stderr writes, closing the gap for 133+ call sites found across pkg/workflow/ and pkg/parser/. Evidence: - Code-pattern scan found 133 fmt.Fprint*(os.Stderr, ...) calls in pkg/ - Consistent with the library logging policy enforced by rawloginlib - Not covered by any standard golangci-lint rule enabled by default Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new custom
go/analysislinterfprintstderrinlibrarythat reportsfmt.Fprintf,fmt.Fprintln, andfmt.Fprintcalls writing directly toos.Stderrinside library (pkg/) packages.Library code should use the structured
pkg/loggerinstead of writing raw text to the error stream. This closes the gap left by the existingrawloginliblinter, which only covers thelog.*package family.What the linter catches
Calls in
cmd/andmainpackages are intentionally skipped (CLIs may write to stderr). The//nolint:fprintstderrinlibrarydirective suppresses individual lines.Evidence
Code-pattern scan (
pkg/)A scan of non-test Go files under
pkg/found 133+ occurrences offmt.Fprint*(os.Stderr, ...)across:pkg/workflow/— 124 occurrencespkg/parser/— 9 occurrencesGitHub Discussions / Issues
Issue #39414 and related issues highlighted that
pkg/packages should use structured logging; therawloginliblinter already enforces this forlog.*but thefmt.Fprint*path was uncovered.Files changed
pkg/linters/fprintstderrinlibrary/fprintstderrinlibrary.gopkg/linters/fprintstderrinlibrary/fprintstderrinlibrary_test.goanalysistestpkg/linters/fprintstderrinlibrary/testdata/src/fprintstderrinlibrary/fprintstderrinlibrary.go// wantannotationscmd/linters/main.goTesting
Run
Linter Miner run #39 — workflow run 27568750533
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comSee Network Configuration for more information.