Skip to content
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

feat(format/html): implement bracketSameLine #4968

Merged
merged 1 commit into from
Feb 2, 2025
Merged

Conversation

dyc3
Copy link
Contributor

@dyc3 dyc3 commented Jan 24, 2025

Summary

This PR implements functionality for the bracketSameLine option, with a particular focus on matching prettier's emitted IR.

closes #4024

Test Plan

added tests

@dyc3 dyc3 marked this pull request as draft January 24, 2025 17:44
@github-actions github-actions bot added A-Formatter Area: formatter L-HTML Language: HTML labels Jan 24, 2025
write!(f, [soft_line_break_or_space()])?;
}

// TODO: These tokens (the `/>`) are not yet borrowed by sibling elements for whitespace sensitivity.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

whitespace sensitivity is not yet implemented for self closing elements

Copy link

codspeed-hq bot commented Jan 24, 2025

CodSpeed Performance Report

Merging #4968 will not alter performance

Comparing html-bracket-same-line (946182e) with next (703bff0)

Summary

✅ 94 untouched benchmarks

@dyc3 dyc3 force-pushed the html-bracket-same-line branch 2 times, most recently from e583d33 to 8afc1a8 Compare January 27, 2025 14:13
@dyc3 dyc3 marked this pull request as ready for review January 27, 2025 14:40
@dyc3 dyc3 force-pushed the html-bracket-same-line branch from 8afc1a8 to b27188e Compare January 27, 2025 15:01
@dyc3

This comment was marked as resolved.

@dyc3 dyc3 marked this pull request as draft January 27, 2025 15:55
@dyc3 dyc3 force-pushed the html-bracket-same-line branch from b27188e to 82f9a47 Compare January 29, 2025 12:44
@dyc3 dyc3 marked this pull request as ready for review January 29, 2025 12:44
@dyc3 dyc3 force-pushed the html-bracket-same-line branch 2 times, most recently from 3f862a2 to 3865b5f Compare February 1, 2025 15:07
@dyc3 dyc3 requested review from a team February 1, 2025 15:30
@dyc3

This comment was marked as resolved.

@dyc3 dyc3 force-pushed the html-bracket-same-line branch from 3865b5f to 94a7762 Compare February 2, 2025 01:37
style="color: red"
data-foo="bar"
data-bar="foo"
/>
Copy link
Member

Choose a reason for hiding this comment

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

If we need to follow the spec, self closing elements don't exist in HTML. Perhaps we can add another case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Self closing elements technically do exist, they are called "void elements" in the spec, and they are defined as elements that have no children, and therefore do not have a closing tag. Syntactically, they do not need the / and it is ignored by browsers. Prettier always adds the / for void elements.

Copy link
Member

@ematipico ematipico Feb 2, 2025

Choose a reason for hiding this comment

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

That's something we might want to discuss later, but I was thinking of diverging from Prettier and not adding the slash at the end. Maybe we could consider an option in case users want to add them

Comment on lines 36 to 42
// TODO: These tokens (the `/>`) are not yet borrowed by sibling elements for whitespace sensitivity.
if slash_token.is_some() {
write!(f, [slash_token.format()])?;
} else {
write!(f, [text("/")])?;
Copy link
Member

Choose a reason for hiding this comment

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

NIT: A couple things:

  • from the Todo, it's not clear what needs to be done
  • if possible, I would avoid adding a slash if users didn't add one. Maybe we can iterate this in another issue/pr

@dyc3 dyc3 force-pushed the html-bracket-same-line branch from 94a7762 to 946182e Compare February 2, 2025 12:52
@dyc3 dyc3 merged commit 93dda40 into next Feb 2, 2025
12 checks passed
@dyc3 dyc3 deleted the html-bracket-same-line branch February 2, 2025 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter L-HTML Language: HTML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants