Implement objectWrap config option (#16163)
Co-authored-by: Sosuke Suzuki <aosukeke@gmail.com>
This commit is contained in:
1 parent
bbb65180e0
commit
bef1d61a7a
26 files changed
+1089
-11
No files matched your search
+5
-3
@@ -29,9 +29,11 @@ It turns out that empty lines are very hard to automatically generate. The appro
|
||||
|
||||
### Multi-line objects
|
||||
|
||||
By default, Prettier’s printing algorithm prints expressions on a single line if they fit. Objects are used for a lot of different things in JavaScript, though, and sometimes it really helps readability if they stay multiline. See [object lists], [nested configs], [stylesheets] and [keyed methods], for example. We haven’t been able to find a good rule for all those cases, so Prettier instead keeps objects multiline if there’s a newline between the `{` and the first key in the original source code. A consequence of this is that long singleline objects are automatically expanded, but short multiline objects are never collapsed.
|
||||
By default, Prettier’s printing algorithm prints expressions on a single line if they fit. Objects are used for a lot of different things in JavaScript, though, and sometimes it really helps readability if they stay multiline. See [object lists], [nested configs], [stylesheets] and [keyed methods], for example. We haven’t been able to find a good rule for all those cases, so by default Prettier keeps objects multi-line if there’s a newline between the `{` and the first key in the original source code. Consequently, long single-line objects are automatically expanded, but short multi-line objects are never collapsed.
|
||||
|
||||
**Tip:** If you have a multiline object that you’d like to join up into a single line:
|
||||
You can disable this conditional behavior with the [`objectWrap`](options.md#object-wrap) option.
|
||||
|
||||
**Tip:** If you have a multi-line object that you’d like to join up into a single line:
|
||||
|
||||
```js
|
||||
const user = {
|
||||
@@ -55,7 +57,7 @@ const user = { name: "John Doe",
|
||||
const user = { name: "John Doe", age: 30 };
|
||||
```
|
||||
|
||||
And if you’d like to go multiline again, add in a newline after `{`:
|
||||
And if you’d like to go multi-line again, add in a newline after `{`:
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
|
||||
Reference in new issue
Block a user