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: invalid from position #5287

Merged
merged 2 commits into from
Jan 2, 2025
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
10 changes: 10 additions & 0 deletions pkg/golinters/gofmt/testdata/gofmt_too_many_empty_lines.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//golangcitest:args -Egofmt
package testdata

import "fmt"

// want +4 "File is not properly formatted"
func _() {
fmt.Println("foo")
}

10 changes: 10 additions & 0 deletions pkg/golinters/gofumpt/testdata/gofumpt_too_many_empty_lines.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//golangcitest:args -Egofumpt
package testdata

import "fmt"

// want +4 "File is not properly formatted"
func _() {
fmt.Println("foo")
}

7 changes: 6 additions & 1 deletion pkg/golinters/internal/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ func ExtractDiagnosticFromPatch(
}

func toDiagnostic(ft *token.File, change Change, adjLine int) analysis.Diagnostic {
start := ft.LineStart(change.From + adjLine)
from := change.From + adjLine
if from > ft.LineCount() {
from = ft.LineCount()
}

start := ft.LineStart(from)

end := goanalysis.EndOfLinePos(ft, change.To+adjLine)

Expand Down
7 changes: 7 additions & 0 deletions pkg/golinters/internal/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func Test_parse(t *testing.T) {
log logutils.Log
expected []Change
}{
{
diff: "delete_last_line.diff",
expected: []Change{{
From: 10,
To: 10,
}},
},
{
diff: "delete_only_first_lines.diff",
expected: []Change{{
Expand Down
9 changes: 9 additions & 0 deletions pkg/golinters/internal/testdata/delete_last_line.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
diff --git i/main.go w/main.go
index ef3cbb7..52a7925 100644
--- i/main.go
+++ w/main.go
@@ -7,4 +7,3 @@ import (
func main() {
fmt.Println("hello world")
}
-
Loading