Conversation
`update_pre_commit_repo_versions` found the line to rewrite from strictyaml's `end_line` plus a hand-computed document offset. `end_line` counts logical nodes rather than physical lines, so it drifts by `lines - 1` past any multi-line flow sequence: the rewrite landed on the wrong line, the `.replace()` matched nothing, and the write aborted with "No changes to write, this should not happen". Take positions from a ruamel round-trip parse instead, whose `lc` marks come from the lexer and are absolute. That also covers a second case the offset never handled, a file starting with blank lines and no `---`, which the `pre-commit-config-start-empty-lines.yaml` fixture has reproduced unnoticed since it was added: `document_start_offset` returned 0 while `end_line` was still short by one. The offset is now unnecessary and is removed. Edits are collected and applied rightmost-first, because replacing one scalar shifts the columns of every scalar after it on that line, and each is checked to have landed so a positional miss fails loudly instead of writing a half-updated file. The round-trip parser comes from strictyaml's vendored copy, falling back to a standalone ruamel.yaml, so no new dependency and no reliance on strictyaml's private attributes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #79 +/- ##
==========================================
- Coverage 97.24% 96.82% -0.43%
==========================================
Files 12 12
Lines 727 725 -2
Branches 66 66
==========================================
- Hits 707 702 -5
- Misses 18 20 +2
- Partials 2 3 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 #64.
strictyaml's
end_linecounts YAML nodes, not source lines. A multi-line flowsequence is one node over several lines, so every line number after it is too
small and we edit the wrong line — silently, since the old text isn't there.
Fix: take line and column from ruamel's
lcmarks instead. They come from thelexer, so they are exact. strictyaml vendors ruamel, so no new dependency.
other's columns.
document_start_offsetand thedifflibchange count are gone.Notes: strictyaml still validates the schema, ruamel only gives
positions. We patch the text rather than re-dump, which would reformat the whole
file. Replacement starts at the column instead of
startswith, because ruamelpoints at the opening quote of a quoted scalar.