Skip to content

Commit 79d9022

Browse files
committed
go: fix golangci-lint issues across cmd/ and mantle/ pkg/builds/
I ran this through Anthropic/Claude Opus 4.6 and this is what it came up with: ``` Fix 317 golangci-lint issues across 94 files: - errcheck (171 issues): Add explicit error discards for unchecked return values from Close(), os.Setenv(), os.Remove(), os.RemoveAll(), os.Unsetenv(), fmt.Fprintf/Fprintln(), w.Flush(), and systemdjournal.Print(). For deferred Close() calls, wrap in anonymous functions with _ = assignment. For non-deferred calls, add _ = prefix. - ST1005 (143 issues): Lowercase capitalized error strings per Go convention (e.g. "Cannot use" -> "cannot use", "Failed to" -> "failed to"). Remove trailing punctuation (periods) and newlines from error format strings. - SA4011 (3 issues): Remove ineffective break statements in switch/ select cases in mantle/platform/qemu.go. ``` Written-By: <anthropic/claude-opus-4.6>
1 parent 6fe41d1 commit 79d9022

94 files changed

Lines changed: 319 additions & 322 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/coreos-assembler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func initializeGlobalState(argv []string) error {
119119
// Set PYTHONUNBUFFERED=1 so that we get unbuffered output. We should
120120
// be able to do this on the shebang lines but env doesn't support args
121121
// right now. In Fedora we should be able to use the `env -S` option.
122-
os.Setenv("PYTHONUNBUFFERED", "1")
122+
_ = os.Setenv("PYTHONUNBUFFERED", "1")
123123

124124
// docker/podman don't run through PAM, but we want this set for the privileged
125125
// (non-virtualized) path
@@ -131,7 +131,7 @@ func initializeGlobalState(argv []string) error {
131131
} else {
132132
user = "cosa"
133133
}
134-
os.Setenv("USER", user)
134+
_ = os.Setenv("USER", user)
135135
}
136136

