Skip to content

fix(no-single-variables-to-translate): count text inside ICU macro props - #157

Merged
andrii-bodnar merged 2 commits into
lingui:mainfrom
cpruijsen:fix/issue-104-9ad90098
Oct 12, 2026
Merged

andrii-bodnar merged 2 commits into
lingui:mainfrom
cpruijsen:fix/issue-104-9ad90098

Conversation

@cpruijsen

Copy link
Copy Markdown
Contributor

no-single-variables-to-translate now reads text in ICU choice props for <Plural>, <Select>, and <SelectOrdinal> inside <Trans>.

In src/rules/no-single-variables-to-translate.ts, choice props count if they contain non-blank strings, template literals with static text, or nested JSX with text. Variable-only choices and unrelated props still produce the existing diagnostic.

The issue's example now passes:

<Trans>
  <span style={{ color: 'red' }}>{websiteCount}</span>{' '}
  <Plural value={websiteCount} one="Website" other="Websites" />
</Trans>

The nine new valid cases, including the issue example, fail without the source change and pass with it.

Fixes #104.

<Plural>, <Select> and <SelectOrdinal> carry their translatable text in
choice props (one=, other=, male=, _0=, ...), not in JSX children, so
a <Trans> containing only an ICU macro was wrongly reported. Inspect
the message-carrying props of the three ICU macros and skip the
non-message props (value, offset, id, comment, ...), mirroring the
list used by no-unnamed-tag-placeholders.

Fixes lingui#104
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.45%. Comparing base (2594d5c) to head (5cb217a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #157      +/-   ##
==========================================
- Coverage   98.63%   98.45%   -0.19%     
==========================================
  Files          18       18              
  Lines         881      906      +25     
  Branches      303      319      +16     
==========================================
+ Hits          869      892      +23     
- Misses         12       14       +2     

☔ View full report in Codecov by Harness.
📢 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.

@andrii-bodnar

Copy link
Copy Markdown
Contributor

@cpruijsen thanks, the fix looks right. Codecov fails on two new lines: the ICU check inside hasIcuTextWithContent is dead since the caller already filters on ICU_MACROS, so it can go, and the !value branch has no test. An invalid case like <Trans><Plural value={count} one other={variable} /></Trans> covers it.

@cpruijsen

Copy link
Copy Markdown
Contributor Author

Done. I removed the redundant check and added that invalid case.

@andrii-bodnar andrii-bodnar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@cpruijsen thank you!

@andrii-bodnar
andrii-bodnar merged commit 3428861 into lingui:main Oct 12, 2026
3 of 4 checks passed
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.

no-single-variables-to-translate false positive

2 participants