Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions pkg/golinters/revive/revive.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ func (w *wrapper) toIssue(pass *analysis.Pass, failure *lint.Failure) *goanalysi
if failure.Filename() == f.Name() {
issue.SuggestedFixes = []analysis.SuggestedFix{{
TextEdits: []analysis.TextEdit{{
Pos: f.LineStart(failure.Position.Start.Line),
End: goanalysis.EndOfLinePos(f, failure.Position.End.Line),
Pos: f.LineStart(failure.Position.Start.Line),
// ReplacementLine doesn't contain the full line (missing newline), so we have to remove 1 from the position of the EOL.
// Also `failure.Position.End.Offset` is at the end of the element but not of the line.
End: goanalysis.EndOfLinePos(f, failure.Position.End.Line) - token.Pos(1),
NewText: []byte(failure.ReplacementLine),
}},
}}
Expand Down
12 changes: 12 additions & 0 deletions pkg/golinters/revive/testdata/fix/in/revive.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ import (
func _() error {
return errors.New(fmt.Sprintf("foo: %d", math.MaxInt))
}

func _() (int, error) {
c := errors.New(fmt.Sprintf("bar: %d", math.MaxInt))
return 1, c
}

func _() (int, error) {
if c := errors.New(fmt.Sprintf("bar: %d", math.MaxInt)); c != nil {
return 0, c
}
return 1, nil
}
12 changes: 12 additions & 0 deletions pkg/golinters/revive/testdata/fix/out/revive.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ import (
func _() error {
return fmt.Errorf("foo: %d", math.MaxInt)
}

func _() (int, error) {
c := fmt.Errorf("bar: %d", math.MaxInt)
return 1, c
}

func _() (int, error) {
if c := fmt.Errorf("bar: %d", math.MaxInt); c != nil {
return 0, c
}
return 1, nil
}
Loading