From 05ceaf35ac030fcc4d0300bd64b59ae685407521 Mon Sep 17 00:00:00 2001 From: Alexander Kachkaev Date: Sat, 21 Mar 2020 22:06:39 +0000 Subject: [PATCH 1/2] Improve formatting comments in v2.0 blog post --- website/blog/2020-03-21-2.0.0.md | 284 +++++++++++++++---------------- 1 file changed, 142 insertions(+), 142 deletions(-) diff --git a/website/blog/2020-03-21-2.0.0.md b/website/blog/2020-03-21-2.0.0.md index 0d83b3f83ffe..d72a47767dc8 100644 --- a/website/blog/2020-03-21-2.0.0.md +++ b/website/blog/2020-03-21-2.0.0.md @@ -18,7 +18,7 @@ Previously, any method call chain of length three or longer would be automatical ```javascript -// Output (Prettier stable) +// Prettier 1.19 if ( foo .one() @@ -32,7 +32,7 @@ if ( // ... } -// Output (Prettier master) +// Prettier 2.0 if (foo.one().two().three() === bar.four().five().six()) { // ... } @@ -53,10 +53,10 @@ const nestedAssertions = /** @type {MyType} */ (/** @type {unknown} */ (x)); -// Prettier stable +// Prettier 1.19 const nestedAssertions /** @type {MyType} */ /** @type {unknown} */ = x; -// Prettier master +// Prettier 2.0 const nestedAssertions = /** @type {MyType} */ (/** @type {unknown} */ (x)); ``` @@ -131,10 +131,10 @@ In version 2.0, this behavior has become the default. // Input const fn = (x) => y => x + y; -// Prettier stable +// Prettier 1.19 const fn = x => y => x + y; -// Prettier master +// Prettier 2.0 const fn = (x) => (y) => x + y; ``` @@ -189,7 +189,7 @@ Previously, a space would be added after the `function` keyword in function decl ```ts -// Prettier stable +// Prettier 1.19 const identity = function(value) { return value; }; @@ -199,7 +199,7 @@ function identity(value) { const f = function(value: T) {}; const g = function*() {}; -// Prettier master +// Prettier 2.0 const identity = function (value) { return value; }; @@ -219,15 +219,15 @@ loop1: //test const i = 3; -// Prettier stable (first output) +// Prettier 1.19 (first output) loop1: //test const i = 3; -// Prettier stable (second output) +// Prettier 1.19 (second output) //test loop1: const i = 3; -// Prettier master (first output) +// Prettier 2.0 (first and second outputs) //test loop1: const i = 3; ``` @@ -241,7 +241,7 @@ loop1: const i = 3; `111111111 222222222 333333333 444444444 555555555 666666666 777777777 ${foo | bar}`; `111111111 222222222 333333333 444444444 555555555 666666666 777777777 ${(foo, bar)}`; -// Prettier stable +// Prettier 1.19 `111111111 222222222 333333333 444444444 555555555 666666666 777777777 ${foo || bar}`; `111111111 222222222 333333333 444444444 555555555 666666666 777777777 ${foo | @@ -249,7 +249,7 @@ loop1: const i = 3; `111111111 222222222 333333333 444444444 555555555 666666666 777777777 ${(foo, bar)}`; -// Prettier master +// Prettier 2.0 `111111111 222222222 333333333 444444444 555555555 666666666 777777777 ${ foo || bar }`; @@ -270,18 +270,18 @@ const averredBathersBoxroomBuggyNurl = bifornCringerMoshedPerplexSawder === 1 || (askTrovenaBeenaDependsRowans === 2 || glimseGlyphsHazardNoopsTieTie === 3); -// Prettier stable (first output) +// Prettier 1.19 (first output) const averredBathersBoxroomBuggyNurl = bifornCringerMoshedPerplexSawder === 1 || askTrovenaBeenaDependsRowans === 2 || glimseGlyphsHazardNoopsTieTie === 3; -// Prettier stable (second output) +// Prettier 1.19 (second output) const averredBathersBoxroomBuggyNurl = bifornCringerMoshedPerplexSawder === 1 || askTrovenaBeenaDependsRowans === 2 || glimseGlyphsHazardNoopsTieTie === 3; -// Prettier master (first and second outputs) +// Prettier 2.0 (first and second outputs) const averredBathersBoxroomBuggyNurl = bifornCringerMoshedPerplexSawder === 1 || askTrovenaBeenaDependsRowans === 2 || @@ -297,14 +297,14 @@ function foo() { throw this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft.right; } -// Prettier stable +// Prettier 1.19 function foo() { throw this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft.right; } -// Prettier master +// Prettier 2.0 function foo() { throw ( this.hasPlugin("dynamicImports") && @@ -322,14 +322,14 @@ const foo = (number % 10 >= 2 && (number % 100 < 10 || number % 100 >= 20) ? kochabCooieGameOnOboleUnweave : annularCooeedSplicesWalksWayWay) ? anodyneCondosMalateOverateRetinol : averredBathersBoxroomBuggyNurl; -// Prettier stable +// Prettier 1.19 const foo = (number % 10 >= 2 && (number % 100 < 10 || number % 100 >= 20) ? kochabCooieGameOnOboleUnweave : annularCooeedSplicesWalksWayWay) ? anodyneCondosMalateOverateRetinol : averredBathersBoxroomBuggyNurl; -// Prettier master +// Prettier 2.0 const foo = ( number % 10 >= 2 && (number % 100 < 10 || number % 100 >= 20) ? kochabCooieGameOnOboleUnweave @@ -355,7 +355,7 @@ export class Item { thing!: Thing; } -// Output (Prettier stable) +// Prettier 1.19 export class Item { @OneToOne( () => Thing, @@ -364,7 +364,7 @@ export class Item { thing!: Thing; } -// Output (Prettier master) +// Prettier 2.0 export class Item { @OneToOne(() => Thing, x => x.item) thing!: Thing; @@ -379,10 +379,10 @@ export class Item { return // comment ; -// Prettier stable +// Prettier 1.19 return // comment; -// Prettier master +// Prettier 2.0 return; // comment ``` @@ -397,7 +397,7 @@ This doesn't happen anymore unless `--html-whitespace-sensitivity ignore` option html`
`; html` TEXT `; -// Prettier stable +// Prettier 1.19 html`
`; @@ -405,7 +405,7 @@ html` TEXT `; -// Prettier master +// Prettier 2.0 html`
`; html` TEXT `; ``` @@ -419,12 +419,12 @@ function* f() { yield
generator
; } -// Prettier stable +// Prettier 1.19 function* f() { yield (
generator
); } -// Prettier master +// Prettier 2.0 function* f() { yield
generator
; } @@ -439,10 +439,10 @@ Omitting these parentheses makes the code invalid. // Input export default (1, 2); -// Prettier stable +// Prettier 1.19 export default 1, 2; -// Prettier master +// Prettier 2.0 export default (1, 2); ``` @@ -454,11 +454,11 @@ export default (1, 2); (foo?.bar)(); new (foo?.bar)(); -// Prettier stable +// Prettier 1.19 foo?.bar(); new foo?.bar(); -// Prettier master +// Prettier 2.0 (foo?.bar)(); new (foo?.bar)(); ``` @@ -475,7 +475,7 @@ undefined foo ? loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong jsx : null -// Prettier stable +// Prettier 1.19 foo ? ( loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong jsx @@ -489,7 +489,7 @@ foo ? ( ) : null; -// Prettier master +// Prettier 2.0 foo ? ( loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong jsx @@ -510,10 +510,10 @@ foo ? ( const foo = /* comments */ bar; -// Prettier stable +// Prettier 1.19 const foo /* comments */ = bar; -// Prettier master +// Prettier 2.0 const foo = /* comments */ bar; ``` @@ -534,13 +534,13 @@ export const getVehicleDescriptor = async ( Collections.Parts.PrintedCircuitBoardAssembly["attributes"] & undefined > => {}; -// Prettier stable +// Prettier 1.19 export const getVehicleDescriptor = async ( vehicleId: string ): Promise => {}; -// Prettier master +// Prettier 2.0 export const getVehicleDescriptor = async ( vehicleId: string ): Promise< @@ -557,10 +557,10 @@ Another fix related to error recovery. Should come in handy to those who migrate // Input function fromFlow(arg: ?Maybe) {} -// Prettier stable +// Prettier 1.19 Error: unknown type: "TSJSDocNullableType" -// Prettier master +// Prettier 2.0 function fromFlow(arg: ?Maybe) {} ``` @@ -581,7 +581,7 @@ type ValidateArgs = [ ...string[], ]; -// Prettier stable +// Prettier 1.19 type ValidateArgs = [ { [key: string]: any; @@ -590,7 +590,7 @@ type ValidateArgs = [ ...string[], ]; -// Prettier master +// Prettier 2.0 type ValidateArgs = [ { [key: string]: any; @@ -614,7 +614,7 @@ const foo = () => { // foo ;[1,2,3].forEach(bar) -// Prettier stable +// Prettier 1.19 const foo = () => { return; }; @@ -622,7 +622,7 @@ const foo = () => { // foo [1, 2, 3].forEach(bar); -// Prettier master +// Prettier 2.0 const foo = () => { return; }; @@ -641,13 +641,13 @@ type f1 = ( // TODO this is a very very very very long comment that makes it go > 80 columns ) => number; -// Prettier stable +// Prettier 1.19 type f1 = (currentRequest: { a: number; }) => // TODO this is a very very very very long comment that makes it go > 80 columns number; -// Prettier master +// Prettier 2.0 type f1 = ( currentRequest: { a: number } // TODO this is a very very very very long comment that makes it go > 80 columns @@ -675,7 +675,7 @@ type foo8 = /* foo */ (a: /* bar */ string) /* baz */ => void let foo9: new /* foo */ (/* bar */) /* baz */ => string; let foo10: new /* foo */ (a: /* bar */ string) /* baz */ => string; -// Prettier stable +// Prettier 1.19 interface foo1 { bar1 /* foo */ /* baz */(); // bat bar2 /* foo */ /* bar */ /* baz */ /* bat */?(); @@ -692,7 +692,7 @@ type foo8 = /* foo */ (a: /* bar */ string) => /* baz */ void; let foo9: new () => /* foo */ /* bar */ /* baz */ string; let foo10: new (/* foo */ a: /* bar */ string) => /* baz */ string; -// Prettier master +// Prettier 2.0 interface foo1 { bar1 /* foo */(/* baz */); // bat bar2 /* foo */ /* bar */?(/* baz */) /* bat */; @@ -718,10 +718,10 @@ abstract class Test { abstract foo13 /* foo */ (/* bar */) /* baz */ } -// Prettier stable +// Prettier 1.19 Error: Comment "foo" was not printed. Please report this error! -// Prettier master +// Prettier 2.0 abstract class Test { abstract foo12 /* foo */(a: /* bar */ string): /* baz */ void; abstract foo13 /* foo */(/* bar */); /* baz */ @@ -735,10 +735,10 @@ abstract class Test { // Input type A = { [key in B] }; -// Prettier stable +// Prettier 1.19 type A = { [key in B]: }; -// Prettier master +// Prettier 2.0 type A = { [key in B] }; ``` @@ -750,13 +750,13 @@ Even though index signatures without type annotations or with multiple parameter ```ts // Input type A = { [key: string] }; -type B = { [a: string, b: string]: string; }; +type B = { [a: string, b: string]: string; }; -// Prettier stable +// Prettier 1.19 type A = { [key: string]: }; type B = { [a: stringb: string]: string }; -// Prettier master +// Prettier 2.0 type A = { [key: string] }; type B = { [a: string, b: string]: string }; ``` @@ -768,10 +768,10 @@ type B = { [a: string, b: string]: string }; // Input const a: T = 1; -// Prettier stable +// Prettier 1.19 Error: Comment "comment" was not printed. Please report this error! -// Prettier master +// Prettier 2.0 const a: T = 1; ``` @@ -789,7 +789,7 @@ const x: symbol = Symbol(); // Prettier after updating Flow, but without this fix Error: unknown type: "SymbolTypeAnnotation" -// Prettier master +// Prettier 2.0 const x: symbol = Symbol(); ``` @@ -809,10 +809,10 @@ class Foo { method2() {} } -// Prettier stable +// Prettier 1.19 SyntaxError: Unexpected token `@`, expected the token `class` (2:1) -// Prettier master +// Prettier 2.0 /* @flow */ @decorator4 class Foo { @@ -834,12 +834,12 @@ class Foo { #privateProp: number; } -// Prettier stable +// Prettier 1.19 class Foo { privateProp: number; } -// Prettier master +// Prettier 2.0 class Foo { #privateProp: number; } @@ -859,11 +859,11 @@ Prettier now always preserves original casing. Label { } -/* Prettier stable */ +/* Prettier 1.19 */ label { } -/* Prettier master */ +/* Prettier 2.0 */ Label { } ``` @@ -882,7 +882,7 @@ $my-map: ( 'bar': 2, // Comment ); -// Prettier stable +// Prettier 1.19 $my-map: ( "foo": 1, // Comment @@ -890,7 +890,7 @@ $my-map: ( // Comment, ); -// Prettier master +// Prettier 2.0 $my-map: ( "foo": 1, // Comment @@ -908,12 +908,12 @@ a { background-image: url($test-path + 'static/test.jpg'); } -// Prettier stable +// Prettier 1.19 a { background-image: url($test-path+"static/test.jpg"); } -// Prettier master +// Prettier 2.0 a { background-image: url($test-path + "static/test.jpg"); } @@ -940,14 +940,14 @@ a { - +
     
   
- +
     
@@ -973,7 +973,7 @@ e-wrap 
  inline  inline   inline  inline 
 
 
-
+
 
   
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block @@ -989,7 +989,7 @@ e-wrap > inline - +
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block @@ -1023,10 +1023,10 @@ e-wrap < - + TypeError: Cannot read property 'start' of null - +
<
``` @@ -1041,10 +1041,10 @@ srcset=" /media/examples/surfer-240-200.jpg "> - + Error: Mixed descriptor in srcset is not supported - + ``` @@ -1056,10 +1056,10 @@ Error: Mixed descriptor in srcset is not supported


- + TypeError: Cannot read property 'start' of null - +


``` @@ -1073,14 +1073,14 @@ TypeError: Cannot read property 'start' of null - + - +
Should not insert empty line before this div
- +
Should not insert empty line before this div
- +
@@ -1124,7 +1124,7 @@ even can not fit one line really a lot and lot of classes ">
- +
- +
- +
- +
export default { data: () => ({ @@ -1270,7 +1270,7 @@ export default { } - + - + - +