Keep the extracted text one line per source line - #1135
Open
Eljees wants to merge 1 commit into
Open
Conversation
A run of line comments was joined with two newlines for a blank one and a terminator that was decided by looking at the run instead of the text it was being attached to. The extracted text and the source it maps back to then had different numbers of lines, so every alert below a blank comment line was reported a line too far down, with its column collapsed to 1 because the source line it was measured against was past the end. The two errors cancelled for a comment whose node content carries its own newline -- Rust's `///` -- which is why columns there looked right while the text was already a line out. Lining the two up exposes that, so the space after the delimiter is now trimmed from every joined line rather than only the ones that still needed a newline; it is counted once, in the padding. Fixes vale-cli#1022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1022.
The reported file, on current
v3:coalescejoins a run of line comments into one comment, and the run came out with more lines than the source it maps back to://with nothing after it — contributed two newlines where every other line contributes one, so it ended its line twice;Once the extracted text and the source disagree about line counts,
adjustAlertsmaps an alert to the wrong source line. Hence the line being one too far down, and the column collapsing to 1: the source line it was measured against was past the end, so its padding was zero.It isn't protobuf-specific — the same file shape in Go reports
7:1for a comment on line 6.The part that isn't obvious
Lining the two up on its own broke Rust.
///and//!node content already carries its trailing newline, so the old code skipped the branch that trimmed the space after the delimiter, and that space stayed on every joined line. It was then counted twice — once in the alert's own column, once inlang.Padding— and the two errors cancelled, which is why Rust columns looked right while the text was already a line out.So the trim is now unconditional, and the space is counted once.
testdata/comments/out/1.jsonshows what that means:" # Arguments"becomes"# Arguments", matching what the author actually wrote after the delimiter.Checked-in expectations that move
Three golden files change, and every change is one spurious blank line or one leading space disappearing:
out/0.json,out/5.json— a blank comment line produced two blank lines in the extracted text; now one.out/1.json— the same, plusSourcelosing the blank line it had gained after the first line, plus the leading spaces above.No line-count expectation in the e2e suite changes: the suite is green as it stands, including
lint/rust,cli/two-dirsandfragments/code-to-markup, which are the cases that pinned the old Rust columns.go test ./...is green (units and all 169 e2e scenarios), as aregofmtandgo vet.fragments/blank-comment-linecovers both shapes — protobuf with one blank line, Go with two — and fails on currentv3with exactly the offsets from the issue.AI-assisted (LLM used for drafting); the runs above are mine.