diff --git a/internal/commands/run.go b/internal/commands/run.go index 99300e61..70362ef7 100644 --- a/internal/commands/run.go +++ b/internal/commands/run.go @@ -53,6 +53,8 @@ func (e *Executor) initRun() { runCmd.Flags().StringSliceVarP(&rc.DisabledLinters, "disable", "D", []string{}, "Disable specific linter") runCmd.Flags().BoolVar(&rc.EnableAllLinters, "enable-all", false, "Enable all linters") runCmd.Flags().BoolVar(&rc.DisableAllLinters, "disable-all", false, "Disable all linters") + + runCmd.Flags().StringSliceVarP(&rc.ExcludePatterns, "exclude", "e", config.DefaultExcludePatterns, "Exclude issue by regexp") } func (e Executor) executeRun(cmd *cobra.Command, args []string) { @@ -92,7 +94,8 @@ func (e Executor) executeRun(cmd *cobra.Command, args []string) { runner := pkg.SimpleRunner{ Processors: []processors.Processor{ processors.MaxLinterIssuesPerFile{}, - //processors.UniqByLineProcessor{}, + processors.UniqByLineProcessor{}, + processors.NewExcludeProcessor(fmt.Sprintf("(%s)", strings.Join(e.cfg.Run.ExcludePatterns, "|"))), processors.NewPathPrettifier(), }, } diff --git a/pkg/config/config.go b/pkg/config/config.go index 911289a4..9afdf2c4 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -12,6 +12,8 @@ const ( var OutFormats = []string{OutFormatColoredLineNumber, OutFormatLineNumber, OutFormatJSON} +var DefaultExcludePatterns = []string{"should have comment", "comment on exported method"} + type Common struct { IsVerbose bool CPUProfilePath string @@ -44,6 +46,8 @@ type Run struct { DisabledLinters []string EnableAllLinters bool DisableAllLinters bool + + ExcludePatterns []string } type Config struct { diff --git a/pkg/golinters/linters_test.go b/pkg/golinters/linters_test.go index d395f853..274dd1e7 100644 --- a/pkg/golinters/linters_test.go +++ b/pkg/golinters/linters_test.go @@ -45,6 +45,6 @@ func installBinary(t *testing.T) { func testOneSource(t *testing.T, sourcePath string) { goErrchkBin := filepath.Join(runtime.GOROOT(), "test", "errchk") - cmd := exec.Command(goErrchkBin, binName, "run", sourcePath) + cmd := exec.Command(goErrchkBin, binName, "run", "--enable-all", sourcePath) runGoErrchk(cmd, t) } diff --git a/pkg/golinters/testdata/golint.go b/pkg/golinters/testdata/golint.go index 5ca5030e..e1a7024d 100644 --- a/pkg/golinters/testdata/golint.go +++ b/pkg/golinters/testdata/golint.go @@ -1,3 +1,15 @@ package testdata var go_lint string // ERROR "don't use underscores in Go names; var go_lint should be goLint" + +func ExportedFuncWithNoComment() { +} + +var ExportedVarWithNoComment string + +type ExportedStructWithNoComment struct{} + +type ExportedInterfaceWithNoComment interface{} + +// Bad comment // ERROR "comment on exported function ExportedFuncWithBadComment should be of the form .ExportedFuncWithBadComment \.\.\.." +func ExportedFuncWithBadComment() {}