Skip to content

Extract classes from multi-line Ruby in Haml templates - #20635

Open
andrewfader wants to merge 7 commits into
tailwindlabs:mainfrom
andrewfader:haml-multiline-ruby
Open

andrewfader wants to merge 7 commits into
tailwindlabs:mainfrom
andrewfader:haml-multiline-ruby

Conversation

@andrewfader

Copy link
Copy Markdown

Summary

In Haml, a line of Ruby can continue onto the next lines as long as each line but the last ends with a comma:

= render("card",
  title: "Hello",
  class: "bg-[#f8f5ff] min-w-[140px]")

skip_indented_block only keeps the first line of that Ruby code. On the next line it stops at the first non-whitespace character (_ => break), so the continuation lines are processed as Haml instead of Ruby: the top-level [, ] and # get replaced with spaces and candidates like bg-[#f8f5ff] and min-w-[140px] are never extracted. The same file renamed to .erb or .rb extracts them fine.

This keeps consuming a line when the previous line ended with a comma, for = and - lines, so the whole expression goes through the Ruby pre-processor. Haml comments (-# and /) are left alone, so a comment ending in a comma doesn't swallow the line after it.

We found this in a Rails app, where classes passed to multi-line render and link_to calls were missing from the build.

One fixture changes: in dst-17051.haml a href: "https://…/loco_motion#locomotion-components" continuation line no longer yields locomotion-components (the fragment of the URL), because it's now handled as a Ruby string, like it would be in a .rb file.

Test plan

Added test_multi_line_ruby to haml.rs, covering = and - continuations, a nested block, and a comment ending in a comma. Without the change it fails with bg-[#f8f5ff], min-w-[140px], text-[#0b3fa8] and w-[240px] missing.

cargo test -p tailwindcss-oxide
rustfmt --check --edition 2021 crates/oxide/src/extractor/pre_processors/haml.rs

@andrewfader
andrewfader requested a review from a team as a code owner October 31, 2026 04:22
@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2a8649f9-878f-4178-bda3-0839f4e8d287
Commits

Reviewing files that changed from the base of the PR and between e860d1f and 09cbcb0.

Files selected for processing: 1
  • crates/oxide/src/extractor/pre_processors/haml.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Walkthrough

The Haml preprocessor now tracks Ruby expression continuation across lines ending with commas, including when trailing whitespace or blank lines follow. It excludes comment lines and Ruby comma character literals from continuation detection. A continued expression can include its final line at end-of-input. Tests cover multiline extraction, CRLF input, and class extraction. The change also updates expected fixture markers and adds an Unreleased changelog entry.

Merge Risk: Minimal · up to 09cbc

Dedented Ruby continuations are retained for class extraction. No actionable merge-blocking risk remains from the supplied evidence.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: extracting classes from multi-line Ruby expressions in Haml templates.
Description check Passed The description is directly related to the changeset. It explains the Haml continuation behavior, affected Ruby expressions, tests, and fixture update.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Reviews (6) · Last reviewed commit: "Keep dedented Ruby continuation lines in..." · Reviewed by Greptile

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Keep the final continuation line at EOF. · haml.rs:419

crates/oxide/src/extractor/pre_processors/haml.rs:419
Minor · Functional Correctness · Quick win

Keep the final continuation line at EOF.

If a multiline Ruby expression is the last content in a file without a trailing newline, the new continuation branch reaches EOF, but this rewind returns to the preceding newline. The final line is then processed as Haml, so classes such as bg-[#f8f5ff] are missed. Return the EOF position when the continuation reaches EOF.


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 845d2efc-626d-4eff-8b76-d3a5fee0d206
Commits

Reviewing files that changed from the base of the PR and between 8cc0551 and 55144c1.

Files selected for processing: 3
  • CHANGELOG.md
  • crates/oxide/src/extractor/pre_processors/haml.rs
  • crates/oxide/src/extractor/pre_processors/test-fixtures/haml/dst-17051.haml

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8557e17f-eeae-41e4-bfa9-10a2334fb6af
Commits

Reviewing files that changed from the base of the PR and between 55144c1 and 672b6fc.

Files selected for processing: 1
  • crates/oxide/src/extractor/pre_processors/haml.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@coderabbitai coderabbitai Bot left a comment

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.

Follow-up Comments

Outside diff Allow dedented Ruby continuation lines.

408-408: Minor · Functional Correctness · Quick win

Allow dedented Ruby continuation lines.

Haml joins continuation lines regardless of indentation. (raw.githubusercontent.com) For example:

%div
  %div
    = render "card",
  class: "bg-[#f8f5ff]"

This guard ends the block before the class line. Haml preprocessing then alters the brackets, so the utility is not extracted. Bypass the indentation check while a non-comment Ruby line continues.

Open the source location


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b717b6a2-eb0f-4f14-a3dc-bb7ac7bcbbaa
Commits

Reviewing files that changed from the base of the PR and between 846d136 and e860d1f.

Files selected for processing: 1
  • crates/oxide/src/extractor/pre_processors/haml.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

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.

1 participant