fix: use first issue without inline on mergeLineIssues on multiplie issues (#3316)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
4fea092fa2
commit
1b0dbb0965
@ -133,20 +133,22 @@ func (f Fixer) mergeLineIssues(lineNum int, lineIssues []result.Issue, origFileL
|
|||||||
|
|
||||||
// check issues first
|
// check issues first
|
||||||
for ind := range lineIssues {
|
for ind := range lineIssues {
|
||||||
i := &lineIssues[ind]
|
li := &lineIssues[ind]
|
||||||
if i.LineRange != nil {
|
|
||||||
|
if li.LineRange != nil {
|
||||||
f.log.Infof("Line %d has multiple issues but at least one of them is ranged: %#v", lineNum, lineIssues)
|
f.log.Infof("Line %d has multiple issues but at least one of them is ranged: %#v", lineNum, lineIssues)
|
||||||
return &lineIssues[0]
|
return &lineIssues[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
r := i.Replacement
|
inline := li.Replacement.Inline
|
||||||
if r.Inline == nil || len(r.NewLines) != 0 || r.NeedOnlyDelete {
|
|
||||||
|
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)
|
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) {
|
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, i, r.Inline)
|
f.log.Warnf("Line %d (%q) has invalid inline fix: %#v, %#v", lineNum, origLine, li, inline)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
test/testdata/configs/multiple-issues-fix.yml
vendored
Normal file
4
test/testdata/configs/multiple-issues-fix.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
linters-settings:
|
||||||
|
gofumpt:
|
||||||
|
extra-rules: true
|
||||||
|
|
11
test/testdata/fix/in/multiple-issues-fix.go
vendored
Normal file
11
test/testdata/fix/in/multiple-issues-fix.go
vendored
Normal file
@ -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
test/testdata/fix/out/multiple-issues-fix.go
vendored
Normal file
11
test/testdata/fix/out/multiple-issues-fix.go
vendored
Normal file
@ -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…
x
Reference in New Issue
Block a user