Skip to content

Commit

Permalink
fix: move uniq-by-line field from output to issues (#5253)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Dec 25, 2024
1 parent b4032c0 commit 93ffea1
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 17 deletions.
8 changes: 4 additions & 4 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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: ""
Expand Down
10 changes: 5 additions & 5 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/flagsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"))
Expand Down
5 changes: 3 additions & 2 deletions pkg/config/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`")
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ 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"`
ShowStats bool `mapstructure:"show-stats"`

// Deprecated: use Formats instead.
Format string `mapstructure:"format"`

// Deprecated: use [Issues.UniqByLine] instead.
UniqByLine *bool `mapstructure:"uniq-by-line"`
}

func (o *Output) Validate() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/result/processors/uniq_by_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

0 comments on commit 93ffea1

Please sign in to comment.