make uniq by line configurable (#920)
This commit is contained in:
parent
bff053ac46
commit
d137c2e18c
@ -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:
|
||||
|
@ -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=<mode> 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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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"`
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user