Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement multilineObject config option
Fixes #2068
- Loading branch information
1 parent
d970dee
commit 7c3754c
Showing
18 changed files
with
269 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#### Implement multilineObject config option (#16163 by @pauldraper) | ||
|
||
Prettier has historically permitted semi-manual formatting of multi-line JavaScript object literals. | ||
|
||
Namely, it keeps objects on multiple lines if there is a newline prior to the first property, even if it could fit the object on a single line. | ||
|
||
Using `--multiline-object=collapse` causes Prettier to instead format object literals independent of whitespace. | ||
|
||
<!-- 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 | ||
const obj1 = { name1: "value1", name2: "value2" }; | ||
|
||
const obj2 = { name1: "value1", name2: "value2" }; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
tests/format/js/object-multiline/__snapshots__/jsfmt.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`multiline.js - {"multilineObject":"collapse"} format 1`] = ` | ||
====================================options===================================== | ||
multilineObject: "collapse" | ||
parsers: ["babel", "flow"] | ||
printWidth: 80 | ||
| printWidth | ||
=====================================input====================================== | ||
const a = { | ||
name1: 'value1', | ||
name2: 'value2', | ||
}; | ||
const b = { name1: 'value1', | ||
name2: 'value2', | ||
}; | ||
const c = { | ||
name1: 'value1', name2: 'value2', | ||
}; | ||
const d = { | ||
name1: 'value1', name2: 'value2', }; | ||
const e = { name1: 'value1', name2: 'value2', }; | ||
=====================================output===================================== | ||
const a = { name1: "value1", name2: "value2" }; | ||
const b = { name1: "value1", name2: "value2" }; | ||
const c = { name1: "value1", name2: "value2" }; | ||
const d = { name1: "value1", name2: "value2" }; | ||
const e = { name1: "value1", name2: "value2" }; | ||
================================================================================ | ||
`; | ||
|
||
exports[`multiline.js format 1`] = ` | ||
====================================options===================================== | ||
parsers: ["babel", "flow", "typescript"] | ||
printWidth: 80 | ||
| printWidth | ||
=====================================input====================================== | ||
const a = { | ||
name1: 'value1', | ||
name2: 'value2', | ||
}; | ||
const b = { name1: 'value1', | ||
name2: 'value2', | ||
}; | ||
const c = { | ||
name1: 'value1', name2: 'value2', | ||
}; | ||
const d = { | ||
name1: 'value1', name2: 'value2', }; | ||
const e = { name1: 'value1', name2: 'value2', }; | ||
=====================================output===================================== | ||
const a = { | ||
name1: "value1", | ||
name2: "value2", | ||
}; | ||
const b = { name1: "value1", name2: "value2" }; | ||
const c = { | ||
name1: "value1", | ||
name2: "value2", | ||
}; | ||
const d = { | ||
name1: "value1", | ||
name2: "value2", | ||
}; | ||
const e = { name1: "value1", name2: "value2" }; | ||
================================================================================ | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
runFormatTest(import.meta, ["babel", "flow", "typescript"]); | ||
runFormatTest(import.meta, ["babel", "flow"], { multilineObject: "collapse" }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const a = { | ||
name1: 'value1', | ||
name2: 'value2', | ||
}; | ||
|
||
const b = { name1: 'value1', | ||
name2: 'value2', | ||
}; | ||
|
||
const c = { | ||
name1: 'value1', name2: 'value2', | ||
}; | ||
|
||
const d = { | ||
name1: 'value1', name2: 'value2', }; | ||
|
||
const e = { name1: 'value1', name2: 'value2', }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.