Files
test-repo/changelog_unreleased/javascript/16163.md
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
996 B
Markdown
Raw Normal View History

#### [HIGHLIGHT]Implement `objectWrap` config option (#16163 by @pauldraper, @sosukesuzuki)
2025-01-15 00:44:45 -07:00
Prettier has historically done semi-manual formatting of multi-line JavaScript object literals.
2025-02-09 19:58:53 +09:00
Namely, an object is kept on multiple lines if there is a newline prior to the first property, even if it could fit on a single line. See [Multi-line objects](https://prettier.io/docs/rationale#multi-line-objects) for more details.
2025-01-15 00:44:45 -07:00
While this behavior continues to be the default, `--object-wrap=collapse` instead ignores whitespace when formatting object literals.
<!-- prettier-ignore -->
```js
// Input
const obj1 = {
name1: "value1", name2: "value2",
};
const obj2 = { name1: "value1",
name2: "value2",
};
// Prettier stable
const obj1 = {
name1: "value1",
name2: "value2",
};
const obj2 = { name1: "value1", name2: "value2" };
// Prettier main (with `--object-wrapping=collapse`)
const obj1 = { name1: "value1", name2: "value2" };
const obj2 = { name1: "value1", name2: "value2" };
```