-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent wrapping object properties with short keys (#10335)
* Prevent wrapping object properties with short keys * Update src/language-js/print/assignment.js Co-authored-by: Sosuke Suzuki <aosukeke@gmail.com> * Use getStringWidth instead of .length Co-authored-by: Sosuke Suzuki <aosukeke@gmail.com>
- Loading branch information
1 parent
2f384ab
commit 5f8fee4
Showing
8 changed files
with
140 additions
and
27 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,22 @@ | ||
#### Prevent wrapping object properties with short keys (#10335 by @thorn0) | ||
|
||
Line breaks after short property names in object literals often look unnatural. Even when such a line break yields a line length benefit of 1 or 2 characters, it rarely looks justified. Prettier main avoids line breaks after property names shorter than `tabWidth + 3`. The "+3" part has been chosen rather arbitrarily. It may be revised upward in future versions, provided there is a really good rationale. | ||
|
||
<!-- prettier-ignore --> | ||
```js | ||
// Input | ||
const importantLink = { | ||
url: "https://prettier.io/docs/en/rationale.html#what-prettier-is-concerned-about" | ||
}; | ||
|
||
// Prettier stable | ||
const importantLink = { | ||
url: | ||
"https://prettier.io/docs/en/rationale.html#what-prettier-is-concerned-about" | ||
}; | ||
|
||
// Prettier main | ||
const importantLink = { | ||
url: "https://prettier.io/docs/en/rationale.html#what-prettier-is-concerned-about" | ||
}; | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3558,18 +3558,16 @@ printWidth: 1 | |
<p> | ||
{{ | ||
{ | ||
a: | ||
!{} | ||
a: !{} | ||
} | ||
}} | ||
</p> | ||
<p> | ||
{{ | ||
{ | ||
a: | ||
a | ||
? b | ||
: {} | ||
a: a | ||
? b | ||
: {} | ||
} | ||
}} | ||
</p> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var obj = { | ||
// an entry with a very long string | ||
x: "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
url: 'http://example.com/12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890', | ||
longName: "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
[i]: "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
[prop]: "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
'x': "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
a: "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
ab: "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
abc: "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
abcd: "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
abcde: "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
abcdef: "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
'古': 'https://prettier.io/docs/en/rationale.html#what-prettier-is-concerned-about', | ||
'古今': 'https://prettier.io/docs/en/rationale.html#what-prettier-is-concerned-about', | ||
'古体诗': 'https://prettier.io/docs/en/rationale.html#what-prettier-is-concerned-about', | ||
}; |
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