From b7f9b9d0398b767d52799c3ec2e67f7165ea36b7 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Mon, 8 Sep 2025 14:46:26 +0200 Subject: [PATCH] Reject use of fmt.Printf under cmd/ --- .golangci.yaml | 4 ++++ cmd/bundle/generate/dashboard.go | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index cedd269c13..4c872deeea 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -16,6 +16,7 @@ linters: - unused - exhaustruct - copyloopvar + - forbidigo settings: copyloopvar: check-alias: true @@ -72,6 +73,9 @@ linters: - path: bundle/terranova/tnresources/all_test.go linters: - exhaustruct + - path-except: ^cmd + linters: + - forbidigo issues: max-issues-per-linter: 1000 max-same-issues: 1000 diff --git a/cmd/bundle/generate/dashboard.go b/cmd/bundle/generate/dashboard.go index e86d385b3c..85b3931450 100644 --- a/cmd/bundle/generate/dashboard.go +++ b/cmd/bundle/generate/dashboard.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "os" "path" "path/filepath" @@ -53,6 +54,10 @@ type dashboard struct { // Relative path from the resource directory to the dashboard directory. relativeDashboardDir string + + // Output and error streams. + out io.Writer + err io.Writer } func (d *dashboard) resolveID(ctx context.Context, b *bundle.Bundle) string { @@ -185,7 +190,7 @@ func (d *dashboard) saveSerializedDashboard(_ context.Context, b *bundle.Bundle, } } - fmt.Printf("Writing dashboard to %q\n", rel) + fmt.Fprintf(d.out, "Writing dashboard to %q\n", rel) return os.WriteFile(filename, data, 0o644) } @@ -229,7 +234,7 @@ func (d *dashboard) saveConfiguration(ctx context.Context, b *bundle.Bundle, das rel = resourcePath } - fmt.Printf("Writing configuration to %q\n", rel) + fmt.Fprintf(d.out, "Writing configuration to %q\n", rel) err = saver.SaveAsYAML(result, resourcePath, d.force) if err != nil { return err @@ -462,7 +467,10 @@ The --watch flag continuously polls for remote changes and updates your local bundle files automatically, useful during active dashboard development.`, } - d := &dashboard{} + d := &dashboard{ + out: cmd.OutOrStdout(), + err: cmd.ErrOrStderr(), + } // Lookup flags. cmd.Flags().StringVar(&d.existingPath, "existing-path", "", `workspace path of the dashboard to generate configuration for`)