diff --git a/src/util.js b/src/util.js index 1b223968..87b076cb 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; } diff --git a/tests/bracketSpacing/__snapshots__/jsfmt.spec.js.snap b/tests/bracketSpacing/__snapshots__/jsfmt.spec.js.snap index cd4bc1fb..12dda276 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 c1b6751b..54e28169 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 a2fda17b..c1c8c54e 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 2325655c..4a1e783c 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 6a88c1ec..e7a38750 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 e524a9cd..c830a4f5 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 23de2090..0481d54c 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 a41597fa..e1b60654 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 d18bb02b..0eb5e3ed 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 = { 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 -} -interface A_ { - x: X -} -interface B extends A, A_ { - z: Z -} +interface A { y: Y } +interface A_ { x: X } +interface B extends A, A_ { z: Z } interface E extends B {} var e: E = { 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 a1ca033c..c3f2e0db 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 ddc7f1a5..dfcaa3e8 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 a22be5de..906d88c3 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 6388d9fa..2fee9061 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 {} // 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 = ; // 3 errors (element: $jsx<*>); (element: $jsx); var FooProps = React.createClass({ - propTypes: { - w: React.PropTypes.string.isRequired - } + propTypes: { w: React.PropTypes.string.isRequired } }); (element: $jsx); " diff --git a/tests/flow/object_api/__snapshots__/jsfmt.spec.js.snap b/tests/flow/object_api/__snapshots__/jsfmt.spec.js.snap index 06e130f9..cd2dc015 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 c979e052..b6eae8e7 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 extends A { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ interface Some {} -interface Other { - x: X -} +interface Other { x: X } interface None {} -interface Nada { - y: Y -} +interface Nada { y: Y } interface A { foo(s: Some, e: None): A, foo(s: Some, e: Nada): A, diff --git a/tests/flow/predicates-abstract/__snapshots__/jsfmt.spec.js.snap b/tests/flow/predicates-abstract/__snapshots__/jsfmt.spec.js.snap index 2ce06f28..74549077 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>( cb: P ): Array<$Refine>; -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; @@ -267,26 +252,11 @@ declare function my_filter>( cb: P ): Array<$Refine>; -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; diff --git a/tests/flow/rec/__snapshots__/jsfmt.spec.js.snap b/tests/flow/rec/__snapshots__/jsfmt.spec.js.snap index 99ef8606..b8504961 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(val: A): Functor { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ -type F = { - foo(x: A): F -}; +type F = { foo(x: A): F }; declare function foo(x: any): F; ({ foo }: F); @@ -204,9 +202,7 @@ function foo(x: I): J { // I and J both expand to () => () => ... } -type Q = { - x: X -}; +type Q = { x: X }; type P = () => Q>; function bar(x: P): () => P { diff --git a/tests/flow/recheck/__snapshots__/jsfmt.spec.js.snap b/tests/flow/recheck/__snapshots__/jsfmt.spec.js.snap index 11e17f61..1d76eff3 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 b82e5435..5cd4c3ee 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 dc3fbcf8..6e7d6813 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 d06f2eb9..e647de05 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 c1ae11a2..c3ad5a3e 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( */ 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 11bee00b..4f3e6ecc 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 46485a83..46809f4b 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 1040b11d..6fc23553 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 1279e865..36cbc18c 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 19b73229..1d0c90a2 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 -} -interface J { - f(): J -} +interface I { xs: Array } +interface J { f(): J } class C { xs: Array; f(): C { diff --git a/tests/flow/traces/__snapshots__/jsfmt.spec.js.snap b/tests/flow/traces/__snapshots__/jsfmt.spec.js.snap index 8c8f0e9d..6729365f 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 881629e3..6253dfb4 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 | T) {} alias({ x: (x: V) => {} }); -type T = { - x: U -}; +type T = { x: U }; type U = (x: V) => void; type V = X; @@ -1347,16 +1338,9 @@ function rec(x: F): G | H { return x; } // polymorphic recursive types -type F = { - f: F, - x: X -}; -type G = { - x: number -}; -type H = { - x: string -}; +type F = { f: F, x: X }; +type G = { x: number }; +type H = { x: string }; function rec(x: F): 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 0fbad8e1..a08e29fc 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 2ac75f44..1bc4417f 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 9cdd3c30..1e685b09 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 00000000..025fa5dc --- /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 a4671d26..da002101 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 fa616b99..84f0402f 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 ? {