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

fix(rome_js_formatter): Single-line comment below a JSX prop triggers… #3641

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

... the main reason this is safe because the Inline layout guarantees that neither the name, type arguments have any comments and arguments is obviously empty :)

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(),
denbezrukov marked this conversation as resolved.
Show resolved Hide resolved
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
33 changes: 33 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,36 @@ const breadcrumbItems = [
</Breadcrumb.Item>
),
].concat(extraBreadcrumbItems);

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

let b = (
<section>
<div>
aVeryLongCOntentThat
</div // comment
>
</section>
);


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>
);
69 changes: 69 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,39 @@ const breadcrumbItems = [
),
].concat(extraBreadcrumbItems);

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

let b = (
<section>
<div>
aVeryLongCOntentThat
</div // comment
>
</section>
);


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 +659,42 @@ const breadcrumbItems = [
</Breadcrumb.Item>,
].concat(extraBreadcrumbItems);

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

let b = (
<section>
<div>
aVeryLongCOntentThat
</div // comment
>
</section>
);

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