Extract classes from interpolated expressions in Ruby#19730
Extract classes from interpolated expressions in Ruby#19730RobinMalfait merged 2 commits intomainfrom
Conversation
WalkthroughThe Ruby pre-processor was updated to improve comment handling by distinguishing between comment syntax and string interpolation. The change adds logic to skip hash characters that are followed by an opening brace, preventing interpolation expressions from being incorrectly treated as comments. Corresponding test cases were added to verify the behavior with interpolated expressions in HEREDOC blocks, ensuring literals are extracted correctly and interpolated content is not mistaken for comments. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/oxide/src/extractor/pre_processors/ruby.rs (1)
393-405: Good regression test coverage for the reported issue.The test correctly validates that
w-100inside heredoc interpolation is extracted. Consider adding an assertion for edge cases if you want additional confidence:🧪 Optional: Extended test coverage
#[test] fn test_interpolated_expressions() { let input = r#" def width_class(width = nil) <<~STYLE_CLASS #{width || 'w-100'} STYLE_CLASS end "#; Ruby::test_extract_contains(input, vec!["w-100"]); + + // Multiple interpolations in heredoc + let input = r#" + <<~HTML + #{a || 'flex'} #{b || 'grid'} + HTML + "#; + Ruby::test_extract_contains(input, vec!["flex", "grid"]); + + // Interpolation followed by actual comment + let input = r#" + x = "#{foo || 'p-4'}" # this is a comment with px-2 + "#; + Ruby::test_extract_contains(input, vec!["p-4"]); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/oxide/src/extractor/pre_processors/ruby.rs` around lines 393 - 405, Add additional edge-case assertions to the existing regression test test_interpolated_expressions so it covers more interpolation scenarios: update the test that calls Ruby::test_extract_contains to also assert behavior for nil/empty interpolation, nested interpolation, and alternative fallback values (e.g., when width is empty string or false) to ensure "w-100" is only extracted where expected; locate the test function test_interpolated_expressions and extend its input and expected vector(s) to include those edge cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@crates/oxide/src/extractor/pre_processors/ruby.rs`:
- Around line 393-405: Add additional edge-case assertions to the existing
regression test test_interpolated_expressions so it covers more interpolation
scenarios: update the test that calls Ruby::test_extract_contains to also assert
behavior for nil/empty interpolation, nested interpolation, and alternative
fallback values (e.g., when width is empty string or false) to ensure "w-100" is
only extracted where expected; locate the test function
test_interpolated_expressions and extend its input and expected vector(s) to
include those edge cases.
This PR ensures that interpolated expressions in Ruby syntax are correctly extracted.
The issue was that we ignore comments in Ruby syntax (which start with
#). We already made an exception for locals (<%# locals: … %>), but we also need to handle interpolated expressions (#{ … }) in the same way because they are not comments.Fixes: #19728
Test plan
Notice that the
w-100gets extracted now.