Skip to content
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

fix: use first issue without inline on mergeLineIssues on multiple issues #3316

Merged
merged 5 commits into from
Mar 7, 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
16 changes: 9 additions & 7 deletions pkg/result/processors/fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,22 @@ func (f Fixer) mergeLineIssues(lineNum int, lineIssues []result.Issue, origFileL

// check issues first
for ind := range lineIssues {
i := &lineIssues[ind]
if i.LineRange != nil {
li := &lineIssues[ind]

if li.LineRange != nil {
f.log.Infof("Line %d has multiple issues but at least one of them is ranged: %#v", lineNum, lineIssues)
return &lineIssues[0]
}

r := i.Replacement
if r.Inline == nil || len(r.NewLines) != 0 || r.NeedOnlyDelete {
inline := li.Replacement.Inline

if inline == nil || len(li.Replacement.NewLines) != 0 || li.Replacement.NeedOnlyDelete {
f.log.Infof("Line %d has multiple issues but at least one of them isn't inline: %#v", lineNum, lineIssues)
return &lineIssues[0]
return li
}

if r.Inline.StartCol < 0 || r.Inline.Length <= 0 || r.Inline.StartCol+r.Inline.Length > len(origLine) {
f.log.Warnf("Line %d (%q) has invalid inline fix: %#v, %#v", lineNum, origLine, i, r.Inline)
if inline.StartCol < 0 || inline.Length <= 0 || inline.StartCol+inline.Length > len(origLine) {
f.log.Warnf("Line %d (%q) has invalid inline fix: %#v, %#v", lineNum, origLine, li, inline)
return nil
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/testdata/configs/multiple-issues-fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters-settings:
gofumpt:
extra-rules: true

11 changes: 11 additions & 0 deletions test/testdata/fix/in/multiple-issues-fix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//golangcitest:args -Egocritic,gofumpt
//golangcitest:config_path testdata/configs/multiple-issues-fix.yml
//golangcitest:expected_exitcode 0
package p

import "fmt"

func main() {
//standard greeting
fmt.Println("hello world")
}
11 changes: 11 additions & 0 deletions test/testdata/fix/out/multiple-issues-fix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//golangcitest:args -Egocritic,gofumpt
//golangcitest:config_path testdata/configs/multiple-issues-fix.yml
//golangcitest:expected_exitcode 0
package p

import "fmt"

func main() {
// standard greeting
fmt.Println("hello world")
}
Loading