Skip to content

fix: move uniq-by-line field from output to issues #5253

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 2 commits into from
Dec 25, 2024
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
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
Loading