Skip to content

feat(no-expression-in-message): recommend named placeholders in the error message - #156

Open
andrii-bodnar wants to merge 2 commits into
mainfrom
feat/no-expression-in-message-recommend-ph
Open

andrii-bodnar wants to merge 2 commits into
mainfrom
feat/no-expression-in-message-recommend-ph

Conversation

@andrii-bodnar

@andrii-bodnar andrii-bodnar commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

The report now names the offending expression and shows the exact ph({ label: expression }) wrapper to use, with the label derived from the code (user.name -> name, getUserName() -> getUserName, otherwise value).

New allowIdentifiers option (default true). With false, plain identifiers such as t`Hello ${name}` and <Trans>Hello {name}</Trans> are reported too, with a message that suggests ph({ name }), so that renaming a variable can never change a message. Explicit labels, the { name } object shorthand, and nested plural/select/selectOrdinal macros remain valid. The shorthand is supported by both the Babel macro and the SWC plugin.

The rule docs are rewritten to lead with ph as the fix, explain with a concrete example why explicit labels are preferred over names inherited from variables, and document the new option.

Refs lingui/js-lingui#2457

…rror message

The report now names the offending expression and shows the exact
`ph({ label: expression })` wrapper to use, with the label derived from
the code (`user.name` -> `name`, `getUserName()` -> `getUserName`,
otherwise `value`). The rule docs are rewritten to lead with `ph` as the
fix and to explain why explicit labels are preferred over names inherited
from variables.

Refs lingui/js-lingui#2457

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #156      +/-   ##
==========================================
+ Coverage   98.63%   98.66%   +0.02%     
==========================================
  Files          18       18              
  Lines         881      900      +19     
  Branches      303      308       +5     
==========================================
+ Hits          869      888      +19     
  Misses         12       12              

☔ 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.

Comment thread docs/rules/no-expression-in-message.md Outdated
Comment thread docs/rules/no-expression-in-message.md Outdated
…ify the docs

With `allowIdentifiers: false` the rule also reports plain identifiers
such as `${name}` and suggests `ph({ name })`, so that renaming a
variable can never change a message. The default stays `true`.

The docs now explain the rename problem with a concrete example.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@andrii-bodnar

Copy link
Copy Markdown
Contributor Author

@timofei-iatsenko is there anything else we can do to move this PR forward?

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