Skip to content

Commit 511b04d

Browse files
committed
fixes after testing all linters on self repo
1 parent 5dc876c commit 511b04d

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

internal/commands/run.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (e *Executor) initRun() {
6565
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")
6666

6767
runCmd.Flags().IntVar(&rc.Dupl.Threshold, "dupl.threshold",
68-
20, "Dupl: Minimal threshold to detect copy-paste")
68+
150, "Dupl: Minimal threshold to detect copy-paste")
6969

7070
runCmd.Flags().IntVar(&rc.Goconst.MinStringLen, "goconst.min-len",
7171
3, "Goconst: minimum constant string length")
@@ -79,7 +79,9 @@ func (e *Executor) initRun() {
7979

8080
runCmd.Flags().DurationVar(&rc.Deadline, "deadline", time.Second*30, "Deadline for total work")
8181

82-
runCmd.Flags().StringSliceVarP(&rc.ExcludePatterns, "exclude", "e", config.DefaultExcludePatterns, "Exclude issue by regexp")
82+
runCmd.Flags().StringSliceVarP(&rc.ExcludePatterns, "exclude", "e", []string{}, "Exclude issue by regexp")
83+
runCmd.Flags().BoolVar(&rc.UseDefaultExcludes, "exclude-use-default", true,
84+
fmt.Sprintf("Use or not use default excludes: (%s)", strings.Join(config.DefaultExcludePatterns, "|")))
8385

8486
runCmd.Flags().IntVar(&rc.MaxIssuesPerLinter, "max-issues-per-linter", 50, "Maximum issues count per one linter. Set to 0 to disable")
8587

@@ -197,9 +199,17 @@ func (e *Executor) runAnalysis(ctx context.Context, args []string) (chan result.
197199
return nil, err
198200
}
199201

202+
excludePatterns := e.cfg.Run.ExcludePatterns
203+
if e.cfg.Run.UseDefaultExcludes {
204+
excludePatterns = append(excludePatterns, config.DefaultExcludePatterns...)
205+
}
206+
var excludeTotalPattern string
207+
if len(excludePatterns) != 0 {
208+
excludeTotalPattern = fmt.Sprintf("(%s)", strings.Join(excludePatterns, "|"))
209+
}
200210
runner := pkg.SimpleRunner{
201211
Processors: []processors.Processor{
202-
processors.NewExclude(fmt.Sprintf("(%s)", strings.Join(e.cfg.Run.ExcludePatterns, "|"))),
212+
processors.NewExclude(excludeTotalPattern),
203213
processors.NewNolint(lintCtx.Program.Fset),
204214
processors.NewUniqByLine(),
205215
processors.NewDiff(e.cfg.Run.Diff, e.cfg.Run.DiffFromRevision, e.cfg.Run.DiffPatchFilePath),

pkg/config/config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ const (
1414

1515
var OutFormats = []string{OutFormatColoredLineNumber, OutFormatLineNumber, OutFormatJSON}
1616

17-
var DefaultExcludePatterns = []string{"should have comment", "comment on exported method"}
17+
var DefaultExcludePatterns = []string{
18+
"should have comment",
19+
"comment on exported method",
20+
"G104", // disable what errcheck does: it reports on Close etc
21+
"G204", // Subprocess launching should be audited: too lot false positives
22+
"G304", // Potential file inclusion via variable: `src, err := ioutil.ReadFile(filename)`
23+
}
1824

1925
type Common struct {
2026
IsVerbose bool
2127
CPUProfilePath string
2228
Concurrency int
2329
}
2430

25-
type Run struct {
31+
type Run struct { // nolint:maligned
2632
Args []string
2733

2834
BuildTags []string
@@ -76,7 +82,8 @@ type Run struct {
7682
EnableAllLinters bool
7783
DisableAllLinters bool
7884

79-
ExcludePatterns []string
85+
ExcludePatterns []string
86+
UseDefaultExcludes bool
8087

8188
Deadline time.Duration
8289

pkg/golinters/gas.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (Gas) Name() string {
2121

2222
func (lint Gas) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) {
2323
gasConfig := gas.NewConfig()
24-
enabledRules := rules.Generate(rules.NewRuleFilter(true, "G104")) // disable what errcheck does: it reports on Close etc
24+
enabledRules := rules.Generate()
2525
logger := log.New(ioutil.Discard, "", 0)
2626
analyzer := gas.NewAnalyzer(gasConfig, logger)
2727
analyzer.LoadRules(enabledRules.Builders())

0 commit comments

Comments
 (0)