Skip to content

Commit 1b0dbb0

Browse files
peakleldez
andauthored
fix: use first issue without inline on mergeLineIssues on multiplie issues (#3316)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 4fea092 commit 1b0dbb0

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

Diff for: pkg/result/processors/fixer.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,22 @@ func (f Fixer) mergeLineIssues(lineNum int, lineIssues []result.Issue, origFileL
133133

134134
// check issues first
135135
for ind := range lineIssues {
136-
i := &lineIssues[ind]
137-
if i.LineRange != nil {
136+
li := &lineIssues[ind]
137+
138+
if li.LineRange != nil {
138139
f.log.Infof("Line %d has multiple issues but at least one of them is ranged: %#v", lineNum, lineIssues)
139140
return &lineIssues[0]
140141
}
141142

142-
r := i.Replacement
143-
if r.Inline == nil || len(r.NewLines) != 0 || r.NeedOnlyDelete {
143+
inline := li.Replacement.Inline
144+
145+
if inline == nil || len(li.Replacement.NewLines) != 0 || li.Replacement.NeedOnlyDelete {
144146
f.log.Infof("Line %d has multiple issues but at least one of them isn't inline: %#v", lineNum, lineIssues)
145-
return &lineIssues[0]
147+
return li
146148
}
147149

148-
if r.Inline.StartCol < 0 || r.Inline.Length <= 0 || r.Inline.StartCol+r.Inline.Length > len(origLine) {
149-
f.log.Warnf("Line %d (%q) has invalid inline fix: %#v, %#v", lineNum, origLine, i, r.Inline)
150+
if inline.StartCol < 0 || inline.Length <= 0 || inline.StartCol+inline.Length > len(origLine) {
151+
f.log.Warnf("Line %d (%q) has invalid inline fix: %#v, %#v", lineNum, origLine, li, inline)
150152
return nil
151153
}
152154
}

Diff for: test/testdata/configs/multiple-issues-fix.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
gofumpt:
3+
extra-rules: true
4+

Diff for: test/testdata/fix/in/multiple-issues-fix.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//golangcitest:args -Egocritic,gofumpt
2+
//golangcitest:config_path testdata/configs/multiple-issues-fix.yml
3+
//golangcitest:expected_exitcode 0
4+
package p
5+
6+
import "fmt"
7+
8+
func main() {
9+
//standard greeting
10+
fmt.Println("hello world")
11+
}

Diff for: test/testdata/fix/out/multiple-issues-fix.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//golangcitest:args -Egocritic,gofumpt
2+
//golangcitest:config_path testdata/configs/multiple-issues-fix.yml
3+
//golangcitest:expected_exitcode 0
4+
package p
5+
6+
import "fmt"
7+
8+
func main() {
9+
// standard greeting
10+
fmt.Println("hello world")
11+
}

0 commit comments

Comments
 (0)