Skip to content

feat: Clear analysis cache when running custom command #5894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/commands/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down