Skip to content

feat: new require-explicit-comment rule#128

Open
andrii-bodnar wants to merge 1 commit intomainfrom
feat/require-explicit-comment
Open

feat: new require-explicit-comment rule#128
andrii-bodnar wants to merge 1 commit intomainfrom
feat/require-explicit-comment

Conversation

@andrii-bodnar
Copy link
Copy Markdown
Contributor

Add require-explicit-comment rule to enforce translator comments across Lingui macro object calls and React macro components (Trans, Plural, Select, SelectOrdinal), while allowing context as an alternative.

This aligns with the goal of providing as much contextual information as possible, which results in better translations.

@andrii-bodnar andrii-bodnar linked an issue Apr 9, 2026 that may be closed by this pull request
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 98.11321% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.10%. Comparing base (e6f7e91) to head (32354cb).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/require-explicit-comment.ts 98.03% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #128   +/-   ##
=======================================
  Coverage   98.10%   98.10%           
=======================================
  Files          13       14    +1     
  Lines         632      685   +53     
  Branches      212      233   +21     
=======================================
+ Hits          620      672   +52     
- Misses         12       13    +1     

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

attr.name.name === propName,
)

const getObjectProp = (node: TSESTree.ObjectExpression, propName: string) =>
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.

Both require-explicit-comment and require-explicit-id define nearly identical prop-lookup logic inline. Consider extracting to src/helpers.ts

I have already done this in #131 could potentially be reused.

missingCommentCall:
"Macro function call requires an explicit 'comment' property when 'context' is absent",
noCommentInTaggedTemplate:
"Tagged template literal doesn't support 'comment'. Use {{ fn }}({ comment: '...', message: '...' }) or provide `context` instead",
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.

The tagged template handler always reports, even though the docs say "unless context is provided". Tagged templates genuinely can't carry comment, but they also can't carry context, so the error message suggesting "provide context instead" is misleading. Consider rewording:

"Tagged template literal doesn't support 'comment' or 'context'. Use {{ fn }}({ comment: '...', message: '...' }) instead."

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.

[feature request] require providing translation context

2 participants