Skip to content

Extract classes from interpolated expressions in Ruby#19730

Merged
RobinMalfait merged 2 commits intomainfrom
fix/issue-19728
Feb 26, 2026
Merged

Extract classes from interpolated expressions in Ruby#19730
RobinMalfait merged 2 commits intomainfrom
fix/issue-19728

Conversation

@RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Feb 26, 2026

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

  1. Existing tests pass
  2. Added a regression test for this scenario
  3. Tested using the extractor on the given code snippet:
image

Notice that the w-100 gets extracted now.

@RobinMalfait RobinMalfait requested a review from a team as a code owner February 26, 2026 11:17
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 2026

Walkthrough

The 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)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: enabling extraction of classes from interpolated expressions in Ruby code.
Description check ✅ Passed The description clearly explains the problem, solution, and provides a test plan with visual evidence of the fix working correctly.
Linked Issues check ✅ Passed The PR directly addresses issue #19728 by fixing the Ruby pre-processor to handle interpolation syntax #{...} correctly, enabling extraction of class names from heredoc interpolations.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing Ruby interpolation handling in the pre-processor with relevant test coverage, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 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-100 inside 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.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ded4a2 and e742f33.

📒 Files selected for processing (1)
  • crates/oxide/src/extractor/pre_processors/ruby.rs

@RobinMalfait RobinMalfait merged commit bf2e2fe into main Feb 26, 2026
9 checks passed
@RobinMalfait RobinMalfait deleted the fix/issue-19728 branch February 26, 2026 11:23
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.

Ruby heredoc interpolation (#{...}): class names not detected by scanner

1 participant