Skip to content

Fix HAML extraction with embedded Ruby #17846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 5, 2025
Merged

Fix HAML extraction with embedded Ruby #17846

merged 6 commits into from
May 5, 2025

Conversation

RobinMalfait
Copy link
Member

This PR fixes and improves the HAML extractor by ensuring that whenever we detect lines or blocks of Ruby code (-, = and ~) characters at the beginning of the line, we treat them as Ruby code.

Fixes: #17813

Test Plan

  1. Existing tests pass
  2. Changed 1 existing test which embedded Ruby syntax
  3. Added a dedicated test to ensure the HAML file in the linked issue is parsed correctly

Running this in the internal extractor tool you can see that the w-[12px], w-[16px], h-[12px], and h-[16px] are properly extracted.

Note: the mr-12px is also extracted, but not highlighted because this is not a valid Tailwind CSS class.

image

@RobinMalfait RobinMalfait requested a review from a team as a code owner May 2, 2025 11:26
@RobinMalfait RobinMalfait marked this pull request as draft May 2, 2025 11:31
Comment on lines 39 to 74
= succeed ',' do
= daisy_link("ViewComponent", "https://viewcomponent.org", target: "_blank")
= succeed ', and' do
= daisy_link "DaisyUI", "https://daisyui.com/", target: "_blank"
= daisy_link "TailwindCSS", "https://tailwindcss.com/", target: "_blank"
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: the reason the = characters are back is because we are not replacing them in the HAML extractor itself anymore. Instead the value after the = is passed to the Ruby extractor.

@RobinMalfait RobinMalfait marked this pull request as ready for review May 2, 2025 12:00
let actual = std::str::from_utf8(&processed).unwrap();
let expected = include_str!("./test-fixtures/haml/dst-17051.haml");

assert_eq!(actual, expected);
Copy link
Member

Choose a reason for hiding this comment

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

I find this a bit confusing to review. Looking at the snapshot alone I am really not sure if the right classes are extract. Should we run the extractor here and assert on the actual candidates being emitted?

Copy link
Member

Choose a reason for hiding this comment

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

I don't feel like this snapshot is super helpful for reviewing code. I know that some stuff changed but it's really unclear which of the symbols are now considered candidates and which ones aren't. I'm fine with keeping the snapshot if we can somehow highlight candidates. High level it feels like these stuff should not be changed in a PR like this, expect if we have something that we under-classified or over-classified for some reason. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Philipp here. What if we added some kind of separator and then listed all the extracted candidates at the bottom of the fixture?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep it's a bit hard to verify what's going on. We discussed this on Discord, but how about now?

Unfortunately for long lines GitHub doesn't always show it nicely, but now we're highlighting ^^^ under the extracted candidates

image

Copy link
Contributor

Choose a reason for hiding this comment

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

This is much better — I've got one request tho can you move the commits and split things so there's the original annotated version before the fix and then the updated annotated version after the fix?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah can do that! I typically push a "failing test" first (which is the output of what we expect).

But let me split things here so the diff is clear between commits.

Copy link
Member Author

Choose a reason for hiding this comment

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

@thecrypticace alright split things up, checkout the individual commits: https://github.com/tailwindlabs/tailwindcss/pull/17846/commits

Or the one commit that adjusts the annotations due to the fix: dd53aaa

@RobinMalfait RobinMalfait merged commit d38554d into main May 5, 2025
7 checks passed
@RobinMalfait RobinMalfait deleted the fix/issue-17813 branch May 5, 2025 14:26
@jeremybdk
Copy link

Thank you @RobinMalfait really appreciate it

RobinMalfait added a commit that referenced this pull request May 5, 2025
This PR fixes a Windows CI issue due to the recently merged #17846

There might be better ways to solve this, but essentially we want to
make sure we are always dealing with `\n` and not `\r\n`. This PR fixes
that by replacing all `\r\n` with `\n` in the tests.
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.

Some classes are not generated in Ruby/HAML since upgrading to Tailwind 4
4 participants