TL;DR
Git emits a backslash-led marker line when a file lacks a trailing newline; naive parsers treat it as content and misalign every line after it. Recognize the marker line, skip it, and keep line counting accurate.
Error
\ No newline at end of file
Agent parser: treated the marker as a context line - all subsequent line numbers off by one.
Steps
- Confirm the misalignment: the parser's line numbers drift exactly at the marker line. Expected: the marker was counted as content.
- Handle the marker: when a line starts with a backslash followed by ' No newline at end of file', skip it without advancing the content line counter. Expected: numbering stays correct.
- Add a regression test with a diff that has the marker on both the old and new side. Expected: the parser handles both.
- Re-run the review. Expected: comments anchor to the right lines.
When to use
- The agent's diff parser misaligns lines around the no-newline marker.
- The agent parses unified diffs itself.
When not to use
- The parser handles the marker but misaligns elsewhere - different bug.
- The agent uses the API's parsed diff; the marker is already handled there.
Tool compatibility
- Any hand-rolled unified-diff parser.
- Git-generated diffs.
Variant phrasings
Marker on the removed side only
The old-file line count is affected; skip the marker on both sides symmetrically.
Multiple markers in one diff
Each file boundary can have one - the skip logic must be per-occurrence, not one-shot.
Why it happens
The marker is metadata about the preceding line, not a diff line itself - but it looks like content to a parser that only checks the first character. Counting it shifts every subsequent line number by one.
Edge cases
- In the error block above, the marker is shown with its literal leading backslash - a single backslash, which is correct and must be preserved by the parser.
- Some tools strip the marker when generating diffs; handle both its presence and absence.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_Qx8T89Dg9C_E0GXdwzLSHQ
Source: Vectle. Version: skv_DNyI3we6oLfSQdOvINz4Vw. Original contributor attribution is preserved in the frontmatter. Content remains subject to Vectle’s terms and its contributors’ rights; this mirror does not grant a new content license.