Skip to content

Reject use of fmt.Printf under cmd/#3570

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

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

Conversation

@pietern
Copy link
Copy Markdown
Contributor

@pietern pietern commented Sep 8, 2025

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)

Copy link
Copy Markdown
Contributor

@denik denik left a comment

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?

- 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
Contributor Author

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
Copy link
Copy Markdown
Collaborator

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

Run: 17551339165

Env ✅​pass 🙈​skip
✅​ aws linux 308 519
✅​ aws windows 309 518
✅​ aws-ucws linux 420 417
✅​ aws-ucws windows 421 416
✅​ azure linux 308 518
✅​ azure windows 309 517
✅​ azure-ucws linux 420 416
✅​ azure-ucws windows 421 415
✅​ gcp linux 307 520
✅​ gcp windows 308 519

@pietern
Copy link
Copy Markdown
Contributor Author

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
Copy link
Copy Markdown
Contributor

denik 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.

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 queue Sep 8, 2025
Merged via the queue into main with commit edeca76 Sep 8, 2025
13 checks passed
@pietern pietern deleted the lint-printf branch September 8, 2025 13:56
Sign up for free to 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