Use same print width for range formatting as normal formatting. (#6050)
* Use same print width for range formatting as normal formatting. Fixes an issue were a file would end up formatted differently with ranged formatting (--range-start & --range-end) versus normal whole file formatting. * Document range bugfix in changelog.master
parent
84cc273c7d
commit
26183e5be2
|
@ -42,6 +42,44 @@ Examples:
|
|||
|
||||
-->
|
||||
|
||||
- Range: Fix ranged formatting not using the correct line width ([#6050] by [@mathieulj])
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
// Input
|
||||
function f() {
|
||||
if (true) {
|
||||
call("this line is 79 chars", "long", "it should", "stay as single line");
|
||||
}
|
||||
}
|
||||
|
||||
// Output (Prettier stable run with --range-start 30 --range-end 110)
|
||||
function f() {
|
||||
if (true) {
|
||||
call(
|
||||
"this line is 79 chars",
|
||||
"long",
|
||||
"it should",
|
||||
"stay as single line"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Output (Prettier stable run without range)
|
||||
function f() {
|
||||
if (true) {
|
||||
call("this line is 79 chars", "long", "it should", "stay as single line");
|
||||
}
|
||||
}
|
||||
|
||||
// Output (Prettier master with and without range)
|
||||
function f() {
|
||||
if (true) {
|
||||
call("this line is 79 chars", "long", "it should", "stay as single line");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- JavaScript: Fix closure compiler typecasts ([#5947] by [@jridgewell])
|
||||
|
||||
If a closing parenthesis follows after a typecast in an inner expression, the typecast would wrap everything to the that following parenthesis.
|
||||
|
|
|
@ -210,7 +210,6 @@ function formatRange(text, opts) {
|
|||
Object.assign({}, opts, {
|
||||
rangeStart: 0,
|
||||
rangeEnd: Infinity,
|
||||
printWidth: opts.printWidth - alignmentSize,
|
||||
// track the cursor offset only if it's within our range
|
||||
cursorOffset:
|
||||
opts.cursorOffset >= rangeStart && opts.cursorOffset < rangeEnd
|
||||
|
|
|
@ -334,6 +334,28 @@ try {
|
|||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`nested-print-width.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
function f() {
|
||||
if (true) {
|
||||
call("this line is 79 chars", "long", "it should", "stay as single line");
|
||||
}
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
function f() {
|
||||
if (true) {
|
||||
call("this line is 79 chars", "long", "it should", "stay as single line");
|
||||
}
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`nested2.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "typescript"]
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
function f() {
|
||||
if (true) {<<<PRETTIER_RANGE_START>>>
|
||||
call("this line is 79 chars", "long", "it should", "stay as single line");
|
||||
<<<PRETTIER_RANGE_END>>>}
|
||||
}
|
Loading…
Reference in New Issue