Repository: jlongster/prettier
Pull request #520 (2017-01-30 17:53:55)

Fix range for object newline detection
It turns out that the range is not inclusive. It incorrectly included a \n after and would expand way more objects than we intended to.

I found it while running prettier on the codebase.

I'll make 0.14.1 for this.


Patch:
diff --git a/src/util.js b/src/util.js
index 1b2239682..87b076cb6 100644
--- a/src/util.js
+++ b/src/util.js
@@ -160,7 +160,7 @@ function hasNewline(text, index, opts) {
 }
 
 function hasNewlineInRange(text, start, end) {
-  for (var i = start; i <= end; ++i) {
+  for (var i = start; i < end; ++i) {
     if (text.charAt(i) === "\n") {
       return true;
     }


Test patch:
diff --git a/tests/bracketSpacing/__snapshots__/jsfmt.spec.js.snap b/tests/bracketSpacing/__snapshots__/jsfmt.spec.js.snap
index cd4bc1fb0..12dda2761 100644
--- a/tests/bracketSpacing/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/bracketSpacing/__snapshots__/jsfmt.spec.js.snap
@@ -20,11 +20,7 @@ exports[`test object.js 1`] = `
 "const obj1 = {a:1, b:2, c:3}
 const obj2 = { a:1, b:2, c:3 };
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-const obj1 = {
-  a: 1,
-  b: 2,
-  c: 3
-};
+const obj1 = { a: 1, b: 2, c: 3 };
 const obj2 = { a: 1, b: 2, c: 3 };
 "
 `;
@@ -33,11 +29,7 @@ exports[`test object.js 2`] = `
 "const obj1 = {a:1, b:2, c:3}
 const obj2 = { a:1, b:2, c:3 };
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-const obj1 = {
-  a: 1,
-  b: 2,
-  c: 3
-};
+const obj1 = {a: 1, b: 2, c: 3};
 const obj2 = {a: 1, b: 2, c: 3};
 "
 `;
diff --git a/tests/flow/arrays/__snapshots__/jsfmt.spec.js.snap b/tests/flow/arrays/__snapshots__/jsfmt.spec.js.snap
index c1b6751b4..54e281694 100644
--- a/tests/flow/arrays/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/arrays/__snapshots__/jsfmt.spec.js.snap
@@ -73,11 +73,7 @@ var abig2: Array<{ x: number, y: number }> = [
   { x: 0, y: 0, a: true },
   { x: 0, y: 0, b: \"hey\" },
   { x: 0, y: 0, c: 1 },
-  {
-    x: 0,
-    y: 0,
-    c: \"hey\"
-  }
+  { x: 0, y: 0, c: \"hey\" }
 ];
 
 module.exports = \"arrays\";
diff --git a/tests/flow/binding/__snapshots__/jsfmt.spec.js.snap b/tests/flow/binding/__snapshots__/jsfmt.spec.js.snap
index a2fda17b3..c1c8c54e5 100644
--- a/tests/flow/binding/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/binding/__snapshots__/jsfmt.spec.js.snap
@@ -45,9 +45,7 @@ x &= 0;
 
 // regression tests -- OK to assign consts like this:
 
-const { foo } = {
-  foo: \"foo\"
-};
+const { foo } = { foo: \"foo\" };
 const [bar] = [\"bar\"];
 (foo: number); // error: string ~> number
 (bar: number); // error: string ~> number
diff --git a/tests/flow/destructuring/__snapshots__/jsfmt.spec.js.snap b/tests/flow/destructuring/__snapshots__/jsfmt.spec.js.snap
index 2325655c7..4a1e783c9 100644
--- a/tests/flow/destructuring/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/destructuring/__snapshots__/jsfmt.spec.js.snap
@@ -321,9 +321,7 @@ qux({ a: \"\" });
 function corge({ b }: { b: string }) {}
 corge({ b: 0 });
 
-var { n }: { n: number } = {
-  n: \"\"
-};
+var { n }: { n: number } = { n: \"\" };
 
 function test() {
   var { foo } = { bar: 123 }; // error on foo
@@ -545,9 +543,7 @@ function bar() {
 // @flow
 
 var { x } = {
-  x: {
-    foo: \"foo\"
-  }
+  x: { foo: \"foo\" }
 };
 
 function bar() {
diff --git a/tests/flow/dictionary/__snapshots__/jsfmt.spec.js.snap b/tests/flow/dictionary/__snapshots__/jsfmt.spec.js.snap
index 6a88c1eca..e7a387505 100644
--- a/tests/flow/dictionary/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/dictionary/__snapshots__/jsfmt.spec.js.snap
@@ -42,9 +42,7 @@ function foo0(
 }
 
 function foo2(
-  x: {
-    [key: string]: number
-  }
+  x: { [key: string]: number }
 ): { [key: string]: number, +toString: () => string } {
   // x\'s prototype has a toString method
   return x;
diff --git a/tests/flow/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap b/tests/flow/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap
index e524a9cd0..c830a4f52 100644
--- a/tests/flow/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap
@@ -1458,10 +1458,7 @@ export const builders: {
   identifier(name: string): Identifier,
   literal(
     value: ?(string | boolean | number | RegExp),
-    regex?: {
-      pattern: string,
-      flags: string
-    }
+    regex?: { pattern: string, flags: string }
   ): Literal,
   thisExpression(): ThisExpression,
   arrayExpression(elements: Expression[]): ArrayExpression,
diff --git a/tests/flow/facebookisms/__snapshots__/jsfmt.spec.js.snap b/tests/flow/facebookisms/__snapshots__/jsfmt.spec.js.snap
index 23de20903..0481d54ca 100644
--- a/tests/flow/facebookisms/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/facebookisms/__snapshots__/jsfmt.spec.js.snap
@@ -59,9 +59,11 @@ let tests = [
   function(copyProperties: Object$Assign) {
     let result = {};
     result.baz = false;
-    (copyProperties(result, { foo: \"a\" }, {
-      bar: 123
-    }): { foo: string, bar: number, baz: boolean });
+    (copyProperties(result, { foo: \"a\" }, { bar: 123 }): {
+      foo: string,
+      bar: number,
+      baz: boolean
+    });
   },
   // module from lib
   function() {
diff --git a/tests/flow/indexer/__snapshots__/jsfmt.spec.js.snap b/tests/flow/indexer/__snapshots__/jsfmt.spec.js.snap
index a41597fa9..e1b606541 100644
--- a/tests/flow/indexer/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/indexer/__snapshots__/jsfmt.spec.js.snap
@@ -41,58 +41,42 @@ function foo7(): {[key: string]: number; foo: number} {
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // No indexer should be fine
 function foo0(): {} {
-  return {
-    foo: \"bar\"
-  };
+  return { foo: \"bar\" };
 }
 
 // Matching indexer should be fine
 function foo1(): { [key: string]: string } {
-  return {
-    foo: \"bar\"
-  };
+  return { foo: \"bar\" };
 }
 
 // Indexer with different key type is an error when it matches
 function foo2(): { [key: number]: string } {
-  return {
-    foo: \"bar\"
-  };
+  return { foo: \"bar\" };
 }
 
 // Matching indexer with different value type is an error
 function foo3(): { [key: string]: number } {
-  return {
-    foo: \"bar\"
-  };
+  return { foo: \"bar\" };
 }
 
 // Indexer with different key type and different value type is twice an error
 function foo4(): { [key: number]: number } {
-  return {
-    foo: \"bar\"
-  };
+  return { foo: \"bar\" };
 }
 
 // If key exists in object type then indexer is not matched
 function foo5(): { [key: string]: number, foo: string } {
-  return {
-    foo: \"bar\"
-  };
+  return { foo: \"bar\" };
 }
 
 // If key exists in object type then indexer is not matched
 function foo6(): { [key: number]: number, foo: string } {
-  return {
-    foo: \"bar\"
-  };
+  return { foo: \"bar\" };
 }
 
 // Should still complain about mistyped properties
 function foo7(): { [key: string]: number, foo: number } {
-  return {
-    foo: \"bar\"
-  };
+  return { foo: \"bar\" };
 }
 "
 `;
diff --git a/tests/flow/interface/__snapshots__/jsfmt.spec.js.snap b/tests/flow/interface/__snapshots__/jsfmt.spec.js.snap
index d18bb02b7..0eb5e3ed4 100644
--- a/tests/flow/interface/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/interface/__snapshots__/jsfmt.spec.js.snap
@@ -2,9 +2,7 @@ exports[`test import.js 1`] = `
 "interface I { x: number }
 export type J = I; // workaround for export interface
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-interface I {
-  x: number
-}
+interface I { x: number }
 export type J = I; // workaround for export interface
 "
 `;
@@ -48,15 +46,11 @@ function testInterfaceName(o: I) {
   (o.constructor.name: string); // ok
 }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-declare class C {
-  x: number
-}
+declare class C { x: number }
 
 var x: string = new C().x;
 
-interface I {
-  x: number
-}
+interface I { x: number }
 
 var i = new I(); // error
 function testInterfaceName(o: I) {
@@ -90,12 +84,8 @@ var e: E<number> = { x: \"\", y: \"\", z: \"\" }; // error: x and z should be nu
 (e.y: string);
 (e.z: string); // error: z is number
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-interface I {
-  y: string
-}
-interface I_ {
-  x: number
-}
+interface I { y: string }
+interface I_ { x: number }
 interface J extends I, I_ {}
 interface K extends J {}
 
@@ -103,21 +93,13 @@ var k: K = { x: \"\", y: \"\" }; // error: x should be number
 (k.x: string); // error: x is number
 (k.y: string);
 
-declare class C {
-  x: number
-}
+declare class C { x: number }
 declare class D extends C, Other {} // error: multiple extends
 //declare class E implements I { } // parse error
 
-interface A<Y> {
-  y: Y
-}
-interface A_<X> {
-  x: X
-}
-interface B<Z> extends A<string>, A_<Z> {
-  z: Z
-}
+interface A<Y> { y: Y }
+interface A_<X> { x: X }
+interface B<Z> extends A<string>, A_<Z> { z: Z }
 interface E<Z> extends B<Z> {}
 
 var e: E<number> = { x: \"\", y: \"\", z: \"\" }; // error: x and z should be numbers
@@ -141,9 +123,7 @@ function bar(m: M) { m.x; m.y; m.z; } // OK
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 import type { J } from \"./import\";
 interface K {}
-interface L extends J, K {
-  y: string
-}
+interface L extends J, K { y: string }
 
 function foo(l: L) {
   l.x;
@@ -151,12 +131,7 @@ function foo(l: L) {
   l.z;
 } // error: z not found in L
 // interface + multiple inheritance is similar to object type + intersection
-type M =
-  & { y: string }
-  & J
-  & {
-    z: boolean
-  };
+type M = { y: string } & J & { z: boolean };
 
 function bar(m: M) {
   m.x;
@@ -175,13 +150,8 @@ function foo(k: K) {
   (k.y: number); // error: y is string in I
 }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-interface I {
-  x: number,
-  y: string
-}
-interface J {
-  y: number
-}
+interface I { x: number, y: string }
+interface J { y: number }
 interface K extends I, J { x: string } // error: x is number in I
 function foo(k: K) {
   (k.x: number); // error: x is string in K
@@ -201,9 +171,7 @@ declare class C {
 
 new C().bar((x: string) => { }); // error, number ~/~> string
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-interface I {
-  foo(x: number): void
-}
+interface I { foo(x: number): void }
 (function foo(x: number) {}: I); // error, property \`foo\` not found function
 declare class C {
   bar(i: I): void,
diff --git a/tests/flow/misc/__snapshots__/jsfmt.spec.js.snap b/tests/flow/misc/__snapshots__/jsfmt.spec.js.snap
index a1ca033cb..c3f2e0dbc 100644
--- a/tests/flow/misc/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/misc/__snapshots__/jsfmt.spec.js.snap
@@ -147,9 +147,7 @@ module.exports = {obj: o};
 /* @providesModule E */
 
 function h(x: number) {}
-var proto = {
-  fn: h
-};
+var proto = { fn: h };
 
 var o = Object.create(proto);
 o.fn(false);
diff --git a/tests/flow/more_annot/__snapshots__/jsfmt.spec.js.snap b/tests/flow/more_annot/__snapshots__/jsfmt.spec.js.snap
index ddc7f1a59..dfcaa3e8a 100644
--- a/tests/flow/more_annot/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/more_annot/__snapshots__/jsfmt.spec.js.snap
@@ -21,9 +21,7 @@ o3.w = o2;
 module.exports = o3;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 var o1 = { x: 0, y: \"\" };
-var o2 = {
-  z: o1
-};
+var o2 = { z: o1 };
 
 var o3 = {};
 o3.w = o2;
diff --git a/tests/flow/more_path/__snapshots__/jsfmt.spec.js.snap b/tests/flow/more_path/__snapshots__/jsfmt.spec.js.snap
index a22be5dea..906d88c37 100644
--- a/tests/flow/more_path/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/more_path/__snapshots__/jsfmt.spec.js.snap
@@ -107,9 +107,7 @@ function goofy() {
 }
 
 function goofy2() {
-  var o = {
-    x: 0
-  };
+  var o = { x: 0 };
   if (typeof o.x == \"function\") {
     o.x();
   }
diff --git a/tests/flow/new_react/__snapshots__/jsfmt.spec.js.snap b/tests/flow/new_react/__snapshots__/jsfmt.spec.js.snap
index 6388d9faf..2fee90617 100644
--- a/tests/flow/new_react/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/new_react/__snapshots__/jsfmt.spec.js.snap
@@ -174,13 +174,8 @@ class C6 extends React.Component { // OK, recommended
 var React = require(\"React\");
 
 type T1 = {};
-type T2 = {
-  x: number
-};
-type T3 = {
-  x: number,
-  y: number
-};
+type T2 = { x: number };
+type T3 = { x: number, y: number };
 
 class C1
   extends React.Component<T1, T2, any> {} // error
@@ -561,10 +556,7 @@ var TestProps = React.createClass({
     z: React.PropTypes.number
   },
   getDefaultProps: function() {
-    return {
-      x: \"\",
-      y: 0
-    };
+    return { x: \"\", y: 0 };
   },
   test: function() {
     var a: number = this.props.x; // error
@@ -577,9 +569,7 @@ var element = <TestProps x={false} y={false} z={false} />; // 3 errors
 (element: $jsx<*>);
 (element: $jsx<TestProps>);
 var FooProps = React.createClass({
-  propTypes: {
-    w: React.PropTypes.string.isRequired
-  }
+  propTypes: { w: React.PropTypes.string.isRequired }
 });
 (element: $jsx<FooProps>);
 "
diff --git a/tests/flow/object_api/__snapshots__/jsfmt.spec.js.snap b/tests/flow/object_api/__snapshots__/jsfmt.spec.js.snap
index 06e130f9c..cd2dc015c 100644
--- a/tests/flow/object_api/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/object_api/__snapshots__/jsfmt.spec.js.snap
@@ -104,9 +104,7 @@ class C {
 ({ foo: \"foo\" }: C);
 
 // error, object types don\'t structurally match instances
-type O = {
-  foo: string
-};
+type O = { foo: string };
 declare var o: O;
 (o: C);
 "
diff --git a/tests/flow/poly_overload/decls/__snapshots__/jsfmt.spec.js.snap b/tests/flow/poly_overload/decls/__snapshots__/jsfmt.spec.js.snap
index c979e0522..b6eae8e73 100644
--- a/tests/flow/poly_overload/decls/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/poly_overload/decls/__snapshots__/jsfmt.spec.js.snap
@@ -17,13 +17,9 @@ interface B<X> extends A<X> {
 }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 interface Some<X> {}
-interface Other<X> {
-  x: X
-}
+interface Other<X> { x: X }
 interface None<Y> {}
-interface Nada<Y> {
-  y: Y
-}
+interface Nada<Y> { y: Y }
 interface A<X> {
   foo<Y>(s: Some<X>, e: None<Y>): A<Y>,
   foo<Y>(s: Some<X>, e: Nada<Y>): A<Y>,
diff --git a/tests/flow/predicates-abstract/__snapshots__/jsfmt.spec.js.snap b/tests/flow/predicates-abstract/__snapshots__/jsfmt.spec.js.snap
index 2ce06f280..745490772 100644
--- a/tests/flow/predicates-abstract/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/predicates-abstract/__snapshots__/jsfmt.spec.js.snap
@@ -60,26 +60,11 @@ declare function my_filter<T, P: $Pred<1>>(
   cb: P
 ): Array<$Refine<T, P, 1>>;
 
-type A = {
-  kind: \"A\",
-  u: number
-};
-type B = {
-  kind: \"B\",
-  v: string
-};
-type C = {
-  kind: \"C\",
-  y: boolean
-};
-type D = {
-  kind: \"D\",
-  x: boolean
-};
-type E = {
-  kind: \"E\",
-  y: boolean
-};
+type A = { kind: \"A\", u: number };
+type B = { kind: \"B\", v: string };
+type C = { kind: \"C\", y: boolean };
+type D = { kind: \"D\", x: boolean };
+type E = { kind: \"E\", y: boolean };
 
 declare var ab: Array<A | B | C>;
 
@@ -267,26 +252,11 @@ declare function my_filter<T, P: $Pred<1>>(
   cb: P
 ): Array<$Refine<T, P, 1>>;
 
-type A = {
-  kind: \"A\",
-  u: number
-};
-type B = {
-  kind: \"B\",
-  v: string
-};
-type C = {
-  kind: \"C\",
-  y: boolean
-};
-type D = {
-  kind: \"D\",
-  x: boolean
-};
-type E = {
-  kind: \"E\",
-  y: boolean
-};
+type A = { kind: \"A\", u: number };
+type B = { kind: \"B\", v: string };
+type C = { kind: \"C\", y: boolean };
+type D = { kind: \"D\", x: boolean };
+type E = { kind: \"E\", y: boolean };
 
 declare var ab: Array<A | B | C>;
 
diff --git a/tests/flow/rec/__snapshots__/jsfmt.spec.js.snap b/tests/flow/rec/__snapshots__/jsfmt.spec.js.snap
index 99ef8606b..b85049610 100644
--- a/tests/flow/rec/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/rec/__snapshots__/jsfmt.spec.js.snap
@@ -21,9 +21,7 @@ function identity<A>(val: A): Functor<A> {
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 /* @flow */
 
-type F<A> = {
-  foo<B>(x: A): F<B>
-};
+type F<A> = { foo<B>(x: A): F<B> };
 declare function foo(x: any): F<any>;
 ({ foo }: F<any>);
 
@@ -204,9 +202,7 @@ function foo(x: I<number>): J<number> {
   // I<number> and J<number> both expand to () => () => ...
 }
 
-type Q<X> = {
-  x: X
-};
+type Q<X> = { x: X };
 type P<X> = () => Q<P<X>>;
 
 function bar(x: P<number>): () => P<number> {
diff --git a/tests/flow/recheck/__snapshots__/jsfmt.spec.js.snap b/tests/flow/recheck/__snapshots__/jsfmt.spec.js.snap
index 11e17f61a..1d76eff3e 100644
--- a/tests/flow/recheck/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/recheck/__snapshots__/jsfmt.spec.js.snap
@@ -208,13 +208,7 @@ export const LIFE = 42;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // @flow
 
-export type Action =
-  | {
-    type: \"FOO\"
-  }
-  | {
-    type: \"BAR\"
-  };
+export type Action = { type: \"FOO\" } | { type: \"BAR\" };
 
 export const LIFE = 42;
 "
diff --git a/tests/flow/recheck/tmp2e/__snapshots__/jsfmt.spec.js.snap b/tests/flow/recheck/tmp2e/__snapshots__/jsfmt.spec.js.snap
index b82e5435d..5cd4c3eef 100644
--- a/tests/flow/recheck/tmp2e/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/recheck/tmp2e/__snapshots__/jsfmt.spec.js.snap
@@ -10,13 +10,7 @@ export const LIFE = 42;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // @flow
 
-export type Action =
-  | {
-    type: \"QUX\"
-  }
-  | {
-    type: \"BAR\"
-  };
+export type Action = { type: \"QUX\" } | { type: \"BAR\" };
 
 export const LIFE = 42;
 "
diff --git a/tests/flow/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap b/tests/flow/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap
index dc3fbcf8d..6e7d6813c 100644
--- a/tests/flow/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap
@@ -10,13 +10,7 @@ export const LIFE = 0;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // @flow
 
-export type Action =
-  | {
-    type: \"QUX\"
-  }
-  | {
-    type: \"BAR\"
-  };
+export type Action = { type: \"QUX\" } | { type: \"BAR\" };
 
 export const LIFE = 0;
 "
diff --git a/tests/flow/refinements/__snapshots__/jsfmt.spec.js.snap b/tests/flow/refinements/__snapshots__/jsfmt.spec.js.snap
index d06f2eb93..e647de055 100644
--- a/tests/flow/refinements/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/refinements/__snapshots__/jsfmt.spec.js.snap
@@ -318,15 +318,7 @@ let tests = [
     return x.result; // error
   },
   function() {
-    type T =
-      | {
-        foo: Object,
-        bar: string
-      }
-      | {
-        baz: string,
-        quux: string
-      };
+    type T = { foo: Object, bar: string } | { baz: string, quux: string };
 
     function testAlwaysTruthyProp(t: T) {
       if (t.foo) {
@@ -615,9 +607,7 @@ function def_assign_setprop_nohavoc(obj: Obj, obj2: Obj2) {
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // @flow
 
-type Obj = {
-  p: number | string
-};
+type Obj = { p: number | string };
 
 function f() {}
 
@@ -692,9 +682,7 @@ function def_assign_within_for(b: boolean, obj: Obj) {
 
 // --- name-sensitive havoc ---
 
-type Obj2 = {
-  q: number | string
-};
+type Obj2 = { q: number | string };
 
 function def_assign_setprop_nohavoc(obj: Obj, obj2: Obj2) {
   obj.p = 10; // (obj.p : number)
@@ -1403,14 +1391,7 @@ let tests = [
     }
     return x.foo; // error
   },
-  function(
-    x:
-      | { kind: 0, foo: number }
-      | {
-        kind: 1,
-        bar: number
-      }
-  ): number {
+  function(x: { kind: 0, foo: number } | { kind: 1, bar: number }): number {
     if (x.kind === 0) {
       return x.foo;
     } else {
@@ -1993,12 +1974,7 @@ let tests = [
     return x.foo; // error
   },
   function(
-    x:
-      | { kind: \"foo\", foo: string }
-      | {
-        kind: \"bar\",
-        bar: string
-      }
+    x: { kind: \"foo\", foo: string } | { kind: \"bar\", bar: string }
   ): string {
     if (x.kind === \"foo\") {
       return x.foo;
@@ -2493,24 +2469,10 @@ function foo(x: ASTNode) {
 }
 
 // example 3
-type Apple = {
-  kind: \"Fruit\",
-  taste: \"Bad\"
-};
-type Orange = {
-  kind: \"Fruit\",
-  taste: \"Good\"
-};
-type Broccoli = {
-  kind: \"Veg\",
-  taste: \"Bad\",
-  raw: \"No\"
-};
-type Carrot = {
-  kind: \"Veg\",
-  taste: \"Good\",
-  raw: \"Maybe\"
-};
+type Apple = { kind: \"Fruit\", taste: \"Bad\" };
+type Orange = { kind: \"Fruit\", taste: \"Good\" };
+type Broccoli = { kind: \"Veg\", taste: \"Bad\", raw: \"No\" };
+type Carrot = { kind: \"Veg\", taste: \"Good\", raw: \"Maybe\" };
 
 type Breakfast = Apple | Orange | Broccoli | Carrot;
 
@@ -2566,10 +2528,7 @@ kind({ kind: EnumKind.A, A: 1 });
 
 // example 6
 type Citizen = { citizen: true };
-type NonCitizen = {
-  citizen: false,
-  nationality: string
-};
+type NonCitizen = { citizen: false, nationality: string };
 function nationality(x: Citizen | NonCitizen) {
   if (x.citizen) return \"Shire\";
   else return x.nationality;
diff --git a/tests/flow/spread/__snapshots__/jsfmt.spec.js.snap b/tests/flow/spread/__snapshots__/jsfmt.spec.js.snap
index c1ae11a20..c3ad5a3e3 100644
--- a/tests/flow/spread/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/spread/__snapshots__/jsfmt.spec.js.snap
@@ -182,9 +182,7 @@ declare function map<Tv, TNext>(
  */
 function test(
   x: { kind: ?string },
-  kinds: {
-    [key: string]: string
-  }
+  kinds: { [key: string]: string }
 ): Array<{ kind: ?string }> {
   return map(kinds, value => {
     (value: string); // OK
diff --git a/tests/flow/strict/__snapshots__/jsfmt.spec.js.snap b/tests/flow/strict/__snapshots__/jsfmt.spec.js.snap
index 11bee00bc..4f3e6ecc0 100644
--- a/tests/flow/strict/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/strict/__snapshots__/jsfmt.spec.js.snap
@@ -78,9 +78,7 @@ module.exports = o;
 
 // progressively annotate:
 
-var o = {
-  x: 0
-};
+var o = { x: 0 };
 //var o: {x: number;} = { x: 0 }
 
 var x: string = o.x;
diff --git a/tests/flow/strict_requires/__snapshots__/jsfmt.spec.js.snap b/tests/flow/strict_requires/__snapshots__/jsfmt.spec.js.snap
index 46485a833..46809f4b0 100644
--- a/tests/flow/strict_requires/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/strict_requires/__snapshots__/jsfmt.spec.js.snap
@@ -12,9 +12,7 @@ exports[`test B.js 1`] = `
 module.exports = { foo: \"\" }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 /* @flow */
-module.exports = {
-  foo: \"\"
-};
+module.exports = { foo: \"\" };
 "
 `;
 
diff --git a/tests/flow/structural_subtyping/__snapshots__/jsfmt.spec.js.snap b/tests/flow/structural_subtyping/__snapshots__/jsfmt.spec.js.snap
index 1040b11d2..6fc23553c 100644
--- a/tests/flow/structural_subtyping/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/structural_subtyping/__snapshots__/jsfmt.spec.js.snap
@@ -144,9 +144,7 @@ interface HasOptional {
   b?: number
 }
 
-var test1: HasOptional = {
-  a: \"hello\"
-};
+var test1: HasOptional = { a: \"hello\" };
 
 var test2: HasOptional = {}; // Error: missing property a
 var test3: HasOptional = { a: \"hello\", b: true }; // Error: boolean ~> number
diff --git a/tests/flow/symlink/__snapshots__/jsfmt.spec.js.snap b/tests/flow/symlink/__snapshots__/jsfmt.spec.js.snap
index 1279e8650..36cbc18c3 100644
--- a/tests/flow/symlink/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/symlink/__snapshots__/jsfmt.spec.js.snap
@@ -1,18 +1,14 @@
 exports[`test bar.js 1`] = `
 "export type Foo = { x: number; }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-export type Foo = {
-  x: number
-};
+export type Foo = { x: number };
 "
 `;
 
 exports[`test foo.js 1`] = `
 "export type Foo = { x: number; }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-export type Foo = {
-  x: number
-};
+export type Foo = { x: number };
 "
 `;
 
diff --git a/tests/flow/this_type/__snapshots__/jsfmt.spec.js.snap b/tests/flow/this_type/__snapshots__/jsfmt.spec.js.snap
index 19b73229d..1d0c90a21 100644
--- a/tests/flow/this_type/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/this_type/__snapshots__/jsfmt.spec.js.snap
@@ -267,12 +267,8 @@ class C {
 function foo(c: C): I { return c; }
 function bar(c: C): J { return c; }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-interface I {
-  xs: Array<this>
-}
-interface J {
-  f(): J
-}
+interface I { xs: Array<this> }
+interface J { f(): J }
 class C {
   xs: Array<C>;
   f(): C {
diff --git a/tests/flow/traces/__snapshots__/jsfmt.spec.js.snap b/tests/flow/traces/__snapshots__/jsfmt.spec.js.snap
index 8c8f0e9dd..6729365f8 100644
--- a/tests/flow/traces/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/traces/__snapshots__/jsfmt.spec.js.snap
@@ -81,15 +81,11 @@ function f(b): React.Element<*> {
 var React = require(\"react\");
 
 var A = React.createClass({
-  propTypes: {
-    foo: React.PropTypes.string.isRequired
-  }
+  propTypes: { foo: React.PropTypes.string.isRequired }
 });
 
 var B = React.createClass({
-  propTypes: {
-    bar: React.PropTypes.string.isRequired
-  }
+  propTypes: { bar: React.PropTypes.string.isRequired }
 });
 
 function f(b): React.Element<*> {
diff --git a/tests/flow/union_new/__snapshots__/jsfmt.spec.js.snap b/tests/flow/union_new/__snapshots__/jsfmt.spec.js.snap
index 881629e3d..6253dfb49 100644
--- a/tests/flow/union_new/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/union_new/__snapshots__/jsfmt.spec.js.snap
@@ -121,9 +121,7 @@ var bar: Array<{b: ?boolean, c: number} | {b: boolean}> = [
 
 var bar: Array<{ b: ?boolean, c: number } | { b: boolean }> = [
   { b: true, c: 123 },
-  {
-    b: true
-  }
+  { b: true }
 ];
 "
 `;
@@ -139,12 +137,7 @@ exports[`test issue-1371.js 1`] = `
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 function create(
   a: any
-):
-  | { type: \"B\", data: number }
-  | {
-    type: \"A\",
-    data: string
-  } {
+): { type: \"B\", data: number } | { type: \"A\", data: string } {
   return {
     type: \"A\",
     data: a
@@ -692,9 +685,7 @@ type B3 = string;
 function alias(a: T<number> | T<string>) {}
 alias({ x: (x: V<B4>) => {} });
 
-type T<X> = {
-  x: U<X>
-};
+type T<X> = { x: U<X> };
 type U<X> = (x: V<X>) => void;
 type V<X> = X;
 
@@ -1347,16 +1338,9 @@ function rec(x: F<string>): G | H { return x; }
 
 // polymorphic recursive types
 
-type F<X> = {
-  f: F<X>,
-  x: X
-};
-type G = {
-  x: number
-};
-type H = {
-  x: string
-};
+type F<X> = { f: F<X>, x: X };
+type G = { x: number };
+type H = { x: string };
 
 function rec(x: F<string>): G | H {
   return x;
@@ -1659,15 +1643,7 @@ function str() {
 
 // annotations for disjoint unions
 
-type T =
-  | {
-    type: \"FOO\",
-    x: number
-  }
-  | {
-    type: \"BAR\",
-    x: string
-  };
+type T = { type: \"FOO\", x: number } | { type: \"BAR\", x: string };
 
 ({ type: (bar(): \"BAR\"), x: str() }: T);
 
@@ -2037,15 +2013,7 @@ type ActionType =
 
 const Constants = require(\"./test30-helper\");
 
-type ActionType =
-  | {
-    type: \"foo\",
-    x: number
-  }
-  | {
-    type: \"bar\",
-    x: number
-  };
+type ActionType = { type: \"foo\", x: number } | { type: \"bar\", x: number };
 
 ({ type: Constants.BAR, x: 0 }: ActionType);
 "
diff --git a/tests/interface/__snapshots__/jsfmt.spec.js.snap b/tests/interface/__snapshots__/jsfmt.spec.js.snap
index 0fbad8e1e..a08e29fc9 100644
--- a/tests/interface/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/interface/__snapshots__/jsfmt.spec.js.snap
@@ -4,9 +4,7 @@ exports[`test module.js 1`] = `
 }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 declare module X {
-  declare interface Y {
-    x: number
-  }
+  declare interface Y { x: number }
 }
 "
 `;
diff --git a/tests/object-prop-break-in/__snapshots__/jsfmt.spec.js.snap b/tests/object-prop-break-in/__snapshots__/jsfmt.spec.js.snap
index 2ac75f445..1bc4417f6 100644
--- a/tests/object-prop-break-in/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/object-prop-break-in/__snapshots__/jsfmt.spec.js.snap
@@ -50,13 +50,7 @@ const e = classnames({
 });
 
 const f = classnames({
-  \"some-prop\": {
-    foo: \"bar\",
-    bar: \"foo\",
-    foo: \"bar\",
-    bar: \"foo\",
-    foo: \"bar\"
-  }
+  \"some-prop\": { foo: \"bar\", bar: \"foo\", foo: \"bar\", bar: \"foo\", foo: \"bar\" }
 });
 
 const g = classnames({
diff --git a/tests/objects/__snapshots__/jsfmt.spec.js.snap b/tests/objects/__snapshots__/jsfmt.spec.js.snap
index 9cdd3c307..1e685b099 100644
--- a/tests/objects/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/objects/__snapshots__/jsfmt.spec.js.snap
@@ -8,3 +8,34 @@ a = () => ({}).x;
 a = () => ({}).x;
 "
 `;
+
+exports[`test range.js 1`] = `
+"group(
+  concat([
+    \"(\",
+    indent(
+      options.tabWidth,
+      concat([line, join(concat([\",\", line]), printed)])
+    ),
+    options.trailingComma ? \",\" : \"\",
+    line,
+    \")\"
+  ]),
+  {shouldBreak: true}
+)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+group(
+  concat([
+    \"(\",
+    indent(
+      options.tabWidth,
+      concat([line, join(concat([\",\", line]), printed)])
+    ),
+    options.trailingComma ? \",\" : \"\",
+    line,
+    \")\"
+  ]),
+  { shouldBreak: true }
+);
+"
+`;
diff --git a/tests/objects/range.js b/tests/objects/range.js
new file mode 100644
index 000000000..025fa5dc8
--- /dev/null
+++ b/tests/objects/range.js
@@ -0,0 +1,13 @@
+group(
+  concat([
+    "(",
+    indent(
+      options.tabWidth,
+      concat([line, join(concat([",", line]), printed)])
+    ),
+    options.trailingComma ? "," : "",
+    line,
+    ")"
+  ]),
+  {shouldBreak: true}
+)
diff --git a/tests/optional-type-name/__snapshots__/jsfmt.spec.js.snap b/tests/optional-type-name/__snapshots__/jsfmt.spec.js.snap
index a4671d263..da002101d 100644
--- a/tests/optional-type-name/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/optional-type-name/__snapshots__/jsfmt.spec.js.snap
@@ -5,8 +5,6 @@ type Bar = { [string]: number }
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 type Foo = (any) => string;
 
-type Bar = {
-  [string]: number
-};
+type Bar = { [string]: number };
 "
 `;
diff --git a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap
index fa616b993..84f0402ff 100644
--- a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap
@@ -19,12 +19,7 @@ const obj1 = conditionIsTruthy
 
 const obj2 = conditionIsTruthy
   ? shortThing
-  : {
-      some: \"long\",
-      object: \"with\",
-      lots: \"of\",
-      stuff
-    };
+  : { some: \"long\", object: \"with\", lots: \"of\", stuff };
 
 const obj3 = conditionIsTruthy
   ? {