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:
Denis Limarev 2024-03-08 00:18:09 +05:00 committed by GitHub
parent 4fea092fa2
commit 1b0dbb0965
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 7 deletions

View File

@ -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
}
}

View File

@ -0,0 +1,4 @@
linters-settings:
gofumpt:
extra-rules: true

View 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")
}

View 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")
}