Skip to content

Keep the extracted text one line per source line - #1135

Merged
jdkato merged 2 commits into
vale-cli:v3from
Eljees:fix/1022-blank-comment-line
Aug 13, 2026
Merged

Keep the extracted text one line per source line#1135
jdkato merged 2 commits into
vale-cli:v3from
Eljees:fix/1022-blank-comment-line

Conversation

@Eljees

@Eljees Eljees commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #1022.

The reported file, on current v3:

$ vale --output=line whatever.proto
whatever.proto:5:4:spelling.english:Did you really mean 'Eror'?
whatever.proto:8:1:spelling.english:Did you really mean 'Eror'?   # source line 7, column 4

coalesce joins a run of line comments into one comment, and the run came out with more lines than the source it maps back to:

  • a blank line comment — // with nothing after it — contributed two newlines where every other line contributes one, so it ended its line twice;
  • the newline that terminates the line a run is attached to was added or skipped based on whether the run already started with one, rather than on whether that text already ended with one.

Once the extracted text and the source disagree about line counts, adjustAlerts maps 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:1 for 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 in lang.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.json shows 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, plus Source losing 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-dirs and fragments/code-to-markup, which are the cases that pinned the old Rust columns. go test ./... is green (units and all 169 e2e scenarios), as are gofmt and go vet.

fragments/blank-comment-line covers both shapes — protobuf with one blank line, Go with two — and fails on current v3 with exactly the offsets from the issue.

AI-assisted (LLM used for drafting); the runs above are mine.

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
@jdkato

jdkato commented Aug 10, 2026

Copy link
Copy Markdown
Member

Thanks — two small things.

attachRun does strings.TrimLeft(run, " "), but appendLine already trimmed every line of the run including the first, so that's dead.

appendLine gives you one line per call only when the input has at most one trailing newline. strings.TrimRight(line, "\n") + "\n" would make the invariant hold unconditionally — a line-scope comment whose content is "text\n\n" still passes the scope test in query.go, and it would slip through as written:

input output lines
"" "\n" 1
"text" "text\n" 1
"text\n" "text\n" 1
"text\n\n" "text\n\n" 2
Signed-off-by: Eljees <3.14hell@gmail.com>
@Eljees

Eljees commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Addressed both points in 3340f36: attachRun no longer trims a run that appendLine has already normalized, and appendLine now uses strings.TrimRight(line, "\n") + "\n". I added a focused table test including the "text\n\n" case. go test ./internal/lint/code passes.

