fix: rewrite directive scanner + handle JSX quotes#242
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #242 +/- ##
==========================================
+ Coverage 94.96% 95.06% +0.10%
==========================================
Files 10 9 -1
Lines 2603 2251 -352
==========================================
- Hits 2472 2140 -332
+ Misses 131 111 -20
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
timofei-iatsenko
left a comment
There was a problem hiding this comment.
The solution looks good to me. Could you also improve the coverage so it's closer to 100%?
660328d to
9bd5e31
Compare
Sure thing! Done now 🙏 |
There was a problem hiding this comment.
Pull request overview
This PR rewrites the Lingui comment-directive scanner to a simpler substring-based locator (intentionally allowing some false positives) and adds regression tests for JSX quote/backtick cases and JSX expression-container block-comment directives.
Changes:
- Replaced the prior source-comment scanner with a
lingui-substring locator + lightweight comment-opener detection and directive parsing. - Moved/expanded directive-scanner unit tests into a dedicated module.
- Added integration test cases + new snapshots covering JSX quotes/backticks and block-comment directives in JSX expression containers, plus an invalid-directive diagnostic snapshot.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/lingui_macro/src/comment_directive/mod.rs | Implements the new directive locator/parser and updates directive collection + span reporting. |
| crates/lingui_macro/src/comment_directive/tests.rs | Adds comprehensive unit tests for locating/parsing/collecting directives. |
| crates/lingui_macro/src/comment_directive/source_scanner.rs | Removes the old comment scanner implementation and its tests. |
| crates/lingui_macro/tests/lingui_directive.rs | Adds new integration test cases (JSX quotes/backticks, JSX block-comment directives, invalid directive diagnostic). |
| crates/lingui_macro/tests/snapshots/lingui_directive__jsx_trans_with_unclosed_quotes.snap | New snapshot for JSX quote/backtick regression scenario. |
| crates/lingui_macro/tests/snapshots/lingui_directive__jsx_trans_with_block_comment_set_in_expression_container.snap | New snapshot for JSX block-comment lingui-set inside {/* ... */}. |
| crates/lingui_macro/tests/snapshots/lingui_directive__jsx_trans_with_block_comment_reset_in_expression_container.snap | New snapshot for JSX block-comment lingui-reset inside {/* ... */}. |
| crates/lingui_macro/tests/snapshots/lingui_directive__jsx_block_comment_directive_with_trailing_code.snap | New snapshot ensuring trailing code after */ doesn’t break directive parsing. |
| crates/lingui_macro/tests/snapshots/lingui_directive__jsdoc_block_comment_directive.snap | New snapshot for JSDoc-style block comment directives. |
| crates/lingui_macro/tests/snapshots/lingui_directive__invalid_directive_reports_diagnostic.snap | New snapshot for invalid-directive diagnostic emission. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Alternative solution to #238 and #240 which sacrifices correctness for simplicity. The caveat is that
lingui-setandlingui-resetdirectives within strings will be seen as valid directives and thus be applied. @timofei-iatsenko suggested this as a compromise (source).Benchmark