Skip to content

make uniq-by-line configurable #920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,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=<mode> to go tools
--issues-exit-code int Exit code when issues were found (default 1)
--build-tags strings Build tags
Expand Down Expand Up @@ -667,6 +668,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:
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/result/processors/uniq_by_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 15 additions & 1 deletion pkg/result/processors/uniq_by_line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}