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

996 B

[HIGHLIGHT]Implement objectWrap config option (#16163 by @pauldraper, @sosukesuzuki)

Prettier has historically done semi-manual formatting of multi-line JavaScript object literals.

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 for more details.

While this behavior continues to be the default, --object-wrap=collapse instead ignores whitespace when formatting object literals.

// 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" };