Skip to content

fix(po-format): remove duplicated references when lineNumbers is false#2509

Merged
andrii-bodnar merged 1 commit intolingui:nextfrom
itsyoboieltr:fix/po-formatter-remove-duplicated-lines
Apr 14, 2026
Merged

fix(po-format): remove duplicated references when lineNumbers is false#2509
andrii-bodnar merged 1 commit intolingui:nextfrom
itsyoboieltr:fix/po-formatter-remove-duplicated-lines

Conversation

@itsyoboieltr
Copy link
Copy Markdown

Description

When lineNumbers: false is used, extracted PO catalogs currently keep duplicate #: reference lines if the same message appears multiple times in the same file. That creates unnecessary diff noise in source control even though the line numbers have already been intentionally removed.

This PR reduces that churn by deduplicating file-only references while preserving their original order.

Changes:

  • deduplicate references in @lingui/format-po when lineNumbers: false
  • deduplicate references in @lingui/format-po-gettext for the mergePlurals: true path, where merged plural entries could reintroduce duplicate file-only references
  • add regression tests for both cases

This keeps the existing behavior unchanged when line numbers are enabled, and only removes repeated file references once multiple locations have collapsed to the same path.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Examples update

Fixes #2405

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 11, 2026

@itsyoboieltr is attempting to deploy a commit to the Crowdin Team on Vercel.

A member of the Team first needs to authorize it.

@timofei-iatsenko
Copy link
Copy Markdown
Collaborator

@itsyoboieltr hey, all current development happened in the next branch, could you change the basse of your PR to that?

mergedItem.references =
options.lineNumbers === false
? [...new Set(duplicateItems.flatMap((item) => item.references))]
: duplicateItems.flatMap((item) => item.references)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid the branching here and just leave the [...new Set(duplicateItems.flatMap((item) => item.references))] the same way as in the po formatter.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.01%. Comparing base (dd43fb0) to head (b4e5bc2).
⚠️ Report is 334 commits behind head on next.

Additional details and impacted files
@@             Coverage Diff             @@
##             next    #2509       +/-   ##
===========================================
+ Coverage   76.66%   89.01%   +12.35%     
===========================================
  Files          81      118       +37     
  Lines        2083     3315     +1232     
  Branches      532      977      +445     
===========================================
+ Hits         1597     2951     +1354     
+ Misses        375      329       -46     
+ Partials      111       35       -76     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@itsyoboieltr itsyoboieltr changed the base branch from main to next April 13, 2026 21:13
@itsyoboieltr itsyoboieltr force-pushed the fix/po-formatter-remove-duplicated-lines branch from 270a0c1 to b4e5bc2 Compare April 13, 2026 21:23
@itsyoboieltr
Copy link
Copy Markdown
Author

@timofei-iatsenko I reset the branch onto next, reapplied the fix there, and force-pushed. The PR should now be clean against next.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
js-lingui Ready Ready Preview Apr 14, 2026 8:06am

Request Review

@andrii-bodnar andrii-bodnar merged commit 5339152 into lingui:next Apr 14, 2026
11 checks passed
@itsyoboieltr itsyoboieltr deleted the fix/po-formatter-remove-duplicated-lines branch April 14, 2026 14:24
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.

Reduce PO catalog comments changes for cleaner source control

3 participants