From a24f934ee19c97b970f14e7f2b10246ba98be0eb Mon Sep 17 00:00:00 2001 From: Kevin Franklin Kim Date: Wed, 4 Dec 2024 10:56:57 +0100 Subject: [PATCH] fix(golang): sort paths --- golang/command.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/golang/command.go b/golang/command.go index 04d0c3c..5b1fde1 100644 --- a/golang/command.go +++ b/golang/command.go @@ -15,6 +15,7 @@ import ( "github.com/foomo/posh/pkg/shell" "github.com/foomo/posh/pkg/util/files" "github.com/foomo/posh/pkg/util/suggests" + "golang.org/x/exp/slices" "golang.org/x/sync/errgroup" ) @@ -122,6 +123,11 @@ func NewCommand(l log.Logger, cache cache.Cache) *Command { Args: []*tree.Arg{pathGenerateArg}, Execute: inst.generate, }, + { + Name: "clean-lint-cache", + Description: "Run golangci lint cache clean", + Execute: inst.cleanLintCache, + }, { Name: "lint", Description: "Run golangci lint", @@ -198,6 +204,7 @@ func (c *Command) build(ctx context.Context, r *readline.Readline) error { } else { paths = c.paths(ctx, "go.mod", true) } + slices.Sort(paths) ctx, wg := c.wg(ctx, r) c.l.Info("Running go build ...") @@ -223,6 +230,8 @@ func (c *Command) test(ctx context.Context, r *readline.Readline) error { } else { paths = c.paths(ctx, "go.mod", true) } + slices.Sort(paths) + fsi := r.FlagSets().Internal() if value, _ := fsi.GetString("tags"); value != "" { envs = append(envs, "GO_TEST_TAGS="+value) @@ -252,6 +261,8 @@ func (c *Command) modTidy(ctx context.Context, r *readline.Readline) error { } else { paths = c.paths(ctx, "go.mod", true) } + slices.Sort(paths) + ctx, wg := c.wg(ctx, r) c.l.Info("Running go mod tidy...") for _, value := range paths { @@ -275,6 +286,8 @@ func (c *Command) modDownload(ctx context.Context, r *readline.Readline) error { } else { paths = c.paths(ctx, "go.mod", true) } + slices.Sort(paths) + ctx, wg := c.wg(ctx, r) c.l.Info("Running go mod download...") for _, value := range paths { @@ -298,6 +311,8 @@ func (c *Command) modOutdated(ctx context.Context, r *readline.Readline) error { } else { paths = c.paths(ctx, "go.mod", true) } + slices.Sort(paths) + ctx, wg := c.wg(ctx, r) c.l.Info("Running go mod outdated...") for _, value := range paths { @@ -340,6 +355,8 @@ func (c *Command) lint(ctx context.Context, r *readline.Readline) error { } else { paths = c.paths(ctx, "go.mod", true) } + slices.Sort(paths) + var args []string ctx, wg := c.wg(ctx, r) c.l.Info("Running golangci-lint run...") @@ -362,6 +379,10 @@ func (c *Command) lint(ctx context.Context, r *readline.Readline) error { return wg.Wait() } +func (c *Command) cleanLintCache(ctx context.Context, r *readline.Readline) error { + return shell.New(ctx, c.l, "golangci-lint", "cache", "clean").Run() +} + func (c *Command) generate(ctx context.Context, r *readline.Readline) error { var paths []string if r.Args().HasIndex(1) { @@ -369,6 +390,7 @@ func (c *Command) generate(ctx context.Context, r *readline.Readline) error { } else { paths = c.paths(ctx, "generate.go", false) } + slices.Sort(paths) ctx, wg := c.wg(ctx, r) c.l.Info("Running go generate...")