Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same print width for range formatting as normal formatting. #6050

Merged
merged 2 commits into from May 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions CHANGELOG.unreleased.md
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/main/core.js
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/range/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -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"]
Expand Down
5 changes: 5 additions & 0 deletions tests/range/nested-print-width.js
@@ -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>>>}
}