Skip to content

Commit 93ffea1

Browse files
authored
fix: move uniq-by-line field from output to issues (#5253)
1 parent b4032c0 commit 93ffea1

File tree

8 files changed

+27
-17
lines changed

8 files changed

+27
-17
lines changed

.golangci.next.reference.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3984,6 +3984,10 @@ issues:
39843984
# Default: 3
39853985
max-same-issues: 0
39863986

3987+
# Make issues output unique by line.
3988+
# Default: true
3989+
uniq-by-line: false
3990+
39873991
# Show only new issues: if there are unstaged changes or untracked files,
39883992
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
39893993
# It's a super-useful option for integration of golangci-lint into existing large codebase.
@@ -4053,10 +4057,6 @@ output:
40534057
# Default: true
40544058
print-linter-name: false
40554059

4056-
# Make issues output unique by line.
4057-
# Default: true
4058-
uniq-by-line: false
4059-
40604060
# Add a prefix to the output file references.
40614061
# Default: ""
40624062
path-prefix: ""

jsonschema/golangci.next.jsonschema.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,6 @@
560560
"type": "boolean",
561561
"default": true
562562
},
563-
"uniq-by-line": {
564-
"description": "Make issues output unique by line.",
565-
"type": "boolean",
566-
"default": true
567-
},
568563
"path-prefix": {
569564
"description": "Add a prefix to the output file references.",
570565
"type": "string",
@@ -3967,6 +3962,11 @@
39673962
"type": "boolean",
39683963
"default": false
39693964
},
3965+
"uniq-by-line": {
3966+
"description": "Make issues output unique by line.",
3967+
"type": "boolean",
3968+
"default": true
3969+
},
39703970
"whole-files": {
39713971
"description": "Show issues in any part of update files (requires new-from-rev or new-from-patch).",
39723972
"type": "boolean",

pkg/commands/flagsets.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
7575
color.GreenString("Print lines of code with issue"))
7676
internal.AddFlagAndBind(v, fs, fs.Bool, "print-linter-name", "output.print-linter-name", true,
7777
color.GreenString("Print linter name in issue line"))
78-
internal.AddFlagAndBind(v, fs, fs.Bool, "uniq-by-line", "output.uniq-by-line", true,
79-
color.GreenString("Make issues output unique by line"))
8078
internal.AddFlagAndBind(v, fs, fs.Bool, "sort-results", "output.sort-results", false,
8179
color.GreenString("Sort linter results"))
8280
internal.AddFlagAndBind(v, fs, fs.StringSlice, "sort-order", "output.sort-order", nil,
@@ -98,6 +96,8 @@ func setupIssuesFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
9896
color.GreenString("Maximum issues count per one linter. Set to 0 to disable"))
9997
internal.AddFlagAndBind(v, fs, fs.Int, "max-same-issues", "issues.max-same-issues", 3,
10098
color.GreenString("Maximum count of issues with the same text. Set to 0 to disable"))
99+
internal.AddFlagAndBind(v, fs, fs.Bool, "uniq-by-line", "issues.uniq-by-line", true,
100+
color.GreenString("Make issues output unique by line"))
101101

102102
internal.AddHackedStringSlice(fs, "exclude-files", color.GreenString("Regexps of files to exclude"))
103103
internal.AddHackedStringSlice(fs, "exclude-dirs", color.GreenString("Regexps of directories to exclude"))

pkg/config/issues.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ type Issues struct {
117117

118118
UseDefaultExcludeDirs bool `mapstructure:"exclude-dirs-use-default"`
119119

120-
MaxIssuesPerLinter int `mapstructure:"max-issues-per-linter"`
121-
MaxSameIssues int `mapstructure:"max-same-issues"`
120+
MaxIssuesPerLinter int `mapstructure:"max-issues-per-linter"`
121+
MaxSameIssues int `mapstructure:"max-same-issues"`
122+
UniqByLine bool `mapstructure:"uniq-by-line"`
122123

123124
DiffFromRevision string `mapstructure:"new-from-rev"`
124125
DiffPatchFilePath string `mapstructure:"new-from-patch"`

pkg/config/loader.go

+7
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ func (l *Loader) handleGoVersion() {
304304
os.Setenv("GOSECGOVERSION", l.cfg.Run.Go)
305305
}
306306

307+
//nolint:gocyclo // The complexity is expected by the cases to handle.
307308
func (l *Loader) handleDeprecation() error {
308309
if l.cfg.InternalTest || l.cfg.InternalCmdTest || os.Getenv(logutils.EnvTestRun) == "1" {
309310
return nil
@@ -335,6 +336,12 @@ func (l *Loader) handleDeprecation() error {
335336
}
336337
l.cfg.Output.ShowStats = l.cfg.Run.ShowStats || l.cfg.Output.ShowStats
337338

339+
// Deprecated since v1.63.0
340+
if l.cfg.Output.UniqByLine != nil {
341+
l.log.Warnf("The configuration option `output.uniq-by-line` is deprecated, please use `issues.uniq-by-line`")
342+
l.cfg.Issues.UniqByLine = *l.cfg.Output.UniqByLine
343+
}
344+
338345
// Deprecated since v1.57.0
339346
if l.cfg.Output.Format != "" {
340347
l.log.Warnf("The configuration option `output.format` is deprecated, please use `output.formats`")

pkg/config/output.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ type Output struct {
4343
Formats OutputFormats `mapstructure:"formats"`
4444
PrintIssuedLine bool `mapstructure:"print-issued-lines"`
4545
PrintLinterName bool `mapstructure:"print-linter-name"`
46-
UniqByLine bool `mapstructure:"uniq-by-line"`
4746
SortResults bool `mapstructure:"sort-results"`
4847
SortOrder []string `mapstructure:"sort-order"`
4948
PathPrefix string `mapstructure:"path-prefix"`
5049
ShowStats bool `mapstructure:"show-stats"`
5150

5251
// Deprecated: use Formats instead.
5352
Format string `mapstructure:"format"`
53+
54+
// Deprecated: use [Issues.UniqByLine] instead.
55+
UniqByLine *bool `mapstructure:"uniq-by-line"`
5456
}
5557

5658
func (o *Output) Validate() error {

pkg/result/processors/uniq_by_line.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (*UniqByLine) Name() string {
2626
}
2727

2828
func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) {
29-
if !p.cfg.Output.UniqByLine {
29+
if !p.cfg.Issues.UniqByLine {
3030
return issues, nil
3131
}
3232

pkg/result/processors/uniq_by_line_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func newFLIssue(file string, line int) result.Issue {
1919

2020
func TestUniqByLine(t *testing.T) {
2121
cfg := config.Config{}
22-
cfg.Output.UniqByLine = true
22+
cfg.Issues.UniqByLine = true
2323

2424
p := NewUniqByLine(&cfg)
2525
i1 := newFLIssue("f1", 1)
@@ -34,7 +34,7 @@ func TestUniqByLine(t *testing.T) {
3434

3535
func TestUniqByLineDisabled(t *testing.T) {
3636
cfg := config.Config{}
37-
cfg.Output.UniqByLine = false
37+
cfg.Issues.UniqByLine = false
3838

3939
p := NewUniqByLine(&cfg)
4040
i1 := newFLIssue("f1", 1)

0 commit comments

Comments
 (0)