Skip to content

Commit 28f0560

Browse files
gofmt: autofix missing newline at EOF (#3917)
1 parent 7cf30e7 commit 28f0560

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pkg/golinters/gofmt_common.go

+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ func (p *hunkChangesParser) parseDiffLines(h *diffpkg.Hunk) {
8080
ret = append(ret, dl)
8181
}
8282

83+
// if > 0, then the original file had a 'No newline at end of file' mark
84+
if h.OrigNoNewlineAt > 0 {
85+
dl := diffLine{
86+
originalNumber: currentOriginalLineNumber + 1,
87+
typ: diffLineAdded,
88+
data: "",
89+
}
90+
ret = append(ret, dl)
91+
}
92+
8393
p.lines = ret
8494
}
8595

test/testdata/fix/in/gofmt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ package p
77
return 1
88
}
99
return 2
10-
}
10+
}

0 commit comments

Comments
 (0)