Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
fix(rome_js_formatter): Single-line comment below a JSX prop triggers…
Browse files Browse the repository at this point in the history
… different formatting #3598
  • Loading branch information
denbezrukov committed Nov 10, 2022
1 parent 3b88794 commit 5a1618a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 12 deletions.
1 change: 0 additions & 1 deletion crates/rome_js_formatter/src/jsx/tag/closing_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ impl FormatNodeRule<JsxClosingElement> for FormatJsxClosingElement {
l_angle_token.format(),
slash_token.format(),
name.format(),
line_suffix_boundary(),
r_angle_token.format(),
]
]
Expand Down
5 changes: 0 additions & 5 deletions crates/rome_js_formatter/src/jsx/tag/opening_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ impl Format<JsFormatContext> for JsxAnyOpeningElement {
l_angle_token.format(),
name.format(),
type_arguments.format(),
line_suffix_boundary(),
space(),
format_close
]
Expand All @@ -63,10 +62,8 @@ impl Format<JsFormatContext> for JsxAnyOpeningElement {
l_angle_token.format(),
name.format(),
type_arguments.format(),
line_suffix_boundary(),
space(),
attributes.format(),
(!attributes.is_empty()).then_some(line_suffix_boundary()),
attribute_spacing,
format_close
]
Expand All @@ -80,9 +77,7 @@ impl Format<JsFormatContext> for JsxAnyOpeningElement {
l_angle_token.format(),
name.format(),
type_arguments.format(),
line_suffix_boundary(),
soft_line_indent_or_space(&attributes.format()),
(!attributes.is_empty()).then_some(line_suffix_boundary()),
]
)?;

Expand Down
9 changes: 3 additions & 6 deletions crates/rome_js_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,9 @@ function() {
// use this test check if your snippet prints as you wish, without using a snapshot
fn quick_test() {
let src = r#"
const a = [
longlonglonglongItem1longlonglonglongItem1,
longlonglonglongItem1longlonglonglongItem2,
longlonglonglongItem1longlonglonglongItem3,
];
<Test
// comment
/>
"#;
let syntax = SourceType::tsx();
let tree = parse(src, FileId::zero(), syntax);
Expand Down
23 changes: 23 additions & 0 deletions crates/rome_js_formatter/tests/specs/jsx/element.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,26 @@ const breadcrumbItems = [
</Breadcrumb.Item>
),
].concat(extraBreadcrumbItems);

function Component() {
return (
<Test
prop={value}
// comment
/>
);
}

let a = (
</*comment3*/Test
// comment before attribute
/*comment1*/prop/*comment2*/=/*comment3*/{/*comment4*/value /*comment5*/}/*comment6*/
// comment after attribute
>
<Test
// comment before attribute
/*comment1*/prop/*comment2*/=/*comment3*/{/*comment4*/value /*comment5*/}/*comment6*/
// comment after attribute
/>
</Test>
);
50 changes: 50 additions & 0 deletions crates/rome_js_formatter/tests/specs/jsx/element.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,29 @@ const breadcrumbItems = [
),
].concat(extraBreadcrumbItems);
function Component() {
return (
<Test
prop={value}
// comment
/>
);
}
let a = (
</*comment3*/Test
// comment before attribute
/*comment1*/prop/*comment2*/=/*comment3*/{/*comment4*/value /*comment5*/}/*comment6*/
// comment after attribute
>
<Test
// comment before attribute
/*comment1*/prop/*comment2*/=/*comment3*/{/*comment4*/value /*comment5*/}/*comment6*/
// comment after attribute
/>
</Test>
);
```


Expand Down Expand Up @@ -626,6 +649,33 @@ const breadcrumbItems = [
</Breadcrumb.Item>,
].concat(extraBreadcrumbItems);
function Component() {
return (
<Test
prop={value}
// comment
/>
);
}
let a = (
</*comment3*/ Test
// comment before attribute
/*comment1*/ prop /*comment2*/=/*comment3*/ {
/*comment4*/ value /*comment5*/
} /*comment6*/
// comment after attribute
>
<Test
// comment before attribute
/*comment1*/ prop /*comment2*/=/*comment3*/ {
/*comment4*/ value /*comment5*/
} /*comment6*/
// comment after attribute
/>
</Test>
);
## Lines exceeding width of 80 characters
Expand Down

0 comments on commit 5a1618a

Please sign in to comment.