Skip to content

Commit 134b776

Browse files
committed
review
1 parent 17399c9 commit 134b776

File tree

7 files changed

+26
-13
lines changed

7 files changed

+26
-13
lines changed

pkg/config/loader.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ func (l *Loader) appendStringSlice(name string, current *[]string) {
285285
}
286286

287287
func (l *Loader) handleGoVersion() {
288-
l.cfg.Run.Go = cmp.Or(l.cfg.Run.Go, detectGoVersion())
288+
if l.cfg.Run.Go == "" {
289+
l.cfg.Run.Go = detectGoVersion()
290+
}
289291

290292
l.cfg.LintersSettings.Govet.Go = l.cfg.Run.Go
291293

pkg/goanalysis/pkgerrors/extract.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package pkgerrors
22

33
import (
4-
"cmp"
54
"fmt"
65
"regexp"
76
"strings"
@@ -51,7 +50,9 @@ func extractErrors(pkg *packages.Package) []packages.Error {
5150
// some errors like "code in directory expects import" don't have Pos, set it here
5251
for i := range uniqErrors {
5352
err := &uniqErrors[i]
54-
err.Pos = cmp.Or(err.Pos, fmt.Sprintf("%s:1", pkg.GoFiles[0]))
53+
if err.Pos == "" {
54+
err.Pos = fmt.Sprintf("%s:1", pkg.GoFiles[0])
55+
}
5556
}
5657
}
5758

pkg/goanalysis/runners.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package goanalysis
22

33
import (
4-
"cmp"
54
"fmt"
65

76
"golang.org/x/tools/go/analysis"
@@ -60,7 +59,9 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss
6059
reportedIssues := cfg.reportIssues(lintCtx)
6160
for i := range reportedIssues {
6261
issue := &reportedIssues[i].Issue
63-
issue.Pkg = cmp.Or(issue.Pkg, passToPkg[reportedIssues[i].Pass])
62+
if issue.Pkg == nil {
63+
issue.Pkg = passToPkg[reportedIssues[i].Pass]
64+
}
6465
retIssues = append(retIssues, *issue)
6566
}
6667
retIssues = append(retIssues, buildIssues(diags, cfg.getLinterNameForDiagnostic)...)

pkg/goutil/env.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package goutil
22

33
import (
4-
"cmp"
54
"context"
65
"encoding/json"
76
"fmt"
@@ -55,5 +54,10 @@ func (e Env) Discover(ctx context.Context) error {
5554
}
5655

5756
func (e Env) Get(k EnvKey) string {
58-
return cmp.Or(os.Getenv(string(k)), e.vars[string(k)])
57+
envValue := os.Getenv(string(k))
58+
if envValue != "" {
59+
return envValue
60+
}
61+
62+
return e.vars[string(k)]
5963
}

pkg/lint/lintersdb/manager.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package lintersdb
22

33
import (
4-
"cmp"
54
"fmt"
65
"os"
76
"slices"
@@ -41,7 +40,10 @@ func NewManager(log logutils.Log, cfg *config.Config, builders ...Builder) (*Man
4140
nameToLCs: make(map[string][]*linter.Config),
4241
}
4342

44-
m.cfg = cmp.Or(cfg, config.NewDefault())
43+
m.cfg = cfg
44+
if cfg == nil {
45+
m.cfg = config.NewDefault()
46+
}
4547

4648
for _, builder := range builders {
4749
linters, err := builder.Build(m.cfg)

pkg/lint/runner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package lint
22

33
import (
4-
"cmp"
54
"context"
65
"errors"
76
"fmt"
@@ -165,7 +164,9 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
165164
}
166165

167166
for i := range issues {
168-
issues[i].FromLinter = cmp.Or(issues[i].FromLinter, lc.Name())
167+
if issues[i].FromLinter == "" {
168+
issues[i].FromLinter = lc.Name()
169+
}
169170
}
170171

171172
return issues, nil

test/bench/bench_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package bench
22

33
import (
44
"bytes"
5-
"cmp"
65
"errors"
76
"fmt"
87
"go/build"
@@ -134,7 +133,10 @@ func Benchmark_golangciLint(b *testing.B) {
134133
func getAllRepositories(tb testing.TB) []repo {
135134
tb.Helper()
136135

137-
benchRoot := cmp.Or(os.Getenv("GCL_BENCH_ROOT"), tb.TempDir())
136+
benchRoot := os.Getenv("GCL_BENCH_ROOT")
137+
if benchRoot == "" {
138+
benchRoot = tb.TempDir()
139+
}
138140

139141
return []repo{
140142
{

0 commit comments

Comments
 (0)