Skip to content

Commit 29eaf2d

Browse files
build(deps): bump github.com/ldez/gomoddirectives from 0.6.0 to 0.6.1 (#5329)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent dd0acd0 commit 29eaf2d

File tree

9 files changed

+64
-62
lines changed

9 files changed

+64
-62
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ require (
6666
github.com/kyoh86/exportloopref v0.1.11
6767
github.com/lasiar/canonicalheader v1.1.2
6868
github.com/ldez/exptostd v0.3.1
69-
github.com/ldez/gomoddirectives v0.6.0
70-
github.com/ldez/grignotin v0.8.0
69+
github.com/ldez/gomoddirectives v0.6.1
70+
github.com/ldez/grignotin v0.9.0
7171
github.com/ldez/tagliatelle v0.7.1
7272
github.com/ldez/usetesting v0.4.2
7373
github.com/leonklingele/grouper v1.1.2

go.sum

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/config.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"cmp"
5+
"context"
56
"fmt"
67
"os"
78
"path/filepath"
@@ -80,20 +81,20 @@ func IsGoGreaterThanOrEqual(current, limit string) bool {
8081
return v1.GreaterThanOrEqual(l)
8182
}
8283

83-
func detectGoVersion() string {
84-
return cmp.Or(detectGoVersionFromGoMod(), "1.17")
84+
func detectGoVersion(ctx context.Context) string {
85+
return cmp.Or(detectGoVersionFromGoMod(ctx), "1.17")
8586
}
8687

8788
// detectGoVersionFromGoMod tries to get Go version from go.mod.
8889
// It returns `toolchain` version if present,
8990
// else it returns `go` version if present,
9091
// else it returns `GOVERSION` version if present,
9192
// else it returns empty.
92-
func detectGoVersionFromGoMod() string {
93-
values, err := goenv.Get(goenv.GOMOD, goenv.GOVERSION)
93+
func detectGoVersionFromGoMod(ctx context.Context) string {
94+
values, err := goenv.Get(ctx, goenv.GOMOD, goenv.GOVERSION)
9495
if err != nil {
9596
values = map[string]string{
96-
goenv.GOMOD: detectGoModFallback(),
97+
goenv.GOMOD: detectGoModFallback(ctx),
9798
}
9899
}
99100

@@ -143,8 +144,8 @@ func parseGoMod(goMod string) (*modfile.File, error) {
143144
return modfile.Parse("go.mod", raw, nil)
144145
}
145146

146-
func detectGoModFallback() string {
147-
info, err := gomod.GetModuleInfo()
147+
func detectGoModFallback(ctx context.Context) string {
148+
info, err := gomod.GetModuleInfo(ctx)
148149
if err != nil {
149150
return ""
150151
}

pkg/config/loader.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"cmp"
5+
"context"
56
"errors"
67
"fmt"
78
"os"
@@ -286,7 +287,7 @@ func (l *Loader) appendStringSlice(name string, current *[]string) {
286287

287288
func (l *Loader) handleGoVersion() {
288289
if l.cfg.Run.Go == "" {
289-
l.cfg.Run.Go = detectGoVersion()
290+
l.cfg.Run.Go = detectGoVersion(context.Background())
290291
}
291292

292293
l.cfg.LintersSettings.Govet.Go = l.cfg.Run.Go

pkg/goformatters/gci/gci.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gci
22

33
import (
4+
"context"
45
"fmt"
56

67
gcicfg "github.com/daixiang0/gci/pkg/config"
@@ -22,7 +23,7 @@ func New(settings *config.GciSettings) (*Formatter, error) {
2223
log.InitLogger()
2324
_ = log.L().Sync()
2425

25-
modPath, err := gomod.GetModulePath()
26+
modPath, err := gomod.GetModulePath(context.Background())
2627
if err != nil {
2728
internal.FormatterLogger.Errorf("gci: %v", err)
2829
}

pkg/goutil/env.go

+10-24
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,39 @@ package goutil
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"os"
8-
"os/exec"
9-
"strings"
107
"time"
118

9+
"github.com/ldez/grignotin/goenv"
10+
1211
"github.com/golangci/golangci-lint/pkg/logutils"
1312
)
1413

1514
type EnvKey string
1615

17-
const (
18-
EnvGoCache EnvKey = "GOCACHE"
19-
EnvGoRoot EnvKey = "GOROOT"
20-
)
21-
2216
type Env struct {
23-
vars map[string]string
24-
log logutils.Log
25-
debugf logutils.DebugFunc
17+
vars map[string]string
18+
log logutils.Log
2619
}
2720

2821
func NewEnv(log logutils.Log) *Env {
2922
return &Env{
30-
vars: map[string]string{},
31-
log: log,
32-
debugf: logutils.Debug(logutils.DebugKeyEnv),
23+
vars: map[string]string{},
24+
log: log,
3325
}
3426
}
3527

3628
func (e Env) Discover(ctx context.Context) error {
3729
startedAt := time.Now()
3830

39-
//nolint:gosec // Everything is static here.
40-
cmd := exec.CommandContext(ctx, "go", "env", "-json", string(EnvGoCache), string(EnvGoRoot))
41-
42-
out, err := cmd.Output()
31+
var err error
32+
e.vars, err = goenv.Get(ctx, goenv.GOCACHE, goenv.GOROOT)
4333
if err != nil {
44-
return fmt.Errorf("failed to run '%s': %w", strings.Join(cmd.Args, " "), err)
45-
}
46-
47-
if err = json.Unmarshal(out, &e.vars); err != nil {
48-
return fmt.Errorf("failed to parse '%s' json: %w", strings.Join(cmd.Args, " "), err)
34+
return fmt.Errorf("%w", err)
4935
}
5036

51-
e.debugf("Read go env for %s: %#v", time.Since(startedAt), e.vars)
37+
e.log.Infof("Read go env for %s: %#v", time.Since(startedAt), e.vars)
5238

5339
return nil
5440
}

pkg/lint/package.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"time"
1313

14+
"github.com/ldez/grignotin/goenv"
1415
"golang.org/x/tools/go/packages"
1516

1617
"github.com/golangci/golangci-lint/pkg/config"
@@ -204,12 +205,13 @@ func (l *PackageLoader) debugPrintLoadedPackages(pkgs []*packages.Package) {
204205
func (l *PackageLoader) prepareBuildContext() {
205206
// Set GOROOT to have working cross-compilation: cross-compiled binaries
206207
// have invalid GOROOT. XXX: can't use runtime.GOROOT().
207-
goroot := l.goenv.Get(goutil.EnvGoRoot)
208+
goroot := l.goenv.Get(goenv.GOROOT)
208209
if goroot == "" {
209210
return
210211
}
211212

212-
os.Setenv(string(goutil.EnvGoRoot), goroot)
213+
_ = os.Setenv(goenv.GOROOT, goroot)
214+
213215
build.Default.GOROOT = goroot
214216
build.Default.BuildTags = l.cfg.Run.BuildTags
215217
}

pkg/logutils/logutils.go

+28-19
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,47 @@ const EnvTestRun = "GL_TEST_RUN"
1515
// - Some analysis details: `GL_DEBUG=goanalysis/analyze,goanalysis/facts golangci-lint run`
1616
const envDebug = "GL_DEBUG"
1717

18+
const (
19+
DebugKeyBinSalt = "bin_salt"
20+
DebugKeyConfigReader = "config_reader"
21+
DebugKeyEmpty = ""
22+
DebugKeyEnabledLinters = "enabled_linters"
23+
DebugKeyExec = "exec"
24+
DebugKeyFormatter = "formatter"
25+
DebugKeyGoEnv = "goenv"
26+
DebugKeyLinter = "linter"
27+
DebugKeyLintersContext = "linters_context"
28+
DebugKeyLintersDB = "lintersdb"
29+
DebugKeyLintersOutput = "linters_output"
30+
DebugKeyLoader = "loader" // Debugs packages loading (including `go/packages` internal debugging).
31+
DebugKeyPkgCache = "pkgcache"
32+
DebugKeyRunner = "runner"
33+
DebugKeyStopwatch = "stopwatch"
34+
DebugKeyTest = "test"
35+
)
36+
37+
// Printers.
38+
const (
39+
DebugKeyTabPrinter = "tab_printer"
40+
DebugKeyTextPrinter = "text_printer"
41+
)
42+
43+
// Processors.
1844
const (
1945
DebugKeyAutogenExclude = "autogen_exclude" // Debugs a filter excluding autogenerated source code.
20-
DebugKeyBinSalt = "bin_salt"
21-
DebugKeyConfigReader = "config_reader"
22-
DebugKeyEmpty = ""
23-
DebugKeyEnabledLinters = "enabled_linters"
24-
DebugKeyEnv = "env" // Debugs `go env` command.
2546
DebugKeyExcludeRules = "exclude_rules"
26-
DebugKeyExec = "exec"
2747
DebugKeyFilenameUnadjuster = "filename_unadjuster"
28-
DebugKeyFormatter = "formatter"
29-
DebugKeyGoEnv = "goenv"
3048
DebugKeyInvalidIssue = "invalid_issue"
31-
DebugKeyLinter = "linter"
32-
DebugKeyLintersContext = "linters_context"
33-
DebugKeyLintersDB = "lintersdb"
34-
DebugKeyLintersOutput = "linters_output"
35-
DebugKeyLoader = "loader" // Debugs packages loading (including `go/packages` internal debugging).
3649
DebugKeyMaxFromLinter = "max_from_linter"
3750
DebugKeyMaxSameIssues = "max_same_issues"
3851
DebugKeyPathAbsoluter = "path_absoluter"
3952
DebugKeyPathPrettifier = "path_prettifier"
40-
DebugKeyPkgCache = "pkgcache"
41-
DebugKeyRunner = "runner"
4253
DebugKeySeverityRules = "severity_rules"
4354
DebugKeySkipDirs = "skip_dirs"
4455
DebugKeySourceCode = "source_code"
45-
DebugKeyStopwatch = "stopwatch"
46-
DebugKeyTabPrinter = "tab_printer"
47-
DebugKeyTest = "test"
48-
DebugKeyTextPrinter = "text_printer"
4956
)
5057

58+
// Analysis.
5159
const (
5260
DebugKeyGoAnalysis = "goanalysis"
5361

@@ -61,6 +69,7 @@ const (
6169
DebugKeyGoAnalysisFactsInherit = DebugKeyGoAnalysisFacts + "/inherit"
6270
)
6371

72+
// Linters.
6473
const (
6574
DebugKeyForbidigo = "forbidigo" // Debugs `forbidigo` linter.
6675
DebugKeyGoCritic = "gocritic" // Debugs `gocritic` linter.

pkg/result/processors/cgo.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"path/filepath"
55
"strings"
66

7+
"github.com/ldez/grignotin/goenv"
8+
79
"github.com/golangci/golangci-lint/pkg/goutil"
810
"github.com/golangci/golangci-lint/pkg/result"
911
)
@@ -19,9 +21,9 @@ type Cgo struct {
1921
goCacheDir string
2022
}
2123

22-
func NewCgo(goenv *goutil.Env) *Cgo {
24+
func NewCgo(env *goutil.Env) *Cgo {
2325
return &Cgo{
24-
goCacheDir: goenv.Get(goutil.EnvGoCache),
26+
goCacheDir: env.Get(goenv.GOCACHE),
2527
}
2628
}
2729

0 commit comments

Comments
 (0)