Uh oh!
There was an error while loading. Please reload this page.
Reject use of fmt.Printf under cmd/ - #3570
Conversation
denik
left a comment
There was a problem hiding this comment.
The CLI uses Cobra and should therefore use cmd.OutOrStdout() and friends.
Could you expand this a bit? What's the advantage of extra indirection? What's the case for when it is useful?
| - path: bundle/terranova/tnresources/all_test.go | ||
| linters: | ||
| - exhaustruct | ||
| - path-except: ^cmd |
There was a problem hiding this comment.
can this be enabled on libs? That's where you don't want print to stdout/stderr typically (outside of debugging).
There was a problem hiding this comment.
It can, but it adds a few more failures. I'd like to keep this small/focused.
|
pietern
commented
Sep 8, 2025
The advantage of indirection is that you can construct a command, run it, and capture the output from within Go. Granted, it has become less relevant now that we write more acceptance tests. |
denik
commented
Sep 8, 2025
ah I see, so it's for testing, potentially. That's valid. |
Uh oh!
There was an error while loading. Please reload this page.
## Changes Reject directly writing to global stdout/stderr. The "forbidigo" linter includes this rule by default. Also see https://golangci-lint.run/docs/linters/configuration/#forbidigo ## Why The CLI uses Cobra and should therefore use `cmd.OutOrStdout()` and friends. Saw this here: #3546 (comment)
Changes
Reject directly writing to global stdout/stderr.
The "forbidigo" linter includes this rule by default.
Also see https://golangci-lint.run/docs/linters/configuration/#forbidigo
Why
The CLI uses Cobra and should therefore use
cmd.OutOrStdout()and friends.Saw this here: #3546 (comment)