From d137c2e18ccbab01b5d614f1d3918e72528b22e2 Mon Sep 17 00:00:00 2001 From: to6ka Date: Sun, 19 Jan 2020 16:49:46 +0300 Subject: [PATCH] make uniq by line configurable (#920) --- .golangci.example.yml | 3 +++ README.md | 4 ++++ pkg/commands/run.go | 1 + pkg/config/config.go | 1 + pkg/result/processors/uniq_by_line.go | 4 ++++ pkg/result/processors/uniq_by_line_test.go | 16 +++++++++++++++- 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.golangci.example.yml b/.golangci.example.yml index d9af6449..2dc024f6 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -61,6 +61,9 @@ output: # print linter name in the end of issue text, default is true print-linter-name: true + # make issues output unique by line, default is true + uniq-by-line: true + # all available settings of specific linters linters-settings: diff --git a/README.md b/README.md index 097f6820..07b35a9b 100644 --- a/README.md +++ b/README.md @@ -511,6 +511,7 @@ Flags: --out-format string Format of output: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml (default "colored-line-number") --print-issued-lines Print lines of code with issue (default true) --print-linter-name Print linter name in issue line (default true) + --uniq-by-line Make issues output unique by line (default true) --modules-download-mode string Modules download mode. If not empty, passed as -mod= to go tools --issues-exit-code int Exit code when issues were found (default 1) --build-tags strings Build tags @@ -669,6 +670,9 @@ output: # print linter name in the end of issue text, default is true print-linter-name: true + # make issues output unique by line, default is true + uniq-by-line: true + # all available settings of specific linters linters-settings: diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 0236b7e9..9358a651 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -79,6 +79,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is wh(fmt.Sprintf("Format of output: %s", strings.Join(config.OutFormats, "|")))) fs.BoolVar(&oc.PrintIssuedLine, "print-issued-lines", true, wh("Print lines of code with issue")) fs.BoolVar(&oc.PrintLinterName, "print-linter-name", true, wh("Print linter name in issue line")) + fs.BoolVar(&oc.UniqByLine, "uniq-by-line", true, wh("Make issues output unique by line")) fs.BoolVar(&oc.PrintWelcomeMessage, "print-welcome", false, wh("Print welcome message")) hideFlag("print-welcome") // no longer used diff --git a/pkg/config/config.go b/pkg/config/config.go index 38b2ca58..01fa19b6 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -389,6 +389,7 @@ type Config struct { Color string PrintIssuedLine bool `mapstructure:"print-issued-lines"` PrintLinterName bool `mapstructure:"print-linter-name"` + UniqByLine bool `mapstructure:"uniq-by-line"` PrintWelcomeMessage bool `mapstructure:"print-welcome"` } diff --git a/pkg/result/processors/uniq_by_line.go b/pkg/result/processors/uniq_by_line.go index d0960d83..17167dde 100644 --- a/pkg/result/processors/uniq_by_line.go +++ b/pkg/result/processors/uniq_by_line.go @@ -27,6 +27,10 @@ func (p UniqByLine) Name() string { } func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) { + if !p.cfg.Output.UniqByLine { + return issues, nil + } + return filterIssues(issues, func(i *result.Issue) bool { if i.Replacement != nil && p.cfg.Issues.NeedFix { // if issue will be auto-fixed we shouldn't collapse issues: diff --git a/pkg/result/processors/uniq_by_line_test.go b/pkg/result/processors/uniq_by_line_test.go index 31b2cdfa..fbb2cb9a 100644 --- a/pkg/result/processors/uniq_by_line_test.go +++ b/pkg/result/processors/uniq_by_line_test.go @@ -18,7 +18,10 @@ func newFLIssue(file string, line int) result.Issue { } func TestUniqByLine(t *testing.T) { - p := NewUniqByLine(&config.Config{}) + cfg := config.Config{} + cfg.Output.UniqByLine = true + + p := NewUniqByLine(&cfg) i1 := newFLIssue("f1", 1) processAssertSame(t, p, i1) @@ -28,3 +31,14 @@ func TestUniqByLine(t *testing.T) { processAssertSame(t, p, newFLIssue("f1", 2)) // another line processAssertSame(t, p, newFLIssue("f2", 1)) // another file } + +func TestUniqByLineDisabled(t *testing.T) { + cfg := config.Config{} + cfg.Output.UniqByLine = false + + p := NewUniqByLine(&cfg) + i1 := newFLIssue("f1", 1) + + processAssertSame(t, p, i1) + processAssertSame(t, p, i1) // check the same issue passed twice +}