Skip to content

Commit d137c2e

Browse files
to6kajirfag
authored andcommitted
make uniq by line configurable (#920)
1 parent bff053a commit d137c2e

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

.golangci.example.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ output:
6161
# print linter name in the end of issue text, default is true
6262
print-linter-name: true
6363

64+
# make issues output unique by line, default is true
65+
uniq-by-line: true
66+
6467

6568
# all available settings of specific linters
6669
linters-settings:

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ Flags:
511511
--out-format string Format of output: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml (default "colored-line-number")
512512
--print-issued-lines Print lines of code with issue (default true)
513513
--print-linter-name Print linter name in issue line (default true)
514+
--uniq-by-line Make issues output unique by line (default true)
514515
--modules-download-mode string Modules download mode. If not empty, passed as -mod=<mode> to go tools
515516
--issues-exit-code int Exit code when issues were found (default 1)
516517
--build-tags strings Build tags
@@ -669,6 +670,9 @@ output:
669670
# print linter name in the end of issue text, default is true
670671
print-linter-name: true
671672
673+
# make issues output unique by line, default is true
674+
uniq-by-line: true
675+
672676
673677
# all available settings of specific linters
674678
linters-settings:

pkg/commands/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
7979
wh(fmt.Sprintf("Format of output: %s", strings.Join(config.OutFormats, "|"))))
8080
fs.BoolVar(&oc.PrintIssuedLine, "print-issued-lines", true, wh("Print lines of code with issue"))
8181
fs.BoolVar(&oc.PrintLinterName, "print-linter-name", true, wh("Print linter name in issue line"))
82+
fs.BoolVar(&oc.UniqByLine, "uniq-by-line", true, wh("Make issues output unique by line"))
8283
fs.BoolVar(&oc.PrintWelcomeMessage, "print-welcome", false, wh("Print welcome message"))
8384
hideFlag("print-welcome") // no longer used
8485

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ type Config struct {
389389
Color string
390390
PrintIssuedLine bool `mapstructure:"print-issued-lines"`
391391
PrintLinterName bool `mapstructure:"print-linter-name"`
392+
UniqByLine bool `mapstructure:"uniq-by-line"`
392393
PrintWelcomeMessage bool `mapstructure:"print-welcome"`
393394
}
394395

pkg/result/processors/uniq_by_line.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func (p UniqByLine) Name() string {
2727
}
2828

2929
func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) {
30+
if !p.cfg.Output.UniqByLine {
31+
return issues, nil
32+
}
33+
3034
return filterIssues(issues, func(i *result.Issue) bool {
3135
if i.Replacement != nil && p.cfg.Issues.NeedFix {
3236
// if issue will be auto-fixed we shouldn't collapse issues:

pkg/result/processors/uniq_by_line_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ func newFLIssue(file string, line int) result.Issue {
1818
}
1919

2020
func TestUniqByLine(t *testing.T) {
21-
p := NewUniqByLine(&config.Config{})
21+
cfg := config.Config{}
22+
cfg.Output.UniqByLine = true
23+
24+
p := NewUniqByLine(&cfg)
2225
i1 := newFLIssue("f1", 1)
2326

2427
processAssertSame(t, p, i1)
@@ -28,3 +31,14 @@ func TestUniqByLine(t *testing.T) {
2831
processAssertSame(t, p, newFLIssue("f1", 2)) // another line
2932
processAssertSame(t, p, newFLIssue("f2", 1)) // another file
3033
}
34+
35+
func TestUniqByLineDisabled(t *testing.T) {
36+
cfg := config.Config{}
37+
cfg.Output.UniqByLine = false
38+
39+
p := NewUniqByLine(&cfg)
40+
i1 := newFLIssue("f1", 1)
41+
42+
processAssertSame(t, p, i1)
43+
processAssertSame(t, p, i1) // check the same issue passed twice
44+
}

0 commit comments

Comments
 (0)