Skip to content

Commit dd800b2

Browse files
mtingersclaude
andcommitted
fix: resolve golangci-lint failures for new lint rules
golangci-lint v2.x (via golangci-lint-action@v9) enforces errcheck more strictly. Fix unchecked os.Setenv/os.Unsetenv calls in example tests and unchecked fmt.Fprintf return values in usage.go. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1543604 commit dd800b2

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

example_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import (
88
)
99

1010
func ExampleProcess() {
11-
os.Setenv("APP_HOST", "localhost")
12-
os.Setenv("APP_PORT", "8080")
13-
defer os.Unsetenv("APP_HOST")
14-
defer os.Unsetenv("APP_PORT")
11+
if err := os.Setenv("APP_HOST", "localhost"); err != nil {
12+
panic(err)
13+
}
14+
if err := os.Setenv("APP_PORT", "8080"); err != nil {
15+
panic(err)
16+
}
17+
defer func() { _ = os.Unsetenv("APP_HOST") }()
18+
defer func() { _ = os.Unsetenv("APP_PORT") }()
1519

1620
type Config struct {
1721
Host string
@@ -28,10 +32,14 @@ func ExampleProcess() {
2832
}
2933

3034
func ExampleProcess_nested() {
31-
os.Setenv("APP_DATABASE_HOST", "db.local")
32-
os.Setenv("APP_DATABASE_PORT", "5432")
33-
defer os.Unsetenv("APP_DATABASE_HOST")
34-
defer os.Unsetenv("APP_DATABASE_PORT")
35+
if err := os.Setenv("APP_DATABASE_HOST", "db.local"); err != nil {
36+
panic(err)
37+
}
38+
if err := os.Setenv("APP_DATABASE_PORT", "5432"); err != nil {
39+
panic(err)
40+
}
41+
defer func() { _ = os.Unsetenv("APP_DATABASE_HOST") }()
42+
defer func() { _ = os.Unsetenv("APP_DATABASE_PORT") }()
3543

3644
type DB struct {
3745
Host string

usage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func usageStruct(prefix string, rt reflect.Type, tw *tabwriter.Writer) {
6464
opts = fmt.Sprintf("[default: %s]", spec.DefaultValue)
6565
}
6666

67-
fmt.Fprintf(tw, " %s\t%s\t%s\t%s\n", key, typeName, opts, spec.Description)
67+
_, _ = fmt.Fprintf(tw, " %s\t%s\t%s\t%s\n", key, typeName, opts, spec.Description)
6868
}
6969
}
7070

@@ -77,7 +77,7 @@ func writeUsage(prefix string, spec interface{}, out io.Writer) error {
7777
return fmt.Errorf("envstruct: spec must be a struct or pointer to struct")
7878
}
7979
tw := tabwriter.NewWriter(out, 0, 4, 2, ' ', 0)
80-
fmt.Fprintf(tw, " %s\t%s\t%s\t%s\n", "KEY", "TYPE", "DEFAULT", "DESCRIPTION")
80+
_, _ = fmt.Fprintf(tw, " %s\t%s\t%s\t%s\n", "KEY", "TYPE", "DEFAULT", "DESCRIPTION")
8181
usageStruct(prefix, rv.Type(), tw)
8282
return tw.Flush()
8383
}

0 commit comments

Comments
 (0)