From 511b04de5e310f8e304845885cd3ae79bc768c4d Mon Sep 17 00:00:00 2001 From: golangci Date: Tue, 8 May 2018 12:10:24 +0300 Subject: [PATCH] fixes after testing all linters on self repo --- internal/commands/run.go | 16 +++++++++++++--- pkg/config/config.go | 13 ++++++++++--- pkg/golinters/gas.go | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/internal/commands/run.go b/internal/commands/run.go index 99c7c690..d0da61fa 100644 --- a/internal/commands/run.go +++ b/internal/commands/run.go @@ -65,7 +65,7 @@ func (e *Executor) initRun() { runCmd.Flags().BoolVar(&rc.Megacheck.EnableUnused, "megacheck.unused", true, "Megacheck: run Unused sub-linter: unused checks Go code for unused constants, variables, functions and types") runCmd.Flags().IntVar(&rc.Dupl.Threshold, "dupl.threshold", - 20, "Dupl: Minimal threshold to detect copy-paste") + 150, "Dupl: Minimal threshold to detect copy-paste") runCmd.Flags().IntVar(&rc.Goconst.MinStringLen, "goconst.min-len", 3, "Goconst: minimum constant string length") @@ -79,7 +79,9 @@ func (e *Executor) initRun() { runCmd.Flags().DurationVar(&rc.Deadline, "deadline", time.Second*30, "Deadline for total work") - runCmd.Flags().StringSliceVarP(&rc.ExcludePatterns, "exclude", "e", config.DefaultExcludePatterns, "Exclude issue by regexp") + runCmd.Flags().StringSliceVarP(&rc.ExcludePatterns, "exclude", "e", []string{}, "Exclude issue by regexp") + runCmd.Flags().BoolVar(&rc.UseDefaultExcludes, "exclude-use-default", true, + fmt.Sprintf("Use or not use default excludes: (%s)", strings.Join(config.DefaultExcludePatterns, "|"))) runCmd.Flags().IntVar(&rc.MaxIssuesPerLinter, "max-issues-per-linter", 50, "Maximum issues count per one linter. Set to 0 to disable") @@ -197,9 +199,17 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (chan result. return nil, err } + excludePatterns := e.cfg.Run.ExcludePatterns + if e.cfg.Run.UseDefaultExcludes { + excludePatterns = append(excludePatterns, config.DefaultExcludePatterns...) + } + var excludeTotalPattern string + if len(excludePatterns) != 0 { + excludeTotalPattern = fmt.Sprintf("(%s)", strings.Join(excludePatterns, "|")) + } runner := pkg.SimpleRunner{ Processors: []processors.Processor{ - processors.NewExclude(fmt.Sprintf("(%s)", strings.Join(e.cfg.Run.ExcludePatterns, "|"))), + processors.NewExclude(excludeTotalPattern), processors.NewNolint(lintCtx.Program.Fset), processors.NewUniqByLine(), processors.NewDiff(e.cfg.Run.Diff, e.cfg.Run.DiffFromRevision, e.cfg.Run.DiffPatchFilePath), diff --git a/pkg/config/config.go b/pkg/config/config.go index ab68d044..d0be7471 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -14,7 +14,13 @@ const ( var OutFormats = []string{OutFormatColoredLineNumber, OutFormatLineNumber, OutFormatJSON} -var DefaultExcludePatterns = []string{"should have comment", "comment on exported method"} +var DefaultExcludePatterns = []string{ + "should have comment", + "comment on exported method", + "G104", // disable what errcheck does: it reports on Close etc + "G204", // Subprocess launching should be audited: too lot false positives + "G304", // Potential file inclusion via variable: `src, err := ioutil.ReadFile(filename)` +} type Common struct { IsVerbose bool @@ -22,7 +28,7 @@ type Common struct { Concurrency int } -type Run struct { +type Run struct { // nolint:maligned Args []string BuildTags []string @@ -76,7 +82,8 @@ type Run struct { EnableAllLinters bool DisableAllLinters bool - ExcludePatterns []string + ExcludePatterns []string + UseDefaultExcludes bool Deadline time.Duration diff --git a/pkg/golinters/gas.go b/pkg/golinters/gas.go index c45bfc86..a932feab 100644 --- a/pkg/golinters/gas.go +++ b/pkg/golinters/gas.go @@ -21,7 +21,7 @@ func (Gas) Name() string { func (lint Gas) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) { gasConfig := gas.NewConfig() - enabledRules := rules.Generate(rules.NewRuleFilter(true, "G104")) // disable what errcheck does: it reports on Close etc + enabledRules := rules.Generate() logger := log.New(ioutil.Discard, "", 0) analyzer := gas.NewAnalyzer(gasConfig, logger) analyzer.LoadRules(enabledRules.Builders())