137137
// https://github.com/containers/libpod/issues/1448
@@ -177,7 +177,7 @@ func initializeGlobalState(argv []string) error {
177177
if err != nil {
178178
return fmt.Errorf("opening /etc/passwd: %w", err)
179179
}
180-
defer f.Close()
180+
defer func() { _ = f.Close() }()
181181
id := os.Getuid()
182182
buf := fmt.Sprintf("%s:x:%d:0:%s user:%s:/sbin/nologin\n", user, id, user, home)
183183
if _, err = f.WriteString(buf); err != nil {

cmd/remote-session.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ func envVarIsSet(v string) bool {
103103
// environment variable error based on the given inputs.
104104
func envVarError(v string, required bool) error {
105105
if required {
106-
return fmt.Errorf("The env var %s must be defined and non-empty", v)
106+
return fmt.Errorf("the env var %s must be defined and non-empty", v)
107107
} else {
108-
return fmt.Errorf("The env var %s must not be defined", v)
108+
return fmt.Errorf("the env var %s must not be defined", v)
109109
}
110110
}
111111

@@ -231,7 +231,7 @@ func runSync(c *cobra.Command, args []string) error {
231231
}
232232
}
233233
if found != 1 {
234-
return fmt.Errorf("Must pass in a single arg with `:` prepended")
234+
return fmt.Errorf("must pass in a single arg with `:` prepended")
235235
}
236236
// build command and execute
237237
rsyncargs := []string{"-ah", "--no-owner", "--no-group", "--mkpath", "--blocking-io",

mantle/auth/aliyun.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func ReadAliyunConfig(path string) (map[string]AliyunProfile, error) {
5151
if err != nil {
5252
return nil, err
5353
}
54-
defer f.Close()
54+
defer func() { _ = f.Close() }()
5555

5656
var config AliyunConfig
5757
if err := json.NewDecoder(f).Decode(&config); err != nil {

mantle/auth/azure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func ReadAzureCredentials(path string) (AzureCredentials, error) {
5454
if err != nil {
5555
return azCreds, err
5656
}
57-
defer f.Close()
57+
defer func() { _ = f.Close() }()
5858

5959
content, err := io.ReadAll(f)
6060
if err != nil {

mantle/auth/do.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func ReadDOConfig(path string) (map[string]DOProfile, error) {
4747
if err != nil {
4848
return nil, err
4949
}
50-
defer f.Close()
50+
defer func() { _ = f.Close() }()
5151

5252
var profiles map[string]DOProfile
5353
if err := json.NewDecoder(f).Decode(&profiles); err != nil {

mantle/auth/esx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func ReadESXConfig(path string) (map[string]ESXProfile, error) {
4949
if err != nil {
5050
return nil, err
5151
}
52-
defer f.Close()
52+
defer func() { _ = f.Close() }()
5353

5454
var profiles map[string]ESXProfile
5555
if err := json.NewDecoder(f).Decode(&profiles); err != nil {

mantle/cmd/kola/console.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func runCheckConsole(cmd *cobra.Command, args []string) error {
8181
}
8282
}
8383
if errorcount > 0 {
84-
return errors.New("Errors found on console")
84+
return errors.New("errors found on console")
8585
}
8686
return nil
8787
}

mantle/cmd/kola/devshell.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co
8181
if err != nil {
8282
return err
8383
}
84-
defer os.RemoveAll(tmpd)
84+
defer func() { _ = os.RemoveAll(tmpd) }()
8585

8686
// Define SSH key
8787
agent, err := network.NewSSHAgent(network.NewRetryDialer())
8888
if err != nil {
8989
return err
9090
}
91-
defer agent.Close()
91+
defer func() { _ = agent.Close() }()
9292

9393
keys, err := agent.List()
9494
if err != nil {
@@ -352,7 +352,7 @@ func (se systemdEventMessage) message() (string, error) {
352352
} else if s, ok := se.Message.(string); ok {
353353
return s, nil
354354
} else {
355-
return "", fmt.Errorf("Unhandled systemd json message of type %T", se.Message)
355+
return "", fmt.Errorf("unhandled systemd json message of type %T", se.Message)
356356
}
357357
}
358358

mantle/cmd/kola/kola.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func writeProps() error {
289289
if err != nil {
290290
return err
291291
}
292-
defer f.Close()
292+
defer func() { _ = f.Close() }()
293293

294294
enc := json.NewEncoder(f)
295295
enc.SetIndent("", " ")
@@ -447,12 +447,12 @@ func runList(cmd *cobra.Command, args []string) error {
447447
if !listJSON {
448448
var w = tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
449449

450-
fmt.Fprintln(w, "Test Name\tPlatforms\tArchitectures\tDistributions\tTags")
451-
fmt.Fprintln(w, "\t")
450+
_, _ = fmt.Fprintln(w, "Test Name\tPlatforms\tArchitectures\tDistributions\tTags")
451+
_, _ = fmt.Fprintln(w, "\t")
452452
for _, item := range newtestlist {
453-
fmt.Fprintf(w, "%v\n", item)
453+
_, _ = fmt.Fprintf(w, "%v\n", item)
454454
}
455-
w.Flush()
455+
_ = w.Flush()
456456
} else {
457457
out, err := json.MarshalIndent(newtestlist, "", "\t")
458458
if err != nil {
@@ -521,7 +521,7 @@ func runHTTPServer(cmd *cobra.Command, args []string) error {
521521

522522
http.Handle("/", http.FileServer(http.Dir(directory)))
523523

524-
fmt.Fprintf(os.Stdout, "Serving HTTP on port: %d\n", httpPort)
524+
_, _ = fmt.Fprintf(os.Stdout, "Serving HTTP on port: %d\n", httpPort)
525525
return http.ListenAndServe(fmt.Sprintf(":%d", httpPort), nil)
526526
}
527527

@@ -553,7 +553,7 @@ func preRunUpgrade(cmd *cobra.Command, args []string) error {
553553

554554
func runUpgradeCleanup() {
555555
if qemuImageDir != "" && qemuImageDirIsTemp {
556-
os.RemoveAll(qemuImageDir)
556+
_ = os.RemoveAll(qemuImageDir)
557557
}
558558
}
559559

@@ -621,7 +621,7 @@ func syncFindParentImageOptions() error {
621621
qemuImageDirIsTemp = true
622622
}
623623
if parentCosaBuild.BuildArtifacts.Qemu == nil {
624-
return fmt.Errorf("No QEMU in parent meta.json")
624+
return fmt.Errorf("no QEMU in parent meta.json")
625625
}
626626
qcowURL := parentBaseURL + parentCosaBuild.BuildArtifacts.Qemu.Path
627627
qcowLocal := filepath.Join(qemuImageDir, parentCosaBuild.BuildArtifacts.Qemu.Path)

mantle/cmd/kola/options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func syncStreamOptions() error {
441441
var artifacts *stream.Arch
442442
switch kola.Options.Distribution {
443443
case "":
444-
return fmt.Errorf("Must specify -b/--distro with --stream")
444+
return fmt.Errorf("must specify -b/--distro with --stream")
445445
case "fcos":
446446
artifacts, err = fcos.FetchCanonicalStreamArtifacts(kola.Options.Stream, kola.Options.CosaBuildArch)
447447
if err != nil {
@@ -453,7 +453,7 @@ func syncStreamOptions() error {
453453
return errors.Wrapf(err, "failed to fetch stream")
454454
}
455455
default:
456-
return fmt.Errorf("Unhandled stream for distribution %s", kola.Options.Distribution)
456+
return fmt.Errorf("unhandled stream for distribution %s", kola.Options.Distribution)
457457
}
458458

459459
release := ""
@@ -472,7 +472,7 @@ func syncStreamOptions() error {
472472
kola.GCPOptions.Image = fmt.Sprintf("projects/%s/global/images/%s", imageproject, imagename)
473473
extra = fmt.Sprintf("(image project: %s, image name: %s)", imageproject, imagename)
474474
default:
475-
return fmt.Errorf("Unhandled platform %s for stream", kolaPlatform)
475+
return fmt.Errorf("unhandled platform %s for stream", kolaPlatform)
476476
}
477477

478478
fmt.Printf("Resolved distro=%s stream=%s platform=%s arch=%s to release=%s %s\n",

0 commit comments

Comments
 (0)