Skip to content

[DIT-13503]: candidate ids hash the line number instead of the occurrence - #7

Merged
laurakoye merged 2 commits into
laura/dit-13480-capture-the-raw-literal-snapshot_text-in-resource-filefrom
laura/dit-13503-candidate-ids-hash-the-line-number-instead-of-the-occurrence
Aug 19, 2026
Merged

[DIT-13503]: candidate ids hash the line number instead of the occurrence#7
laurakoye merged 2 commits into
laura/dit-13480-capture-the-raw-literal-snapshot_text-in-resource-filefrom
laura/dit-13503-candidate-ids-hash-the-line-number-instead-of-the-occurrence

Conversation

@laurakoye

@laurakoye laurakoye commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Closes DIT-13503.

Candidate ids hashed (file, line, column, value). The project's identity rule is the opposite: a string is identified by its file, its text, and which repeat it is — never its line number.

Now: id = sha1(file:value:occurrence_index). line and column stay on location, just not in the hash. occurrence_index is already computed before the id loop, so nothing was reordered.

Fixes two things

Ids churned on unrelated edits. An import added above a string shifted its line and changed its id — a delete plus a create to anything keying by id. That's what occurrence_index (DIT-13463) exists to prevent.

Ids could collide. PO plural forms take their location from the same msgid_plural line, so two forms sharing text hashed identically and a consumer keyed by id dropped one:

msgstr[1] "%d rzeczy"   → (file, line, 1, "%d rzeczy")
msgstr[2] "%d rzeczy"   → (file, line, 1, "%d rzeczy")   ← same id

Tests

New src/candidate-id.test.ts — plural forms sharing text get distinct ids; an id survives lines inserted above it. No existing test hardcoded an id.

Breaking

  • makeCandidateId is exported: (file, line, column, value)(file, value, occurrenceIndex)
  • every candidate's id value changes

Safe now — nothing persists candidate ids yet, so this is a two-line change today and a migration later.

Also bumps package.json to 0.3.0. With #4, the release note needs three breaks: required snapshot_text, the makeCandidateId signature, and changed id values.

@laurakoye
laurakoye changed the base branch from main to laura/dit-13464-capture-the-raw-literal-snapshot_text-in-source-code August 18, 2026 21:12
@laurakoye
laurakoye changed the base branch from laura/dit-13464-capture-the-raw-literal-snapshot_text-in-source-code to laura/dit-13480-capture-the-raw-literal-snapshot_text-in-resource-file August 18, 2026 21:12
@laurakoye
laurakoye merged commit a0e3825 into laura/dit-13480-capture-the-raw-literal-snapshot_text-in-resource-file Aug 19, 2026
3 checks passed
@laurakoye
laurakoye deleted the laura/dit-13503-candidate-ids-hash-the-line-number-instead-of-the-occurrence branch August 19, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants