Skip to content

Reject use of fmt.Printf under cmd/ - #3570

Merged
pietern merged 1 commit into
mainfrom
lint-printf
Sep 8, 2025
Merged

Reject use of fmt.Printf under cmd/#3570
pietern merged 1 commit into
mainfrom
lint-printf

Conversation

@pietern

@pieternpietern commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

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)

@denikdenik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread.golangci.yaml
- path: bundle/terranova/tnresources/all_test.go
linters:
- exhaustruct
- path-except: ^cmd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be enabled on libs? That's where you don't want print to stdout/stderr typically (outside of debugging).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, but it adds a few more failures. I'd like to keep this small/focused.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Sep 8, 2025

Copy link
Copy Markdown
Collaborator

Run: 17551339165

Env✅​pass🙈​skip
✅​aws linux308519
✅​aws windows309518
✅​aws-ucws linux420417
✅​aws-ucws windows421416
✅​azure linux308518
✅​azure windows309517
✅​azure-ucws linux420416
✅​azure-ucws windows421415
✅​gcp linux307520
✅​gcp windows308519

@pietern

Copy link
Copy Markdown
ContributorAuthor

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

denik commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

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.

ah I see, so it's for testing, potentially. That's valid.

@pietern
pietern enabled auto-merge September 8, 2025 13:37
@pietern
pietern added this pull request to the merge queueSep 8, 2025
Merged via the queue into main with commit edeca76Sep 8, 2025
13 checks passed
@pietern
pietern deleted the lint-printf branch September 8, 2025 13:56
denik pushed a commit that referenced this pull request May 20, 2026
## 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)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pietern@eng-dev-ecosystem-bot@denik