Prettier 1.2
1.0 is not the end of prettier, we're going to continue to work on the long tail of formatting issues in order to make it an awesome JavaScript code formatter. You should expect minor version releases like this one to change small things and edge cases but nothing major or controversial.
Format
#1286)
Do not print the sub-tree when using prettier-ignore (#1294)
Bail when traversing === groups (A regression was introduced in 1.0 where deeply nested functions like this would trigger an exponential behavior and no longer complete in a reasonable time. We introduced a mitigation such that it's not instant but at least completes in a reasonable amount of time.
someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
return someObject.someFunction().then(function () {
});
});
});
});
});
#1344)
Break if () if conditional inside breaks (prettier was sometimes breaking inside of an if condition as it didn't fit 80 columns but would print all the conditions in a single line. This was very weird looking. Now if the if break, prettier will also break the conditions.
// Before
if (
this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
) {
// After
if (
this.hasPlugin("dynamicImports") &&
this.lookahead().type === tt.parenLeft
) {
#1305)
Avoid breaking arguments for last arg expansion (A long-standing issue around last argument expansion and complex arguments has been fixed, it no longer looks crazy bad.
// Before
manageChildren: jest.fn(function manageChildren(parentTag, moveFromIndices = [
], moveToIndices = [], addChildReactTags = [], addAtIndices = [
], removeAtIndices = []) {
// After
manageChildren: jest.fn(function manageChildren(
parentTag,
moveFromIndices = [],
moveToIndices = [],
addChildReactTags = [],
addAtIndices = [],
removeAtIndices = []
) {
#1326)
Add parentheses for assignment as body of arrow (We're fine tuning when to add parenthesis in order to improve understanding of the code. This time, we're adding it to assignment inside of arrow functions. Please open up issues if you think that there should be parenthesis and prettier doesn't put them.
// Before
() => foo = bar + 2;
// After
() => (foo = bar + 2);
#1341)
Improve regex printing (Flow and Babylon were inconsistent in how they printed escapes and flags. Now the escapes are untouched compared to the original ones and the flags are sorted.
// Before
/[\/]\/\u0aBc/mgi;
// After
/[/]\/\u0aBc/gim;
#1339)
Fix arrow function parenthesis with comments in flow (With the Flow parser, prettier didn't add parenthesis for single argument functions with a comment.
// Before
call(/*object*/ row => {});
// After
call((/*object*/ row) => {});
#1345)
Don't inline paren at right of arguments (We incorrectly put a comment at the right of arguments inside of the argument list.
// Before
f(/* ... */) {}
// After
f() /* ... */ {}
#1296)
Fix template literal comments (Comments inside of template literals would crash in some conditions and be inserted in the wrong ${}
, no more :)
// Before
stdin: TypeError: Cannot read property 'comments' of undefined
// After
`
(?:${escapeChar}[\\S\\s]|(?:(?!${// Using `XRegExp.union` safely rewrites backreferences in `left` and `right`.
// Intentionally not passing `basicFlags` to `XRegExp.union` since any syntax
// transformation resulting from those flags was already applied to `left` and
// `right` when they were passed through the XRegExp constructor above.
XRegExp.union([left, right], '', {conjunction: 'or'}).source})[^${escapeChar}])+)+
`
#1263)
Fix isPreviousLineEmpty on Windows (Empty lines were not properly preserved for switch case on windows.
// Before
switch (a) {
case x:
case y:
call();
}
// After
switch (a) {
case x:
case y:
call();
}
CLI
#1307)
Skip globbing filenames with node-glob when the filename is not a glob (If you run prettier file.js
and file.js
doesn't exist, it's going to throw an exception instead of silently doing nothing.
#1292)
Write out change CLI changes synchronously (There was a race condition when you did ctrl-c to stop the process where it could delete files. Now we write files synchronously so it doesn't anymore.