Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions crates/rome_js_formatter/src/ts/types/mapped_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ impl FormatNodeRule<TsMappedType> for FormatTsMappedType {

let property_name = property_name?;

// Check if the user introduced a new line inside the node.
let should_expand = node
.syntax()
.tokens()
// Skip the first token to avoid formatter instability. See #4165.
// This also makes sense since leading trivia of the first token
// are not part of the interior of the node.
.skip(1)
.flat_map(|token| {
token
.leading_trivia()
Expand All @@ -47,8 +52,6 @@ impl FormatNodeRule<TsMappedType> for FormatTsMappedType {
});

let format_inner = format_with(|f| {
write!(f, [soft_line_break_or_space()])?;

if let Some(readonly_modifier) = &readonly_modifier {
write!(f, [readonly_modifier.format(), space()])?;
}
Expand Down Expand Up @@ -81,8 +84,7 @@ impl FormatNodeRule<TsMappedType> for FormatTsMappedType {
f,
[
&l_curly_token.format(),
group(&indent(&format_inner)).should_expand(should_expand),
soft_line_break_or_space(),
group(&soft_space_or_block_indent(&format_inner)).should_expand(should_expand),
r_curly_token.format(),
]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type LongNameHereToCauseLineBreak_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ={ [K in "foo"]: string };
39 changes: 39 additions & 0 deletions crates/rome_js_formatter/tests/specs/ts/type/mapped_type.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
source: crates/rome_formatter_test/src/snapshot_builder.rs
assertion_line: 212
info: ts/type/mapped_type.ts
---

# Input

```ts
type LongNameHereToCauseLineBreak_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ={ [K in "foo"]: string };
```


=============================

# Outputs

## Output 1

-----
Indent style: Tab
Line width: 80
Quote style: Double Quotes
Quote properties: As needed
Trailing comma: All
Semicolons: Always
-----

```ts
type LongNameHereToCauseLineBreak_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =
{ [K in "foo"]: string };
```

# Lines exceeding max width of 80 characters
```
1: type LongNameHereToCauseLineBreak_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =
```