diff --git a/README.md b/README.md index 243bfa9c..70271df3 100644 --- a/README.md +++ b/README.md @@ -432,6 +432,7 @@ Flags: --print-linter-name Print linter name in issue line (default true) --issues-exit-code int Exit code when issues were found (default 1) --build-tags strings Build tags + --mod string module download mode to use: readonly or vendor (passed to go list) --deadline duration Deadline for total work (default 1m0s) --tests Analyze tests (*_test.go) (default true) --print-resources-usage Print avg and max memory usage of golangci-lint and total time diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 46bfa29e..dc893efe 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -63,6 +63,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager) { fs.IntVar(&rc.ExitCodeIfIssuesFound, "issues-exit-code", exitcodes.IssuesFound, wh("Exit code when issues were found")) fs.StringSliceVar(&rc.BuildTags, "build-tags", nil, wh("Build tags")) + fs.StringVar(&rc.Mod, "mod", "", wh("module download mode to use: readonly or vendor (passed to go list)")) fs.DurationVar(&rc.Deadline, "deadline", time.Minute, wh("Deadline for total work")) fs.BoolVar(&rc.AnalyzeTests, "tests", true, wh("Analyze tests (*_test.go)")) fs.BoolVar(&rc.PrintResourcesUsage, "print-resources-usage", false, diff --git a/pkg/config/config.go b/pkg/config/config.go index ccc4094f..8ec2b077 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -110,6 +110,7 @@ type Run struct { Args []string BuildTags []string `mapstructure:"build-tags"` + Mod string `mapstructure:"mod"` ExitCodeIfIssuesFound int `mapstructure:"issues-exit-code"` AnalyzeTests bool `mapstructure:"tests"` diff --git a/pkg/lint/load.go b/pkg/lint/load.go index e7f25d70..f8cbb4aa 100644 --- a/pkg/lint/load.go +++ b/pkg/lint/load.go @@ -201,10 +201,17 @@ func (cl ContextLoader) loadPackages(ctx context.Context, loadMode packages.Load cl.prepareBuildContext() var buildFlags []string + if len(cl.cfg.Run.BuildTags) != 0 { // go help build buildFlags = []string{"-tags", strings.Join(cl.cfg.Run.BuildTags, " ")} } + + if cl.cfg.Run.Mod != "" { + // go help module + buildFlags = append(buildFlags, fmt.Sprintf("-mod=%s", cl.cfg.Run.Mod)) + } + conf := &packages.Config{ Mode: loadMode, Tests: cl.cfg.Run.AnalyzeTests,