fix(formatter): prevent line break when comment follows end of attributes, irrespective of bracketSameLine value #3534
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
There was a bug where when the
bracket same line
option was true and there was a comment after an attribute, that comment would be formatted as the value of the element.When the comment is //, putting the bracket on the same line would also comment out the closing
>
, so I thought that even if bracket same line is true, we shouldn't break the line when there's a comment after an attribute.I created a function called
has_last_attribute_comments
incrates/biome_js_formatter/src/jsx/tag/opening_element.rs
that returns a boolean indicating whether there's a comment after an attribute.I added a last_attribute_comments argument to
OpeningElementLayout::IndentAttributes
and passed has_last_attribute_comments to it.When both
force_bracket_same_line
andlast_attribute_has_comments
are true, we make it break the line.Test Plan
added test cases for when attributes have comments in
crates/biome_js_formatter/tests/specs/jsx/bracket_same_line/bracket_same_line.js
x.I confirmed that all tests in the jsx_module in
crates/biome_js_formatter/tests/spec_tests.rs
pass.close #3354