diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 83ed0728f545..38718cee0cb7 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -3984,6 +3984,10 @@ issues: # Default: 3 max-same-issues: 0 + # Make issues output unique by line. + # Default: true + uniq-by-line: false + # Show only new issues: if there are unstaged changes or untracked files, # only those changes are analyzed, else only changes in HEAD~ are analyzed. # It's a super-useful option for integration of golangci-lint into existing large codebase. @@ -4053,10 +4057,6 @@ output: # Default: true print-linter-name: false - # Make issues output unique by line. - # Default: true - uniq-by-line: false - # Add a prefix to the output file references. # Default: "" path-prefix: "" diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 7e94f74065bf..f21a4557081d 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -560,11 +560,6 @@ "type": "boolean", "default": true }, - "uniq-by-line": { - "description": "Make issues output unique by line.", - "type": "boolean", - "default": true - }, "path-prefix": { "description": "Add a prefix to the output file references.", "type": "string", @@ -3967,6 +3962,11 @@ "type": "boolean", "default": false }, + "uniq-by-line": { + "description": "Make issues output unique by line.", + "type": "boolean", + "default": true + }, "whole-files": { "description": "Show issues in any part of update files (requires new-from-rev or new-from-patch).", "type": "boolean", diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go index 6176b4e3174d..4a9f0e970380 100644 --- a/pkg/commands/flagsets.go +++ b/pkg/commands/flagsets.go @@ -75,8 +75,6 @@ func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) { color.GreenString("Print lines of code with issue")) internal.AddFlagAndBind(v, fs, fs.Bool, "print-linter-name", "output.print-linter-name", true, color.GreenString("Print linter name in issue line")) - internal.AddFlagAndBind(v, fs, fs.Bool, "uniq-by-line", "output.uniq-by-line", true, - color.GreenString("Make issues output unique by line")) internal.AddFlagAndBind(v, fs, fs.Bool, "sort-results", "output.sort-results", false, color.GreenString("Sort linter results")) internal.AddFlagAndBind(v, fs, fs.StringSlice, "sort-order", "output.sort-order", nil, @@ -98,6 +96,8 @@ func setupIssuesFlagSet(v *viper.Viper, fs *pflag.FlagSet) { color.GreenString("Maximum issues count per one linter. Set to 0 to disable")) internal.AddFlagAndBind(v, fs, fs.Int, "max-same-issues", "issues.max-same-issues", 3, color.GreenString("Maximum count of issues with the same text. Set to 0 to disable")) + internal.AddFlagAndBind(v, fs, fs.Bool, "uniq-by-line", "issues.uniq-by-line", true, + color.GreenString("Make issues output unique by line")) internal.AddHackedStringSlice(fs, "exclude-files", color.GreenString("Regexps of files to exclude")) internal.AddHackedStringSlice(fs, "exclude-dirs", color.GreenString("Regexps of directories to exclude")) diff --git a/pkg/config/issues.go b/pkg/config/issues.go index 2ee9364aaa91..49f4dcf88c67 100644 --- a/pkg/config/issues.go +++ b/pkg/config/issues.go @@ -117,8 +117,9 @@ type Issues struct { UseDefaultExcludeDirs bool `mapstructure:"exclude-dirs-use-default"` - MaxIssuesPerLinter int `mapstructure:"max-issues-per-linter"` - MaxSameIssues int `mapstructure:"max-same-issues"` + MaxIssuesPerLinter int `mapstructure:"max-issues-per-linter"` + MaxSameIssues int `mapstructure:"max-same-issues"` + UniqByLine bool `mapstructure:"uniq-by-line"` DiffFromRevision string `mapstructure:"new-from-rev"` DiffPatchFilePath string `mapstructure:"new-from-patch"` diff --git a/pkg/config/loader.go b/pkg/config/loader.go index 256bda8d3b55..0c90ad41d57a 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -304,6 +304,7 @@ func (l *Loader) handleGoVersion() { os.Setenv("GOSECGOVERSION", l.cfg.Run.Go) } +//nolint:gocyclo // The complexity is expected by the cases to handle. func (l *Loader) handleDeprecation() error { if l.cfg.InternalTest || l.cfg.InternalCmdTest || os.Getenv(logutils.EnvTestRun) == "1" { return nil @@ -335,6 +336,12 @@ func (l *Loader) handleDeprecation() error { } l.cfg.Output.ShowStats = l.cfg.Run.ShowStats || l.cfg.Output.ShowStats + // Deprecated since v1.63.0 + if l.cfg.Output.UniqByLine != nil { + l.log.Warnf("The configuration option `output.uniq-by-line` is deprecated, please use `issues.uniq-by-line`") + l.cfg.Issues.UniqByLine = *l.cfg.Output.UniqByLine + } + // Deprecated since v1.57.0 if l.cfg.Output.Format != "" { l.log.Warnf("The configuration option `output.format` is deprecated, please use `output.formats`") diff --git a/pkg/config/output.go b/pkg/config/output.go index 6a26d5773e76..aaa5183ec4e4 100644 --- a/pkg/config/output.go +++ b/pkg/config/output.go @@ -43,7 +43,6 @@ type Output struct { Formats OutputFormats `mapstructure:"formats"` PrintIssuedLine bool `mapstructure:"print-issued-lines"` PrintLinterName bool `mapstructure:"print-linter-name"` - UniqByLine bool `mapstructure:"uniq-by-line"` SortResults bool `mapstructure:"sort-results"` SortOrder []string `mapstructure:"sort-order"` PathPrefix string `mapstructure:"path-prefix"` @@ -51,6 +50,9 @@ type Output struct { // Deprecated: use Formats instead. Format string `mapstructure:"format"` + + // Deprecated: use [Issues.UniqByLine] instead. + UniqByLine *bool `mapstructure:"uniq-by-line"` } func (o *Output) Validate() error { diff --git a/pkg/result/processors/uniq_by_line.go b/pkg/result/processors/uniq_by_line.go index c3a59ac000c6..ec134f25f6ae 100644 --- a/pkg/result/processors/uniq_by_line.go +++ b/pkg/result/processors/uniq_by_line.go @@ -26,7 +26,7 @@ func (*UniqByLine) Name() string { } func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) { - if !p.cfg.Output.UniqByLine { + if !p.cfg.Issues.UniqByLine { return issues, nil } diff --git a/pkg/result/processors/uniq_by_line_test.go b/pkg/result/processors/uniq_by_line_test.go index fbb2cb9a7e11..d96e95ab4b52 100644 --- a/pkg/result/processors/uniq_by_line_test.go +++ b/pkg/result/processors/uniq_by_line_test.go @@ -19,7 +19,7 @@ func newFLIssue(file string, line int) result.Issue { func TestUniqByLine(t *testing.T) { cfg := config.Config{} - cfg.Output.UniqByLine = true + cfg.Issues.UniqByLine = true p := NewUniqByLine(&cfg) i1 := newFLIssue("f1", 1) @@ -34,7 +34,7 @@ func TestUniqByLine(t *testing.T) { func TestUniqByLineDisabled(t *testing.T) { cfg := config.Config{} - cfg.Output.UniqByLine = false + cfg.Issues.UniqByLine = false p := NewUniqByLine(&cfg) i1 := newFLIssue("f1", 1)