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 debff30
Showing
18 changed files
with
268 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,32 @@ | ||
#### Implement multilineObject config option (#16163 by @pauldraper) | ||
|
||
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. | ||
|
||
While this behavior continues to be the default, `--multiline-object=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 | ||
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.