Skip to content

fix: rewrite directive scanner + handle JSX quotes#242

Merged
timofei-iatsenko merged 5 commits into
lingui:mainfrom
mogelbrod:medium-directive-scanner
Jun 25, 2026
Merged

fix: rewrite directive scanner + handle JSX quotes#242
timofei-iatsenko merged 5 commits into
lingui:mainfrom
mogelbrod:medium-directive-scanner

Conversation

@mogelbrod

@mogelbrod mogelbrod commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Alternative solution to #238 and #240 which sacrifices correctness for simplicity. The caveat is that lingui-set and lingui-reset directives within strings will be seen as valid directives and thus be applied. @timofei-iatsenko suggested this as a compromise (source).

Benchmark

implementation median trim-mean min vs main
main (source_scanner) 179.7 ms 180.9 170.2
this branch 180.3 ms 182.4 173.0 +0.4%
regex 200.8 ms 203.6 194.0 +11.8%

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.06%. Comparing base (bd2d361) to head (9bb6680).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests 95.06% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
crates/lingui_macro/src/comment_directive/mod.rs 100.00% <100.00%> (+6.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timofei-iatsenko timofei-iatsenko left a comment

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.

The solution looks good to me. Could you also improve the coverage so it's closer to 100%?

Comment thread crates/lingui_macro/src/comment_directive/mod.rs Outdated
@mogelbrod mogelbrod force-pushed the medium-directive-scanner branch from 660328d to 9bd5e31 Compare June 23, 2026 07:46
@mogelbrod

Copy link
Copy Markdown
Contributor Author

The solution looks good to me. Could you also improve the coverage so it's closer to 100%?

Sure thing! Done now 🙏

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread crates/lingui_macro/src/comment_directive/mod.rs
@timofei-iatsenko timofei-iatsenko merged commit 4a68dd1 into lingui:main Jun 25, 2026
2 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.

3 participants