diff --git a/src/printer.js b/src/printer.js index ecfab4ea3..2450d03b9 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2080,7 +2080,7 @@ function adjustClause(clause, options, forceSpace) { return concat([ " ", clause ]); } - return indent(options.tabWidth, concat([ hardline, clause ])); + return indent(options.tabWidth, concat([ line, clause ])); } function isCurlyBracket(doc) { diff --git a/tests/abnormal/__snapshots__/jsfmt.spec.js.snap b/tests/abnormal/__snapshots__/jsfmt.spec.js.snap index bf33d38a1..d8cbcd17d 100644 --- a/tests/abnormal/__snapshots__/jsfmt.spec.js.snap +++ b/tests/abnormal/__snapshots__/jsfmt.spec.js.snap @@ -33,8 +33,7 @@ function foo() { function bar(x: number) {} function foo() { var x = null; - if (x == null) - return; + if (x == null) return; bar(x); } " diff --git a/tests/break/__snapshots__/jsfmt.spec.js.snap b/tests/break/__snapshots__/jsfmt.spec.js.snap index 406a0070d..732c630b6 100644 --- a/tests/break/__snapshots__/jsfmt.spec.js.snap +++ b/tests/break/__snapshots__/jsfmt.spec.js.snap @@ -83,8 +83,7 @@ function foo(b) { function bar(b) { var x = b ? null : false; - if (x == null) - return; + if (x == null) return; switch (\"\") { case 0: var y: number = x; @@ -101,8 +100,7 @@ function bar(b) { function bar2(b) { var x = b ? null : false; - if (x == null) - return; + if (x == null) return; switch (\"\") { case 0: { let y: number = x; diff --git a/tests/instanceof/__snapshots__/jsfmt.spec.js.snap b/tests/instanceof/__snapshots__/jsfmt.spec.js.snap index c757067d1..d32238bbf 100644 --- a/tests/instanceof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/instanceof/__snapshots__/jsfmt.spec.js.snap @@ -104,16 +104,13 @@ function x(b) { function consumer1(b) { var g = x(b); - if (g instanceof X2) - g.foo = \"1337\"; - else - g.foo = 1337; + if (g instanceof X2) g.foo = \"1337\"; + else g.foo = 1337; } function consumer2(b) { var g = x(b); - if (g instanceof X1) - g.foo = \"1337\"; // oops + if (g instanceof X1) g.foo = \"1337\"; // oops } // x.y instanceof t @@ -131,16 +128,13 @@ function y(b) { function consumer3(b) { var g = y(b); - if (g.bar instanceof X2) - g.bar.foo = \"1337\"; - else - g.bar.foo = 1337; + if (g.bar instanceof X2) g.bar.foo = \"1337\"; + else g.bar.foo = 1337; } function consumer4(b) { var g = y(b); - if (g.bar instanceof X1) - g.bar.foo = \"1337\"; // oops + if (g.bar instanceof X1) g.bar.foo = \"1337\"; // oops } // x.y.z instance of t @@ -158,25 +152,20 @@ function z(b) { function consumer5(b) { var g = z(b); - if (g.baz.bar instanceof X2) - g.baz.bar.foo = \"1337\"; - else - g.baz.bar.foo = 1337; + if (g.baz.bar instanceof X2) g.baz.bar.foo = \"1337\"; + else g.baz.bar.foo = 1337; } function consumer6(b) { var g = z(b); - if (g.baz.bar instanceof X1) - g.baz.bar.foo = \"1337\"; // oops + if (g.baz.bar instanceof X1) g.baz.bar.foo = \"1337\"; // oops } // this instanceof t class C { m() { - if (this instanceof D) - alert(this.s); - else - alert(\"nope\"); + if (this instanceof D) alert(this.s); + else alert(\"nope\"); } } diff --git a/tests/nullable/__snapshots__/jsfmt.spec.js.snap b/tests/nullable/__snapshots__/jsfmt.spec.js.snap index 5489aef98..33cfd5db7 100644 --- a/tests/nullable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/nullable/__snapshots__/jsfmt.spec.js.snap @@ -48,11 +48,9 @@ function corge(x: number) {} var x = bar(); // x: ?string -if (x != null) - qux(x); +if (x != null) qux(x); // x: ?string | null -if (x != null) - corge(x); +if (x != null) corge(x); // x: ?string | null function grault() { x = null; diff --git a/tests/path/__snapshots__/jsfmt.spec.js.snap b/tests/path/__snapshots__/jsfmt.spec.js.snap index 2de635b6a..282608fed 100644 --- a/tests/path/__snapshots__/jsfmt.spec.js.snap +++ b/tests/path/__snapshots__/jsfmt.spec.js.snap @@ -9,8 +9,7 @@ var z:number = x; var x = 1; while (typeof x == \"number\" || typeof x == \"string\") { x = x + 1; - if (true) - x = \"\"; + if (true) x = \"\"; } var z: number = x; " diff --git a/tests/plsummit/__snapshots__/jsfmt.spec.js.snap b/tests/plsummit/__snapshots__/jsfmt.spec.js.snap index 7a51a4316..b7c5075fc 100644 --- a/tests/plsummit/__snapshots__/jsfmt.spec.js.snap +++ b/tests/plsummit/__snapshots__/jsfmt.spec.js.snap @@ -80,8 +80,7 @@ function foo() { } function bar(x: ?string): number { - if (x == null) - x = \"\"; + if (x == null) x = \"\"; return x.length; } " diff --git a/tests/refi/__snapshots__/jsfmt.spec.js.snap b/tests/refi/__snapshots__/jsfmt.spec.js.snap index 176504bd4..090250741 100644 --- a/tests/refi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/refi/__snapshots__/jsfmt.spec.js.snap @@ -85,8 +85,7 @@ var tests = [ } }, function() { - if (x == null) - return; + if (x == null) return; var y: string = x; // ok }, function() { @@ -383,8 +382,7 @@ var tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p == null) - return; + if (x.p == null) return; var y: string = x.p; // ok }, function() { @@ -762,8 +760,7 @@ var paths = [ }, function() { var x: ?string = \"xxx\"; - if (x == null) - return; + if (x == null) return; var y: string = x; // ok }, function() { @@ -1071,28 +1068,22 @@ class C { p: ?string; ensure0(): string { - if (this.p != null) - return this.p; - else - return \"\"; + if (this.p != null) return this.p; + else return \"\"; } ensure1(): string { - if (this.p == null) - return \"\"; + if (this.p == null) return \"\"; return this.p; } ensure2(): string | void { - if (this.p !== null) - return this.p; - else - return \"\"; + if (this.p !== null) return this.p; + else return \"\"; } ensure3(): string | void { - if (this.p === null) - return \"\"; + if (this.p === null) return \"\"; return this.p; } } @@ -1100,17 +1091,13 @@ class C { // super.p op null class D extends C { ensure100(): string { - if (super.p != null) - return super.p; - else - return \"\"; + if (super.p != null) return super.p; + else return \"\"; } ensure101(): string { - if (super.p == null) - return \"\"; - else - return super.p; + if (super.p == null) return \"\"; + else return super.p; } ensure103(): string { @@ -1486,31 +1473,23 @@ class A { p: ?string; ensure0(): string { - if (typeof this.p == \"string\") - return this.p; - else - return \"\"; + if (typeof this.p == \"string\") return this.p; + else return \"\"; } ensure1(): string { - if (typeof this.p != \"string\") - return \"\"; - else - return this.p; + if (typeof this.p != \"string\") return \"\"; + else return this.p; } ensure2(): string | void { - if (typeof this.p === \"string\") - return this.p; - else - return \"\"; + if (typeof this.p === \"string\") return this.p; + else return \"\"; } ensure3(): string | void { - if (typeof this.p !== \"string\") - return \"\"; - else - return this.p; + if (typeof this.p !== \"string\") return \"\"; + else return this.p; } } " @@ -1648,17 +1627,13 @@ class A { p: ?string; ensure0(): string { - if (this.p !== undefined && this.p !== null) - return this.p; - else - return \"\"; + if (this.p !== undefined && this.p !== null) return this.p; + else return \"\"; } ensure1(): string { - if (this.p === undefined || this.p === null) - return \"\"; - else - return this.p; + if (this.p === undefined || this.p === null) return \"\"; + else return this.p; } } " @@ -1796,17 +1771,13 @@ class A { p: ?string; ensure0(): string { - if (this.p !== void 0 && this.p !== null) - return this.p; - else - return \"\"; + if (this.p !== void 0 && this.p !== null) return this.p; + else return \"\"; } ensure1(): string { - if (this.p === void 0 || this.p === null) - return \"\"; - else - return this.p; + if (this.p === void 0 || this.p === null) return \"\"; + else return this.p; } } " diff --git a/tests/refinements/__snapshots__/jsfmt.spec.js.snap b/tests/refinements/__snapshots__/jsfmt.spec.js.snap index 163f54563..e70352b9c 100644 --- a/tests/refinements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/refinements/__snapshots__/jsfmt.spec.js.snap @@ -287,8 +287,7 @@ type NonNullType = { kind: \"NonNullType\", type: Name | ListType | BadType }; type BadType = {}; function getTypeASTName(typeAST: Type): string { - if (!typeAST.type) - throw new Error(\"Must be wrapping type\"); + if (!typeAST.type) throw new Error(\"Must be wrapping type\"); // OK return getTypeASTName(typeAST.type); // error, BadType not a subtype of Type } @@ -2466,8 +2465,7 @@ type Breakfast = Apple | Orange | Broccoli | Carrot; function bar(x: Breakfast) { if (x.kind === \"Fruit\") { (x.taste: \"Good\"); - } // error, Apple.taste = Bad else - (x.raw: \"No\"); // error, Carrot.raw = Maybe + } // error, Apple.taste = Bad else (x.raw: \"No\"); // error, Carrot.raw = Maybe } function qux(x: Breakfast) { @@ -2480,8 +2478,7 @@ function qux(x: Breakfast) { // example 4 function list(n) { - if (n > 0) - return { kind: \"cons\", next: list(n - 1) }; + if (n > 0) return { kind: \"cons\", next: list(n - 1) }; return { kind: \"nil\" }; } function length(l) { @@ -2493,8 +2490,7 @@ function length(l) { } } function check(n) { - if (n >= 0) - return n === length(list(n)); + if (n >= 0) return n === length(list(n)); return true; } @@ -2520,10 +2516,8 @@ kind({ kind: EnumKind.A, A: 1 }); type Citizen = { citizen: true }; type NonCitizen = { citizen: false, nationality: string }; function nationality(x: Citizen | NonCitizen) { - if (x.citizen) - return \"Shire\"; - else - return x.nationality; + if (x.citizen) return \"Shire\"; + else return x.nationality; } let tests = [ diff --git a/tests/super/__snapshots__/jsfmt.spec.js.snap b/tests/super/__snapshots__/jsfmt.spec.js.snap index e80899e8e..b2ecf83cd 100644 --- a/tests/super/__snapshots__/jsfmt.spec.js.snap +++ b/tests/super/__snapshots__/jsfmt.spec.js.snap @@ -211,10 +211,8 @@ class G extends A { class H extends A { y: number; constructor() { - if (Math.random() < 0.5) - super(); - else - super(); + if (Math.random() < 0.5) super(); + else super(); this.y; // OK this.x; // OK @@ -262,8 +260,7 @@ class K_ { class K extends K_ { constructor() { super(() => { - if (_this) - _this.foo(); + if (_this) _this.foo(); }); // OK var _this = this; diff --git a/tests/tabWith/__snapshots__/jsfmt.spec.js.snap b/tests/tabWith/__snapshots__/jsfmt.spec.js.snap index e583af41a..03113ea47 100644 --- a/tests/tabWith/__snapshots__/jsfmt.spec.js.snap +++ b/tests/tabWith/__snapshots__/jsfmt.spec.js.snap @@ -15,8 +15,7 @@ class A { var x = 1; while (typeof x == \"number\" || typeof x == \"string\") { x = x + 1; - if (true) - x = \"\"; + if (true) x = \"\"; } var z: number = x; } @@ -41,8 +40,7 @@ class A { var x = 1; while (typeof x == \"number\" || typeof x == \"string\") { x = x + 1; - if (true) - x = \"\"; + if (true) x = \"\"; } var z: number = x; } diff --git a/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap b/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap index f42c9a98e..2848c5c28 100644 --- a/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap @@ -17,8 +17,7 @@ function foo(x: ?string): $NonMaybeType { function foo(x: ?string): $NonMaybeType { if (x != null) { return x; - } else - return 0; // this should be an error + } else return 0; // this should be an error } //(foo(): string); // should not be necessary to expose the error above @@ -51,10 +50,8 @@ type Obj_Prop_x = $PropertyType; (42: Obj_Prop_x); function foo(o: Obj): $PropertyType { - if (false) - return o.x; - else - return 0; + if (false) return o.x; + else return 0; } " `; diff --git a/tests/undefined/__snapshots__/jsfmt.spec.js.snap b/tests/undefined/__snapshots__/jsfmt.spec.js.snap index 553191442..d869ee280 100644 --- a/tests/undefined/__snapshots__/jsfmt.spec.js.snap +++ b/tests/undefined/__snapshots__/jsfmt.spec.js.snap @@ -47,8 +47,7 @@ function foo() { function bar() { var x: ?{ bar(): void }; - if (x) - x.bar(); + if (x) x.bar(); } function qux(x?: number, y: string = \"\", z) {} diff --git a/tests/union_new/__snapshots__/jsfmt.spec.js.snap b/tests/union_new/__snapshots__/jsfmt.spec.js.snap index 22046bc1c..e0e214dfe 100644 --- a/tests/union_new/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union_new/__snapshots__/jsfmt.spec.js.snap @@ -330,10 +330,8 @@ function hello(x:X): string { type X = ({ a: true } & { b: string }) | ({ a: false } & { c: string }); //type X = {a:true, b:string} | {a:false, c:string}; // this works. function hello(x: X): string { - if (x.a === true) - return x.b; - else - return x.c; + if (x.a === true) return x.b; + else return x.c; } " `; @@ -1242,10 +1240,8 @@ type Cons = { kind: \"cons\", next: List }; // disjoint unions function length(list: List) { - if (list.kind === \"cons\") - return length(list.next) + 1; - else - return 0; + if (list.kind === \"cons\") return length(list.next) + 1; + else return 0; } length({ kind: \"nil\" }); @@ -1619,10 +1615,8 @@ type Error = { type: \"ERROR\" } & Empty; export type T = Success | Error; function foo(x: T) { - if (x.type === \"SUCCESS\") - return x.result; - else - return x.result; + if (x.type === \"SUCCESS\") return x.result; + else return x.result; } " `; @@ -1827,17 +1821,13 @@ function hello4(x:X): string { type X = ({ a: true } & { b: string }) | ({ a: false } & { c: string }); //type X = {a:true, b:string} | {a:false, c:string}; // this works. function hello1(x: X): string { - if (x.a === true) - return x.b; - else - return x.c; + if (x.a === true) return x.b; + else return x.c; } function hello2(x: X): string { - if (x.a === false) - return x.c; - else - return x.b; + if (x.a === false) return x.c; + else return x.b; } function hello3(x: X): string {