Skip to content

Commit

Permalink
fix(js_formatter): break long destructuring binding pattern (#2185)
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-yu authored Mar 25, 2024
1 parent 3414bd8 commit 35ba975
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### Formatter

#### Bug fixes

- Fix [#2172](https://github.com/biomejs/biome/issues/2172) by breaking long object destructuring patterns. Contributed by @ah-yu

### JavaScript APIs

### Linter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;

use biome_formatter::write;
use biome_formatter::{format_args, write};
use biome_js_syntax::JsObjectBindingPatternProperty;
use biome_js_syntax::JsObjectBindingPatternPropertyFields;

Expand All @@ -20,14 +20,17 @@ impl FormatNodeRule<JsObjectBindingPatternProperty> for FormatJsObjectBindingPat
init,
} = node.as_fields();

let group_id = f.group_id("assignment");

write![
f,
[
[group(&format_args![
member.format(),
colon_token.format(),
space(),
pattern.format(),
]
group(&indent(&soft_line_break_or_space())).with_group_id(Some(group_id)),
line_suffix_boundary(),
indent_if_group_breaks(&pattern.format(), group_id)
])]
]?;

if let Some(init) = init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ let {a}=b
let {d,b:c}=d
let {x,y=c,z:pp=f,...g}=h
let {aaaaaaaaaaaaaaaaaaaa,bbbbbbbbbbbbbbbbbbbb=cccccccccccccccccccc,dddddddddddddddddddd:eeeeeeeeeeeeeeeeeeee=ffffffffffffffffffff,...gggggggggggggggggggg}=h
let {looooooooooooooooooooooooooooooooooooooooooong: loooooooooooooooooooooooooooooooooooooooooong }=h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: js/module/binding/object_binding.js
---

# Input

```js
let {a}=b
let {d,b:c}=d
let {x,y=c,z:pp=f,...g}=h
let {aaaaaaaaaaaaaaaaaaaa,bbbbbbbbbbbbbbbbbbbb=cccccccccccccccccccc,dddddddddddddddddddd:eeeeeeeeeeeeeeeeeeee=ffffffffffffffffffff,...gggggggggggggggggggg}=h

let {looooooooooooooooooooooooooooooooooooooooooong: loooooooooooooooooooooooooooooooooooooooooong }=h
```


Expand Down Expand Up @@ -46,6 +45,10 @@ let {
dddddddddddddddddddd: eeeeeeeeeeeeeeeeeeee = ffffffffffffffffffff,
...gggggggggggggggggggg
} = h;
let {
looooooooooooooooooooooooooooooooooooooooooong:
loooooooooooooooooooooooooooooooooooooooooong,
} = h;
```

## Output 2
Expand Down Expand Up @@ -76,6 +79,8 @@ let {
dddddddddddddddddddd: eeeeeeeeeeeeeeeeeeee = ffffffffffffffffffff,
...gggggggggggggggggggg
} = h;
let {
looooooooooooooooooooooooooooooooooooooooooong:
loooooooooooooooooooooooooooooooooooooooooong,
} = h;
```


4 changes: 4 additions & 0 deletions website/src/content/docs/internals/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### Formatter

#### Bug fixes

- Fix [#2172](https://github.com/biomejs/biome/issues/2172) by breaking long object destructuring patterns. Contributed by @ah-yu

### JavaScript APIs

### Linter
Expand Down

0 comments on commit 35ba975

Please sign in to comment.