You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a file does not end in a newline, then every line added to the end of the file results in a diff to the previous final
line.
An example using `\n` to symbolize end of line characters:
https://github.com/arduino-libraries/Servo\nhttps://github.com/arduino-libraries/Stepper
When another line is added at the end:
https://github.com/arduino-libraries/Servo\nhttps://github.com/arduino-libraries/Stepper\nhttps://github.com/arduino-libraries/FooBar
you can see there is necessarily a diff on line 2 even though the editor did not touch that line.
For this reason, it is best practices to always retain a newline at the end of files.
In addition to it being common practice, the GitHub web editor automatically adds this newline. Between this and my
expectation that people would either add URLs to the top of the list or in alphabetical order, leaving the distant end of
the file alone, I was hoping that this would not be a common problem with the library submission system, but this is
simply not a realistic expectation.
What I hadn’t considered is that the person to suffer for this formatting is the next to add a URL to the end of the
file. Because of this “ghost diff”, the submission system sees this PR as a modification to an existing item on the list
rather than an addition.
I think this will be best handled by detecting and dealing with the problem at its introduction, rather than attempting
to make the system resilient to a missing final newline.
Copy file name to clipboardExpand all lines: main.go
+12-5Lines changed: 12 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,7 @@ type request struct {
74
74
Submissions []submissionType`json:"submissions"`// Data for submitted libraries.
75
75
IndexEntrystring`json:"indexEntry"`// Entry that will be made to the Library Manager index source file when the submission is accepted.
76
76
IndexerLogsURLsstring`json:"indexerLogsURLs"`// List of URLs where the logs from the Library Manager indexer for each submission are available for view.
77
+
Errorstring`json:"error"`// Error message.
77
78
}
78
79
79
80
// submissionType is the type of the data for each individual library submitted in the request.
// parseDiff parses the request diff and returns the request type, request error, `arduino-lint --library-manager` setting, and list of submission URLs.
// Check if the PR has removed the final newline from a file, which would cause a spurious diff for the next PR if merged.
186
+
// Unfortunately, the diff package does not have this capability (only to detect missing newline in the original file).
187
+
ifbytes.Contains(rawDiff, []byte("\\ No newline at end of file")) {
188
+
return"invalid", "Pull request removes newline from the end of a file.%0APlease add a blank line to the end of the file.", "", nil
189
+
}
190
+
184
191
diffs, err:=diff.ParseMultiFileDiff(rawDiff)
185
192
iferr!=nil {
186
193
panic(err)
187
194
}
188
195
189
196
if (len(diffs) !=1) || (diffs[0].OrigName[2:] !=listName) || (diffs[0].OrigName[2:] !=diffs[0].NewName[2:]) { // Git diffs have a a/ or b/ prefix on file names.
0 commit comments