@jdkato
jdkato merged commit c154ac2 into vale-cli:v3 Aug 13, 2026
7 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 21, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [errata-ai/vale](https://github.com/errata-ai/vale) | minor | `v3.17.1` → `v3.18.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>errata-ai/vale (errata-ai/vale)</summary>

### [`v3.18.0`](https://github.com/vale-cli/vale/releases/tag/v3.18.0)

[Compare Source](vale-cli/vale@v3.17.1...v3.18.0)

v3.18.0 is the largest expansion of Vale's format support since v3.0.0.

[MDX](https://docs.vale.sh/formats/mdx) is now parsed natively — `mdx2vast` is no longer required. This release also adds support for four new markup formats: [Typst](https://docs.vale.sh/formats/typst) (through the new [`typst2vast`](https://github.com/jdkato/typst2vast) program), [Quarto](https://docs.vale.sh/formats/quarto), [MyST](https://docs.vale.sh/formats/myst), and [QDoc](https://docs.vale.sh/formats/qdoc). R Markdown now works out of the box, and comment extraction now covers Lua, PHP, Haskell, R, Perl, and SCSS.

Beyond formats, there's a new `meta` [scope](https://docs.vale.sh/topics/scopes) for a document's machine-readable content, a `--plain-progress` flag, and per-package logging for `vale sync` in CI — plus a long list of fixes that make alert positions and scoping more accurate across every format.

> ✨ Sponsor Spotlight
>
> Special thanks to [Promptless](https://vale.sh/sponsors/promptless) — Vale's newest sponsor and the latest to receive a [Spotlight page](https://vale.sh/sponsors/promptless). Promptless suggests doc updates when your product changes; you review, edit, and ship.

#### Changelog

- [`6c382ec`](vale-cli/vale@6c382ecd) fix: stop element-scoped rules from matching sentence fragments ([#&#8203;1150](vale-cli/vale#1150))
- [`9b9594d`](vale-cli/vale@9b9594d0) fix: don't treat a word before a code span as inline markup ([#&#8203;1147](vale-cli/vale#1147))
- [`2b159ab`](vale-cli/vale@2b159ab6) fix: stop corrupting suggestions containing 'PIPE'
- [`390dda6`](vale-cli/vale@390dda6e) fix: compile glob patterns once at construction ([#&#8203;1145](vale-cli/vale#1145))
- [`fcf0740`](vale-cli/vale@fcf07409) fix(ls-metrics): prevent panic on empty directory ([#&#8203;1144](vale-cli/vale#1144))
- [`dd09d42`](vale-cli/vale@dd09d428) fix(core): resolve Lang and Transform in section order, not map order ([#&#8203;1143](vale-cli/vale#1143))
- [`85ee608`](vale-cli/vale@85ee6088) fix(dita): report dita's own error output instead of just the exit status ([#&#8203;1141](vale-cli/vale#1141))
- [`fd8c2e0`](vale-cli/vale@fd8c2e02) refactor: satisfy revive's empty-block
- [`2f65b83`](vale-cli/vale@2f65b836) fix: close display math on any line ending with `$$` ([#&#8203;1148](vale-cli/vale#1148))
- [`e587329`](vale-cli/vale@e5873290) fix(lint): treat an HTML comment as a text boundary outside inline elements ([#&#8203;1140](vale-cli/vale#1140))
- [`4691bd3`](vale-cli/vale@4691bd36) docs: add new spotlight
- [`37cb109`](vale-cli/vale@37cb109b) feat: add `--plain-progress`
- [`12fbbd7`](vale-cli/vale@12fbbd7f) feat: log each package when sync isn't writing to a terminal
- [`9a1a16c`](vale-cli/vale@9a1a16c3) fix: mark a QDoc image that has no alt text, and publish inline ones
- [`c154ac2`](vale-cli/vale@c154ac2a) Keep the extracted text one line per source line ([#&#8203;1135](vale-cli/vale#1135))
- [`8fe9804`](vale-cli/vale@8fe98044) refactor: CLI clean up and subcommand help
- [`ae6d749`](vale-cli/vale@ae6d7496) feat: add `vale test`
- [`e5a0286`](vale-cli/vale@e5a0286a) fix: read a shebang as a POSIX path
- [`eec2f59`](vale-cli/vale@eec2f59a) fix: read a .qdocinc as the include it is, and keep meta out of prose
- [`7618d04`](vale-cli/vale@7618d044) fix: only hand the Docutils source to a Python interpreter
- [`b596b0d`](vale-cli/vale@b596b0dc) fix: stop a string run's helper processes the way a file run does
- [`f3f3402`](vale-cli/vale@f3f34021) fix: keep `vale off` working when QDoc prose is escaped
- [`54efd3b`](vale-cli/vale@54efd3bb) fix: escape QDoc markup
- [`5666297`](vale-cli/vale@5666297b) fix: treat a snippet marker inside a QDoc comment as markup
- [`c2d1a55`](vale-cli/vale@c2d1a559) feat: add a meta scope for a document's machine-readable content
- [`33e4012`](vale-cli/vale@33e40124) fix: close QDoc's code blocks on the right command, and scope its divs
- [`5ae4867`](vale-cli/vale@5ae48670) fix: read only `/*!` as QDoc, and cover commands
- [`e60b5bc`](vale-cli/vale@e60b5bc3) fix: keep a rule's level in the section that set it
- [`c1e2fa0`](vale-cli/vale@c1e2fa01) fix: honor IgnoredScopes when a markup format is mapped onto source
- [`85c1343`](vale-cli/vale@85c13436) fix: place a match inside a block that inline markup rewrote
- [`b47ccb0`](vale-cli/vale@b47ccb06) fix: don't mask an autolink's URL twice
- [`65f5687`](vale-cli/vale@65f5687f) fix: skip `$…$` inline math
- [`b3bade4`](vale-cli/vale@b3bade4b) fix: lint a tight list item's own text as its own block
- [`4a6b7cf`](vale-cli/vale@4a6b7cfd) Don't lint a shebang as a comment ([#&#8203;1134](vale-cli/vale#1134))
- [`77179c0`](vale-cli/vale@77179c0a) fix: report spans against the file's actual bytes
- [`7f429e3`](vale-cli/vale@7f429e31) test: pin issue 1007's frontmatter and blockquote scenarios
- [`b049e35`](vale-cli/vale@b049e35f) feat: support the .scss extension
- [`b678b8d`](vale-cli/vale@b678b8d9) test: add QML case
- [`e82432d`](vale-cli/vale@e82432d7) feat: extract Lua, PHP, Haskell, R, and Perl comments with tree-sitter
- [`0e2f8bf`](vale-cli/vale@0e2f8bf3) eat: support QML sources via qml = qdoc
- [`cc710aa`](vale-cli/vale@cc710aa2) fix: treat only block comments as QDoc documentation
- [`bd1f33a`](vale-cli/vale@bd1f33a6) ci: install typst2vast, drop mdx2vast
- [`9708be6`](vale-cli/vale@9708be61) feat: support Typst
- [`15115bf`](vale-cli/vale@15115bfb) fix: place a rewritten block by its longest word, not its last
- [`5c91639`](vale-cli/vale@5c916393) fix: skip a repeated match's prior occurrences by count, not by masking
- [`db8c83c`](vale-cli/vale@db8c83cf) feat: support QDoc
- [`fca7b79`](vale-cli/vale@fca7b79b) feat: support Quarto
- [`286fc59`](vale-cli/vale@286fc59a) feat: parse MDX natively, dropping mdx2vast
- [`fedaf20`](vale-cli/vale@fedaf204) feat: support MyST
- [`eec788d`](vale-cli/vale@eec788d8) fix: read the character actually beside a match for inline code
- [`590278e`](vale-cli/vale@590278e5) feat: lint R Markdown out of the box
- [`4d8e228`](vale-cli/vale@4d8e2289) fix: strip tab indentation from block comments ([#&#8203;1131](vale-cli/vale#1131))
- [`02fb654`](vale-cli/vale@02fb6547) fix: switch on what every term of a chained scope needs
- [`f011cb0`](vale-cli/vale@f011cb02) fix: keep 'scope: paragraph' out of headings, tables, lists, and blockquotes

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yODguMCIsInVwZGF0ZWRJblZlciI6IjQzLjI4OC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6bWlub3IiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants