From d6dd5bbbd2b9a71c32d88c4f1847943feb0ff2a5 Mon Sep 17 00:00:00 2001 From: k-omotani Date: Wed, 25 Jun 2025 13:07:17 +0900 Subject: [PATCH] feat: clear analysis cache when running custom command This change ensures that the custom build of golangci-lint always starts with a clean cache by removing the cache directory before building. This prevents potential issues where stale cached analysis results might affect the custom build's behavior. --- pkg/commands/custom.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/commands/custom.go b/pkg/commands/custom.go index a53197ce3457..e084bd38d28c 100644 --- a/pkg/commands/custom.go +++ b/pkg/commands/custom.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" + "github.com/golangci/golangci-lint/v2/internal/cache" "github.com/golangci/golangci-lint/v2/pkg/commands/internal" "github.com/golangci/golangci-lint/v2/pkg/logutils" ) @@ -55,6 +56,14 @@ func (c *customCommand) preRunE(_ *cobra.Command, _ []string) error { } func (c *customCommand) runE(cmd *cobra.Command, _ []string) error { + // Clear cache before building custom version + cacheDir := cache.DefaultDir() + if err := os.RemoveAll(cacheDir); err != nil { + c.log.Warnf("Failed to clear cache: %v", err) + } else { + c.log.Infof("Cache cleared: %s", cacheDir) + } + tmp, err := os.MkdirTemp(os.TempDir(), "custom-gcl") if err != nil { return fmt.Errorf("create temporary directory: %w", err)