From 8ad3aeff6ac693690b1ad4374fdc43dea4c4c433 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 20 May 2017 12:16:28 +0200 Subject: [PATCH] Sync the Flow tests (#1638) --- tests/flow/bom/FormData.js | 2 +- .../flow/bom/__snapshots__/jsfmt.spec.js.snap | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- tests/flow/constructor_annots/constructors.js | 1 + .../date/__snapshots__/jsfmt.spec.js.snap | 8 +-- tests/flow/date/date.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 12 +++- tests/flow/declare_class/declare_class.js | 5 ++ tests/flow/dom/Document.js | 1 + .../flow/dom/__snapshots__/jsfmt.spec.js.snap | 2 + .../fetch/__snapshots__/jsfmt.spec.js.snap | 70 ++++++++++--------- tests/flow/fetch/headers.js | 6 +- tests/flow/fetch/request.js | 12 ++-- tests/flow/fetch/response.js | 12 ++-- tests/flow/fetch/urlsearchparams.js | 5 ++ .../function/__snapshots__/jsfmt.spec.js.snap | 6 ++ tests/flow/function/rest.js | 3 + .../get-def2/__snapshots__/jsfmt.spec.js.snap | 2 + tests/flow/get-def2/main.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 22 ++++++ .../jsfmt.spec.js | 0 tests/flow/include_suppressed/test.js | 8 +++ .../__snapshots__/jsfmt.spec.js.snap | 18 +++++ tests/flow/malformed_code/jsfmt.spec.js | 1 + tests/flow/malformed_code/text.js | 6 ++ .../__snapshots__/jsfmt.spec.js.snap | 8 +-- tests/flow/multiflow/spread.js | 4 +- .../buffer/__snapshots__/jsfmt.spec.js.snap | 16 ++--- tests/flow/node_tests/buffer/buffer.js | 8 +-- .../process/__snapshots__/jsfmt.spec.js.snap | 57 +++++++++++++++ tests/flow/node_tests/process/jsfmt.spec.js | 1 + tests/flow/node_tests/process/nextTick.js | 28 ++++++++ .../__snapshots__/jsfmt.spec.js.snap | 42 ----------- .../objectTypeProperty/objectTypeProperty.js | 18 ----- .../__snapshots__/jsfmt.spec.js.snap | 4 +- tests/flow/object_is/object_is.js | 2 +- .../promises/__snapshots__/jsfmt.spec.js.snap | 12 ++-- tests/flow/promises/promise.js | 6 +- .../recheck/__snapshots__/jsfmt.spec.js.snap | 7 ++ tests/flow/recheck/k.js | 1 + .../tmpk/__snapshots__/jsfmt.spec.js.snap | 14 ++++ tests/flow/recheck/tmpk/jsfmt.spec.js | 1 + tests/flow/recheck/tmpk/k.js | 4 ++ .../tmplibk/__snapshots__/jsfmt.spec.js.snap | 19 +++++ tests/flow/recheck/tmplibk/jsfmt.spec.js | 1 + tests/flow/recheck/tmplibk/libk1.js | 1 + tests/flow/recheck/tmplibk/libk2.js | 3 + .../require/__snapshots__/jsfmt.spec.js.snap | 4 +- tests/flow/require/not_builtin_require.js | 2 +- .../symbol/__snapshots__/jsfmt.spec.js.snap | 6 +- tests/flow/symbol/symbol.js | 3 +- .../lib/__snapshots__/jsfmt.spec.js.snap | 4 +- tests/flow/union_new/lib/test25_lib.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 54 ++++++++++++++ tests/flow/unused_function_args/jsfmt.spec.js | 1 + tests/flow/unused_function_args/test.js | 24 +++++++ 56 files changed, 405 insertions(+), 167 deletions(-) create mode 100644 tests/flow/include_suppressed/__snapshots__/jsfmt.spec.js.snap rename tests/flow/{objectTypeProperty => include_suppressed}/jsfmt.spec.js (100%) create mode 100644 tests/flow/include_suppressed/test.js create mode 100644 tests/flow/malformed_code/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/flow/malformed_code/jsfmt.spec.js create mode 100644 tests/flow/malformed_code/text.js create mode 100644 tests/flow/node_tests/process/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/flow/node_tests/process/jsfmt.spec.js create mode 100644 tests/flow/node_tests/process/nextTick.js delete mode 100644 tests/flow/objectTypeProperty/__snapshots__/jsfmt.spec.js.snap delete mode 100644 tests/flow/objectTypeProperty/objectTypeProperty.js create mode 100644 tests/flow/recheck/k.js create mode 100644 tests/flow/recheck/tmpk/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/flow/recheck/tmpk/jsfmt.spec.js create mode 100644 tests/flow/recheck/tmpk/k.js create mode 100644 tests/flow/recheck/tmplibk/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/flow/recheck/tmplibk/jsfmt.spec.js create mode 100644 tests/flow/recheck/tmplibk/libk1.js create mode 100644 tests/flow/recheck/tmplibk/libk2.js create mode 100644 tests/flow/unused_function_args/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/flow/unused_function_args/jsfmt.spec.js create mode 100644 tests/flow/unused_function_args/test.js diff --git a/tests/flow/bom/FormData.js b/tests/flow/bom/FormData.js index 79db7648..b369cd95 100644 --- a/tests/flow/bom/FormData.js +++ b/tests/flow/bom/FormData.js @@ -39,7 +39,7 @@ a.append('foo', 'bar'); // correct a.append('foo', {}); // incorrect a.append(2, 'bar'); // incorrect a.append('foo', 'bar', 'baz'); // incorrect -a.append('foo', 'bar'); // incorrect +a.append('foo', 'bar'); // correct a.append('bar', new File([], 'q')) // correct a.append('bar', new File([], 'q'), 'x') // correct a.append('bar', new File([], 'q'), 2) // incorrect diff --git a/tests/flow/bom/__snapshots__/jsfmt.spec.js.snap b/tests/flow/bom/__snapshots__/jsfmt.spec.js.snap index 2072362e..97875572 100644 --- a/tests/flow/bom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/bom/__snapshots__/jsfmt.spec.js.snap @@ -42,7 +42,7 @@ a.append('foo', 'bar'); // correct a.append('foo', {}); // incorrect a.append(2, 'bar'); // incorrect a.append('foo', 'bar', 'baz'); // incorrect -a.append('foo', 'bar'); // incorrect +a.append('foo', 'bar'); // correct a.append('bar', new File([], 'q')) // correct a.append('bar', new File([], 'q'), 'x') // correct a.append('bar', new File([], 'q'), 2) // incorrect @@ -110,7 +110,7 @@ a.append("foo", "bar"); // correct a.append("foo", {}); // incorrect a.append(2, "bar"); // incorrect a.append("foo", "bar", "baz"); // incorrect -a.append("foo", "bar"); // incorrect +a.append("foo", "bar"); // correct a.append("bar", new File([], "q")); // correct a.append("bar", new File([], "q"), "x"); // correct a.append("bar", new File([], "q"), 2); // incorrect diff --git a/tests/flow/constructor_annots/__snapshots__/jsfmt.spec.js.snap b/tests/flow/constructor_annots/__snapshots__/jsfmt.spec.js.snap index 93f93e4c..11519b4e 100644 --- a/tests/flow/constructor_annots/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/constructor_annots/__snapshots__/jsfmt.spec.js.snap @@ -20,6 +20,7 @@ interface IFoo extends IFooPrototype { x: boolean; // error, should have declared x: number instead static (): void; static y: boolean; // error, should have declared static y: number instead + constructor(): void; } exports.Foo2 = (Foo: Class); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -45,7 +46,8 @@ interface IFooPrototype { interface IFoo extends IFooPrototype { x: boolean, // error, should have declared x: number instead static (): void, - static y: boolean // error, should have declared static y: number instead + static y: boolean, // error, should have declared static y: number instead + constructor(): void } exports.Foo2 = (Foo: Class); diff --git a/tests/flow/constructor_annots/constructors.js b/tests/flow/constructor_annots/constructors.js index dac947e6..d7bfe938 100644 --- a/tests/flow/constructor_annots/constructors.js +++ b/tests/flow/constructor_annots/constructors.js @@ -17,5 +17,6 @@ interface IFoo extends IFooPrototype { x: boolean; // error, should have declared x: number instead static (): void; static y: boolean; // error, should have declared static y: number instead + constructor(): void; } exports.Foo2 = (Foo: Class); diff --git a/tests/flow/date/__snapshots__/jsfmt.spec.js.snap b/tests/flow/date/__snapshots__/jsfmt.spec.js.snap index 7d9d0790..5267b471 100644 --- a/tests/flow/date/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/date/__snapshots__/jsfmt.spec.js.snap @@ -25,10 +25,8 @@ new Date(2015, 6, 18, '11'); new Date(2015, 6, 18, 11, '55'); new Date(2015, 6, 18, 11, 55, '42'); new Date(2015, 6, 18, 11, 55, 42, '999'); - -// invalid constructors that we incorrectly consider valid -new Date('2015', 6); new Date(2015, 6, 18, 11, 55, 42, 999, 'hahaha'); +new Date('2015', 6); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var d = new Date(0); var x: string = d.getTime(); @@ -54,9 +52,7 @@ new Date(2015, 6, 18, "11"); new Date(2015, 6, 18, 11, "55"); new Date(2015, 6, 18, 11, 55, "42"); new Date(2015, 6, 18, 11, 55, 42, "999"); - -// invalid constructors that we incorrectly consider valid -new Date("2015", 6); new Date(2015, 6, 18, 11, 55, 42, 999, "hahaha"); +new Date("2015", 6); `; diff --git a/tests/flow/date/date.js b/tests/flow/date/date.js index dddd8aa0..0edf1189 100644 --- a/tests/flow/date/date.js +++ b/tests/flow/date/date.js @@ -22,7 +22,5 @@ new Date(2015, 6, 18, '11'); new Date(2015, 6, 18, 11, '55'); new Date(2015, 6, 18, 11, 55, '42'); new Date(2015, 6, 18, 11, 55, 42, '999'); - -// invalid constructors that we incorrectly consider valid -new Date('2015', 6); new Date(2015, 6, 18, 11, 55, 42, 999, 'hahaha'); +new Date('2015', 6); diff --git a/tests/flow/declare_class/__snapshots__/jsfmt.spec.js.snap b/tests/flow/declare_class/__snapshots__/jsfmt.spec.js.snap index 046e2d87..732907b3 100644 --- a/tests/flow/declare_class/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/declare_class/__snapshots__/jsfmt.spec.js.snap @@ -4,6 +4,8 @@ exports[`declare_class.js 1`] = ` declare class C { static x: number; static foo(x: number): void; + + constructor(x: string): void; } C.x = ""; @@ -11,10 +13,15 @@ C.foo(""); (C.name: string); (C.name: number); // error, it's a string + +declare class D extends C { } +new D(123); // error, number ~> string ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare class C { static x: number, - static foo(x: number): void + static foo(x: number): void, + + constructor(x: string): void } C.x = ""; @@ -23,4 +30,7 @@ C.foo(""); (C.name: string); (C.name: number); // error, it's a string +declare class D extends C {} +new D(123); // error, number ~> string + `; diff --git a/tests/flow/declare_class/declare_class.js b/tests/flow/declare_class/declare_class.js index 3096c97a..bd1867d2 100644 --- a/tests/flow/declare_class/declare_class.js +++ b/tests/flow/declare_class/declare_class.js @@ -1,6 +1,8 @@ declare class C { static x: number; static foo(x: number): void; + + constructor(x: string): void; } C.x = ""; @@ -8,3 +10,6 @@ C.foo(""); (C.name: string); (C.name: number); // error, it's a string + +declare class D extends C { } +new D(123); // error, number ~> string diff --git a/tests/flow/dom/Document.js b/tests/flow/dom/Document.js index 46d156e8..fa37d38f 100644 --- a/tests/flow/dom/Document.js +++ b/tests/flow/dom/Document.js @@ -8,5 +8,6 @@ let tests = [ (document.createElement('option'): HTMLOptionElement); (document.createElement('select'): HTMLSelectElement); (document.querySelector('select'): HTMLSelectElement | null); + (document.createElement('hr'): HTMLElement); // GH #3752 } ]; diff --git a/tests/flow/dom/__snapshots__/jsfmt.spec.js.snap b/tests/flow/dom/__snapshots__/jsfmt.spec.js.snap index a345eb37..ef4c45b1 100644 --- a/tests/flow/dom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/dom/__snapshots__/jsfmt.spec.js.snap @@ -65,6 +65,7 @@ let tests = [ (document.createElement('option'): HTMLOptionElement); (document.createElement('select'): HTMLSelectElement); (document.querySelector('select'): HTMLSelectElement | null); + (document.createElement('hr'): HTMLElement); // GH #3752 } ]; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -78,6 +79,7 @@ let tests = [ (document.createElement("option"): HTMLOptionElement); (document.createElement("select"): HTMLSelectElement); (document.querySelector("select"): HTMLSelectElement | null); + (document.createElement("hr"): HTMLElement); // GH #3752 } ]; diff --git a/tests/flow/fetch/__snapshots__/jsfmt.spec.js.snap b/tests/flow/fetch/__snapshots__/jsfmt.spec.js.snap index 2d7a1e2d..9524085a 100644 --- a/tests/flow/fetch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/fetch/__snapshots__/jsfmt.spec.js.snap @@ -81,7 +81,11 @@ for (let v of e.entries()) { const [i, j]: [string, string] = v; // correct } -e.getAll('content-type').forEach((v: string) => {}); // correct +e.getAll('content-type'); // incorrect +e.forEach((val: string) => val); // correct +e.forEach((val: string, key: string) => \`\${key}: \${val}\`); // correct +e.forEach((val: string, key: string, o: Headers) => {}); // correct +e.forEach(() => {}, {}); // correct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ @@ -110,7 +114,11 @@ for (let v of e.entries()) { const [i, j]: [string, string] = v; // correct } -e.getAll("content-type").forEach((v: string) => {}); // correct +e.getAll("content-type"); // incorrect +e.forEach((val: string) => val); // correct +e.forEach((val: string, key: string) => \`\${key}: \${val}\`); // correct +e.forEach((val: string, key: string, o: Headers) => {}); // correct +e.forEach(() => {}, {}); // correct `; @@ -124,6 +132,7 @@ const e: Request = new Request(b, c); // incorrect const f: Request = new Request({}) // incorrect const g: Request = new Request('http://example.org', {}) // correct +new Request(new URL('http://example.org')); // correct const h: Request = new Request('http://example.org', { method: 'GET', @@ -174,14 +183,9 @@ const l: Request = new Request('http://example.org', { cache: 'default' }) // incorrect - headers is string -const m: Request = new Request('http://example.org', { - method: 'CONNECT', - headers: { - 'Content-Type': 'image/jpeg' - }, - mode: 'cors', - cache: 'default' -}) // incorrect - CONNECT is forbidden +new Request('/', { method: 'post' }); // correct +new Request('/', { method: 'hello' }); // correct +new Request('/', { method: null }); // incorrect ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ const a: Request = new Request(); // incorrect @@ -192,6 +196,7 @@ const e: Request = new Request(b, c); // incorrect const f: Request = new Request({}); // incorrect const g: Request = new Request("http://example.org", {}); // correct +new Request(new URL("http://example.org")); // correct const h: Request = new Request("http://example.org", { method: "GET", @@ -242,14 +247,9 @@ const l: Request = new Request("http://example.org", { cache: "default" }); // incorrect - headers is string -const m: Request = new Request("http://example.org", { - method: "CONNECT", - headers: { - "Content-Type": "image/jpeg" - }, - mode: "cors", - cache: "default" -}); // incorrect - CONNECT is forbidden +new Request("/", { method: "post" }); // correct +new Request("/", { method: "hello" }); // correct +new Request("/", { method: null }); // incorrect `; @@ -259,13 +259,10 @@ const a: Response = new Response(); // correct const b: Response = new Response(new Blob()); // correct const c: Response = new Response(new FormData()); // correct -const d: Response = new Response(new FormData(), { - status: 404 -}); // correct - -const e: Response = new Response("responsebody", { - status: "404" -}); // incorrect +new Response("", { status: 404 }); // correct +new Response(null, { status: 204 }); // correct +new Response("", { status: "404" }); // incorrect +new Response("", { status: null }); // incorrect const f: Response = new Response("responsebody", { status: 404, @@ -294,6 +291,7 @@ const i: Response = new Response({ }); // incorrect const ok: boolean = h.ok; +const redirected: boolean = h.redirected; const status: number = h.status; h.text().then((t: string) => t); // correct @@ -306,13 +304,10 @@ const a: Response = new Response(); // correct const b: Response = new Response(new Blob()); // correct const c: Response = new Response(new FormData()); // correct -const d: Response = new Response(new FormData(), { - status: 404 -}); // correct - -const e: Response = new Response("responsebody", { - status: "404" -}); // incorrect +new Response("", { status: 404 }); // correct +new Response(null, { status: 204 }); // correct +new Response("", { status: "404" }); // incorrect +new Response("", { status: null }); // incorrect const f: Response = new Response("responsebody", { status: 404, @@ -341,6 +336,7 @@ const i: Response = new Response({ }); // incorrect const ok: boolean = h.ok; +const redirected: boolean = h.redirected; const status: number = h.status; h.text().then((t: string) => t); // correct @@ -379,6 +375,11 @@ for (let v of e.entries()) { } e.getAll('key1').forEach((v: string) => {}); // correct + +e.forEach((val: string) => val); // correct +e.forEach((val: string, key: string) => \`\${key}: \${val}\`); // correct +e.forEach((val: string, key: string, o: URLSearchParams) => {}); // correct +e.forEach(() => {}, {}); // correct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ @@ -409,4 +410,9 @@ for (let v of e.entries()) { e.getAll("key1").forEach((v: string) => {}); // correct +e.forEach((val: string) => val); // correct +e.forEach((val: string, key: string) => \`\${key}: \${val}\`); // correct +e.forEach((val: string, key: string, o: URLSearchParams) => {}); // correct +e.forEach(() => {}, {}); // correct + `; diff --git a/tests/flow/fetch/headers.js b/tests/flow/fetch/headers.js index 9eab0d99..d58f97d5 100644 --- a/tests/flow/fetch/headers.js +++ b/tests/flow/fetch/headers.js @@ -25,4 +25,8 @@ for (let v of e.entries()) { const [i, j]: [string, string] = v; // correct } -e.getAll('content-type').forEach((v: string) => {}); // correct +e.getAll('content-type'); // incorrect +e.forEach((val: string) => val); // correct +e.forEach((val: string, key: string) => `${key}: ${val}`); // correct +e.forEach((val: string, key: string, o: Headers) => {}); // correct +e.forEach(() => {}, {}); // correct diff --git a/tests/flow/fetch/request.js b/tests/flow/fetch/request.js index e2a9380c..d8a4fc5c 100644 --- a/tests/flow/fetch/request.js +++ b/tests/flow/fetch/request.js @@ -7,6 +7,7 @@ const e: Request = new Request(b, c); // incorrect const f: Request = new Request({}) // incorrect const g: Request = new Request('http://example.org', {}) // correct +new Request(new URL('http://example.org')); // correct const h: Request = new Request('http://example.org', { method: 'GET', @@ -57,11 +58,6 @@ const l: Request = new Request('http://example.org', { cache: 'default' }) // incorrect - headers is string -const m: Request = new Request('http://example.org', { - method: 'CONNECT', - headers: { - 'Content-Type': 'image/jpeg' - }, - mode: 'cors', - cache: 'default' -}) // incorrect - CONNECT is forbidden +new Request('/', { method: 'post' }); // correct +new Request('/', { method: 'hello' }); // correct +new Request('/', { method: null }); // incorrect diff --git a/tests/flow/fetch/response.js b/tests/flow/fetch/response.js index f68b4d8b..aa556ea4 100644 --- a/tests/flow/fetch/response.js +++ b/tests/flow/fetch/response.js @@ -3,13 +3,10 @@ const a: Response = new Response(); // correct const b: Response = new Response(new Blob()); // correct const c: Response = new Response(new FormData()); // correct -const d: Response = new Response(new FormData(), { - status: 404 -}); // correct - -const e: Response = new Response("responsebody", { - status: "404" -}); // incorrect +new Response("", { status: 404 }); // correct +new Response(null, { status: 204 }); // correct +new Response("", { status: "404" }); // incorrect +new Response("", { status: null }); // incorrect const f: Response = new Response("responsebody", { status: 404, @@ -38,6 +35,7 @@ const i: Response = new Response({ }); // incorrect const ok: boolean = h.ok; +const redirected: boolean = h.redirected; const status: number = h.status; h.text().then((t: string) => t); // correct diff --git a/tests/flow/fetch/urlsearchparams.js b/tests/flow/fetch/urlsearchparams.js index f40aae31..c3973b0b 100644 --- a/tests/flow/fetch/urlsearchparams.js +++ b/tests/flow/fetch/urlsearchparams.js @@ -26,3 +26,8 @@ for (let v of e.entries()) { } e.getAll('key1').forEach((v: string) => {}); // correct + +e.forEach((val: string) => val); // correct +e.forEach((val: string, key: string) => `${key}: ${val}`); // correct +e.forEach((val: string, key: string, o: URLSearchParams) => {}); // correct +e.forEach(() => {}, {}); // correct diff --git a/tests/flow/function/__snapshots__/jsfmt.spec.js.snap b/tests/flow/function/__snapshots__/jsfmt.spec.js.snap index 01c1c408..260000ba 100644 --- a/tests/flow/function/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/function/__snapshots__/jsfmt.spec.js.snap @@ -457,6 +457,9 @@ function return_rest_param>( return args; // Error: Array ~> number } } + +function requires_first_param(x: number, ...rest: Array): void {} +requires_first_param(); // Error: missing first arg ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* regression tests */ @@ -529,6 +532,9 @@ function return_rest_param>( }; } +function requires_first_param(x: number, ...rest: Array): void {} +requires_first_param(); // Error: missing first arg + `; exports[`rest_type.js 1`] = ` diff --git a/tests/flow/function/rest.js b/tests/flow/function/rest.js index 4d98e693..1b7e33fc 100644 --- a/tests/flow/function/rest.js +++ b/tests/flow/function/rest.js @@ -59,3 +59,6 @@ function return_rest_param>( return args; // Error: Array ~> number } } + +function requires_first_param(x: number, ...rest: Array): void {} +requires_first_param(); // Error: missing first arg diff --git a/tests/flow/get-def2/__snapshots__/jsfmt.spec.js.snap b/tests/flow/get-def2/__snapshots__/jsfmt.spec.js.snap index 5d7f604b..b92f22f0 100644 --- a/tests/flow/get-def2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/get-def2/__snapshots__/jsfmt.spec.js.snap @@ -37,6 +37,7 @@ let foo = require('./Parent').ParentFoo.foo; foo; import type {Foo} from './types'; +function takesFoo(foo: Foo) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow @@ -61,6 +62,7 @@ let foo = require("./Parent").ParentFoo.foo; foo; import type { Foo } from "./types"; +function takesFoo(foo: Foo) {} `; diff --git a/tests/flow/get-def2/main.js b/tests/flow/get-def2/main.js index 63064a34..149588b6 100644 --- a/tests/flow/get-def2/main.js +++ b/tests/flow/get-def2/main.js @@ -21,3 +21,4 @@ let foo = require('./Parent').ParentFoo.foo; foo; import type {Foo} from './types'; +function takesFoo(foo: Foo) { } diff --git a/tests/flow/include_suppressed/__snapshots__/jsfmt.spec.js.snap b/tests/flow/include_suppressed/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..180ed628 --- /dev/null +++ b/tests/flow/include_suppressed/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,22 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test.js 1`] = ` +// @flow + +(123: string); // Normal error + +// $FlowFixMe +(123: string); // Suppressed error + +// $FlowFixMe - unused suppression comment +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// @flow + +(123: string); // Normal error + +// $FlowFixMe +(123: string); // Suppressed error + +// $FlowFixMe - unused suppression comment + +`; diff --git a/tests/flow/objectTypeProperty/jsfmt.spec.js b/tests/flow/include_suppressed/jsfmt.spec.js similarity index 100% rename from tests/flow/objectTypeProperty/jsfmt.spec.js rename to tests/flow/include_suppressed/jsfmt.spec.js diff --git a/tests/flow/include_suppressed/test.js b/tests/flow/include_suppressed/test.js new file mode 100644 index 00000000..14ed1d68 --- /dev/null +++ b/tests/flow/include_suppressed/test.js @@ -0,0 +1,8 @@ +// @flow + +(123: string); // Normal error + +// $FlowFixMe +(123: string); // Suppressed error + +// $FlowFixMe - unused suppression comment diff --git a/tests/flow/malformed_code/__snapshots__/jsfmt.spec.js.snap b/tests/flow/malformed_code/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..98c329fa --- /dev/null +++ b/tests/flow/malformed_code/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`text.js 1`] = ` +// @flow +// Example found at +// https://github.com/sebmarkbage/art/blob/51ffce8164a555d652843241c2fdda52e186cbbd/parsers/svg/text.js#L137 +const evil_regex_as_a_string = "/[\\s�]*$/"; + +const error: string = 123; // Should be an error, but can't lex this file +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// @flow +// Example found at +// https://github.com/sebmarkbage/art/blob/51ffce8164a555d652843241c2fdda52e186cbbd/parsers/svg/text.js#L137 +const evil_regex_as_a_string = "/[s�]*$/"; + +const error: string = 123; // Should be an error, but can't lex this file + +`; diff --git a/tests/flow/malformed_code/jsfmt.spec.js b/tests/flow/malformed_code/jsfmt.spec.js new file mode 100644 index 00000000..989047bc --- /dev/null +++ b/tests/flow/malformed_code/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname); diff --git a/tests/flow/malformed_code/text.js b/tests/flow/malformed_code/text.js new file mode 100644 index 00000000..76c5bd5d --- /dev/null +++ b/tests/flow/malformed_code/text.js @@ -0,0 +1,6 @@ +// @flow +// Example found at +// https://github.com/sebmarkbage/art/blob/51ffce8164a555d652843241c2fdda52e186cbbd/parsers/svg/text.js#L137 +const evil_regex_as_a_string = "/[\s�]*$/"; + +const error: string = 123; // Should be an error, but can't lex this file diff --git a/tests/flow/multiflow/__snapshots__/jsfmt.spec.js.snap b/tests/flow/multiflow/__snapshots__/jsfmt.spec.js.snap index bcf30ac4..d4e95c83 100644 --- a/tests/flow/multiflow/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/multiflow/__snapshots__/jsfmt.spec.js.snap @@ -243,8 +243,8 @@ function fun(x: 'hi', y: 123) {} fun(...['hi', 123]); // No error fun(...['hi'], ...[123]); // No error fun(...['hi'], ...[], ...[123]); // No error -fun(...['hi'], ...[], ...[123], ...[true]); // No error -fun(...['hi'], ...[true], ...[123]); // Error: true ~> 123 +fun(...['hi'], ...[], ...[123], ...[true]); // Error - true is unused +fun(...['hi'], ...[true], ...[123]); // Error: true ~> 123 and 123 is unused declare var arrOf123: Array<123>; fun('hi', ...arrOf123); // No error - ignore the fact arrOf123 could be empty @@ -272,8 +272,8 @@ function fun(x: "hi", y: 123) {} fun(...["hi", 123]); // No error fun(...["hi"], ...[123]); // No error fun(...["hi"], ...[], ...[123]); // No error -fun(...["hi"], ...[], ...[123], ...[true]); // No error -fun(...["hi"], ...[true], ...[123]); // Error: true ~> 123 +fun(...["hi"], ...[], ...[123], ...[true]); // Error - true is unused +fun(...["hi"], ...[true], ...[123]); // Error: true ~> 123 and 123 is unused declare var arrOf123: Array<123>; fun("hi", ...arrOf123); // No error - ignore the fact arrOf123 could be empty diff --git a/tests/flow/multiflow/spread.js b/tests/flow/multiflow/spread.js index cea927f8..d127de0c 100644 --- a/tests/flow/multiflow/spread.js +++ b/tests/flow/multiflow/spread.js @@ -4,8 +4,8 @@ function fun(x: 'hi', y: 123) {} fun(...['hi', 123]); // No error fun(...['hi'], ...[123]); // No error fun(...['hi'], ...[], ...[123]); // No error -fun(...['hi'], ...[], ...[123], ...[true]); // No error -fun(...['hi'], ...[true], ...[123]); // Error: true ~> 123 +fun(...['hi'], ...[], ...[123], ...[true]); // Error - true is unused +fun(...['hi'], ...[true], ...[123]); // Error: true ~> 123 and 123 is unused declare var arrOf123: Array<123>; fun('hi', ...arrOf123); // No error - ignore the fact arrOf123 could be empty diff --git a/tests/flow/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap b/tests/flow/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap index 706828b3..9304d260 100644 --- a/tests/flow/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap @@ -53,11 +53,11 @@ buffer = Buffer.from(typedArray.buffer, typedArray.byteOffset, typedArray.byteLe buffer = Buffer.from(new Buffer(0)); buffer = Buffer.from("foo", "utf8"); -// This call to from() does type check ok, but should not. Unfortunately, Buffer +// This call to from() used to type check ok, but should not. Buffer // extends Uint8Array but gets rid of this signature to .from(). Understandably, -// flow doesn't support a subclass hiding a superclass member, so this checks out as -// ok, even though it is not correct. -buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72], (a:number) => a + 1, {}); // should error but doesn't +// flow didn't used to support a subclass hiding a superclass member, so this +// used to check out as ok, even though it is not correct. +buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72], (a:number) => a + 1, {}); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ @@ -128,14 +128,14 @@ buffer = Buffer.from( buffer = Buffer.from(new Buffer(0)); buffer = Buffer.from("foo", "utf8"); -// This call to from() does type check ok, but should not. Unfortunately, Buffer +// This call to from() used to type check ok, but should not. Buffer // extends Uint8Array but gets rid of this signature to .from(). Understandably, -// flow doesn't support a subclass hiding a superclass member, so this checks out as -// ok, even though it is not correct. +// flow didn't used to support a subclass hiding a superclass member, so this +// used to check out as ok, even though it is not correct. buffer = Buffer.from( [0x62, 0x75, 0x66, 0x66, 0x65, 0x72], (a: number) => a + 1, {} -); // should error but doesn't +); // error `; diff --git a/tests/flow/node_tests/buffer/buffer.js b/tests/flow/node_tests/buffer/buffer.js index 9c531979..f3e03861 100644 --- a/tests/flow/node_tests/buffer/buffer.js +++ b/tests/flow/node_tests/buffer/buffer.js @@ -50,8 +50,8 @@ buffer = Buffer.from(typedArray.buffer, typedArray.byteOffset, typedArray.byteLe buffer = Buffer.from(new Buffer(0)); buffer = Buffer.from("foo", "utf8"); -// This call to from() does type check ok, but should not. Unfortunately, Buffer +// This call to from() used to type check ok, but should not. Buffer // extends Uint8Array but gets rid of this signature to .from(). Understandably, -// flow doesn't support a subclass hiding a superclass member, so this checks out as -// ok, even though it is not correct. -buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72], (a:number) => a + 1, {}); // should error but doesn't +// flow didn't used to support a subclass hiding a superclass member, so this +// used to check out as ok, even though it is not correct. +buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72], (a:number) => a + 1, {}); // error diff --git a/tests/flow/node_tests/process/__snapshots__/jsfmt.spec.js.snap b/tests/flow/node_tests/process/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..b859c0e3 --- /dev/null +++ b/tests/flow/node_tests/process/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,57 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`nextTick.js 1`] = ` +/* @flow */ + +process.nextTick(() => {}); + +process.nextTick( + (a: string, b: number, c: boolean) => {}, + 'z', + 1, + true +); + +process.nextTick( + (a: string, b: number, c: boolean) => {}, + 0, // Error: number ~> string + 1, + null // Error: null ~> boolean +); + +process.nextTick( + (a: string, b: number, c: boolean) => {}, + 'z', + 'y', // Error: string ~> number + true +); + +process.nextTick( + (a: string, b: number, c: boolean) => {} // Error: too few arguments +); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/* @flow */ + +process.nextTick(() => {}); + +process.nextTick((a: string, b: number, c: boolean) => {}, "z", 1, true); + +process.nextTick( + (a: string, b: number, c: boolean) => {}, + 0, // Error: number ~> string + 1, + null // Error: null ~> boolean +); + +process.nextTick( + (a: string, b: number, c: boolean) => {}, + "z", + "y", // Error: string ~> number + true +); + +process.nextTick( + (a: string, b: number, c: boolean) => {} // Error: too few arguments +); + +`; diff --git a/tests/flow/node_tests/process/jsfmt.spec.js b/tests/flow/node_tests/process/jsfmt.spec.js new file mode 100644 index 00000000..989047bc --- /dev/null +++ b/tests/flow/node_tests/process/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname); diff --git a/tests/flow/node_tests/process/nextTick.js b/tests/flow/node_tests/process/nextTick.js new file mode 100644 index 00000000..a9d95257 --- /dev/null +++ b/tests/flow/node_tests/process/nextTick.js @@ -0,0 +1,28 @@ +/* @flow */ + +process.nextTick(() => {}); + +process.nextTick( + (a: string, b: number, c: boolean) => {}, + 'z', + 1, + true +); + +process.nextTick( + (a: string, b: number, c: boolean) => {}, + 0, // Error: number ~> string + 1, + null // Error: null ~> boolean +); + +process.nextTick( + (a: string, b: number, c: boolean) => {}, + 'z', + 'y', // Error: string ~> number + true +); + +process.nextTick( + (a: string, b: number, c: boolean) => {} // Error: too few arguments +); diff --git a/tests/flow/objectTypeProperty/__snapshots__/jsfmt.spec.js.snap b/tests/flow/objectTypeProperty/__snapshots__/jsfmt.spec.js.snap deleted file mode 100644 index 9de1f27b..00000000 --- a/tests/flow/objectTypeProperty/__snapshots__/jsfmt.spec.js.snap +++ /dev/null @@ -1,42 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`objectTypeProperty.js 1`] = ` -/* @flow */ - -declare var BAZ: {stuff?: (x: number) => void} | void; - -declare class Foo { - constructor(): void; - foo: () => void; -} - -let x: { x?: number } - -type T = { - get goodGetterWithAnnotation(): number, - set goodSetterWithAnnotation(x: number): void, - - get getterWithMultipleSpacesPrecedingName(): number, - set setterWithMultipleSpacesPrecedingName(x: number): void, -} -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/* @flow */ - -declare var BAZ: { stuff?: (x: number) => void } | void; - -declare class Foo { - constructor(): void, - foo: () => void -} - -let x: { x?: number }; - -type T = { - get goodGetterWithAnnotation(): number, - set goodSetterWithAnnotation(x: number): void, - - get getterWithMultipleSpacesPrecedingName(): number, - set setterWithMultipleSpacesPrecedingName(x: number): void -}; - -`; diff --git a/tests/flow/objectTypeProperty/objectTypeProperty.js b/tests/flow/objectTypeProperty/objectTypeProperty.js deleted file mode 100644 index 1e91cfc8..00000000 --- a/tests/flow/objectTypeProperty/objectTypeProperty.js +++ /dev/null @@ -1,18 +0,0 @@ -/* @flow */ - -declare var BAZ: {stuff?: (x: number) => void} | void; - -declare class Foo { - constructor(): void; - foo: () => void; -} - -let x: { x?: number } - -type T = { - get goodGetterWithAnnotation(): number, - set goodSetterWithAnnotation(x: number): void, - - get getterWithMultipleSpacesPrecedingName(): number, - set setterWithMultipleSpacesPrecedingName(x: number): void, -} diff --git a/tests/flow/object_is/__snapshots__/jsfmt.spec.js.snap b/tests/flow/object_is/__snapshots__/jsfmt.spec.js.snap index 63277d2c..67364ea5 100644 --- a/tests/flow/object_is/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/object_is/__snapshots__/jsfmt.spec.js.snap @@ -22,7 +22,7 @@ Object.is(squared, squared); var a: boolean = Object.is('a', 'a'); var b: string = Object.is('a', 'a'); var c: boolean = Object.is('a'); -var d: boolean = Object.is('a', 'b', 'c'); +var d: boolean = Object.is('a', 'b', 'c'); // Error - 'c' is unused ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Object.is(1, 1); Object.is(1, 2); @@ -45,6 +45,6 @@ Object.is(squared, squared); var a: boolean = Object.is("a", "a"); var b: string = Object.is("a", "a"); var c: boolean = Object.is("a"); -var d: boolean = Object.is("a", "b", "c"); +var d: boolean = Object.is("a", "b", "c"); // Error - 'c' is unused `; diff --git a/tests/flow/object_is/object_is.js b/tests/flow/object_is/object_is.js index a13f2e3b..c0c7b0c3 100644 --- a/tests/flow/object_is/object_is.js +++ b/tests/flow/object_is/object_is.js @@ -19,4 +19,4 @@ Object.is(squared, squared); var a: boolean = Object.is('a', 'a'); var b: string = Object.is('a', 'a'); var c: boolean = Object.is('a'); -var d: boolean = Object.is('a', 'b', 'c'); +var d: boolean = Object.is('a', 'b', 'c'); // Error - 'c' is unused diff --git a/tests/flow/promises/__snapshots__/jsfmt.spec.js.snap b/tests/flow/promises/__snapshots__/jsfmt.spec.js.snap index c69b2b5f..31308116 100644 --- a/tests/flow/promises/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/promises/__snapshots__/jsfmt.spec.js.snap @@ -340,13 +340,11 @@ Promise.reject(0) var b: number = str; // Error: string ~> number }); -// TODO: resolvedPromise -> catch() -> then():T +// resolvedPromise -> catch() -> then():?T Promise.resolve(0) .catch(function(err) {}) .then(function(num) { - var a: number = num; - - // TODO + var a: ?number = num; var b: string = num; // Error: string ~> number }); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -588,11 +586,9 @@ Promise.reject(0) var b: number = str; // Error: string ~> number }); -// TODO: resolvedPromise -> catch() -> then():T +// resolvedPromise -> catch() -> then():?T Promise.resolve(0).catch(function(err) {}).then(function(num) { - var a: number = num; - - // TODO + var a: ?number = num; var b: string = num; // Error: string ~> number }); diff --git a/tests/flow/promises/promise.js b/tests/flow/promises/promise.js index 1266b018..79618e8e 100644 --- a/tests/flow/promises/promise.js +++ b/tests/flow/promises/promise.js @@ -217,12 +217,10 @@ Promise.reject(0) var b: number = str; // Error: string ~> number }); -// TODO: resolvedPromise -> catch() -> then():T +// resolvedPromise -> catch() -> then():?T Promise.resolve(0) .catch(function(err) {}) .then(function(num) { - var a: number = num; - - // TODO + var a: ?number = num; var b: string = num; // Error: string ~> number }); diff --git a/tests/flow/recheck/__snapshots__/jsfmt.spec.js.snap b/tests/flow/recheck/__snapshots__/jsfmt.spec.js.snap index 276f013e..487d4254 100644 --- a/tests/flow/recheck/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/recheck/__snapshots__/jsfmt.spec.js.snap @@ -409,3 +409,10 @@ const foo = require("./j1"); foo.p = 0; `; + +exports[`k.js 1`] = ` +/* @flow */ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/* @flow */ + +`; diff --git a/tests/flow/recheck/k.js b/tests/flow/recheck/k.js new file mode 100644 index 00000000..e667c471 --- /dev/null +++ b/tests/flow/recheck/k.js @@ -0,0 +1 @@ +/* @flow */ diff --git a/tests/flow/recheck/tmpk/__snapshots__/jsfmt.spec.js.snap b/tests/flow/recheck/tmpk/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..d066df2f --- /dev/null +++ b/tests/flow/recheck/tmpk/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`k.js 1`] = ` +/* @flow */ + +declare var x: LibK; +(x.p: string); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/* @flow */ + +declare var x: LibK; +(x.p: string); + +`; diff --git a/tests/flow/recheck/tmpk/jsfmt.spec.js b/tests/flow/recheck/tmpk/jsfmt.spec.js new file mode 100644 index 00000000..989047bc --- /dev/null +++ b/tests/flow/recheck/tmpk/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname); diff --git a/tests/flow/recheck/tmpk/k.js b/tests/flow/recheck/tmpk/k.js new file mode 100644 index 00000000..a2c85787 --- /dev/null +++ b/tests/flow/recheck/tmpk/k.js @@ -0,0 +1,4 @@ +/* @flow */ + +declare var x: LibK; +(x.p: string); diff --git a/tests/flow/recheck/tmplibk/__snapshots__/jsfmt.spec.js.snap b/tests/flow/recheck/tmplibk/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..1bd131cf --- /dev/null +++ b/tests/flow/recheck/tmplibk/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`libk1.js 1`] = ` +type LibK = {} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +type LibK = {}; + +`; + +exports[`libk2.js 1`] = ` +type LibK = { + p: string; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +type LibK = { + p: string +}; + +`; diff --git a/tests/flow/recheck/tmplibk/jsfmt.spec.js b/tests/flow/recheck/tmplibk/jsfmt.spec.js new file mode 100644 index 00000000..989047bc --- /dev/null +++ b/tests/flow/recheck/tmplibk/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname); diff --git a/tests/flow/recheck/tmplibk/libk1.js b/tests/flow/recheck/tmplibk/libk1.js new file mode 100644 index 00000000..3e7ddfee --- /dev/null +++ b/tests/flow/recheck/tmplibk/libk1.js @@ -0,0 +1 @@ +type LibK = {} diff --git a/tests/flow/recheck/tmplibk/libk2.js b/tests/flow/recheck/tmplibk/libk2.js new file mode 100644 index 00000000..51bee311 --- /dev/null +++ b/tests/flow/recheck/tmplibk/libk2.js @@ -0,0 +1,3 @@ +type LibK = { + p: string; +} diff --git a/tests/flow/require/__snapshots__/jsfmt.spec.js.snap b/tests/flow/require/__snapshots__/jsfmt.spec.js.snap index 4b552290..c7be8acb 100644 --- a/tests/flow/require/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/require/__snapshots__/jsfmt.spec.js.snap @@ -76,12 +76,12 @@ exports[`ProvidesModuleD.js 1`] = ` exports[`not_builtin_require.js 1`] = ` // @flow -function require() {} +function require(x: string) {} require("not a module name"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow -function require() {} +function require(x: string) {} require("not a module name"); `; diff --git a/tests/flow/require/not_builtin_require.js b/tests/flow/require/not_builtin_require.js index 36719059..e87c2a34 100644 --- a/tests/flow/require/not_builtin_require.js +++ b/tests/flow/require/not_builtin_require.js @@ -1,4 +1,4 @@ // @flow -function require() {} +function require(x: string) {} require("not a module name"); diff --git a/tests/flow/symbol/__snapshots__/jsfmt.spec.js.snap b/tests/flow/symbol/__snapshots__/jsfmt.spec.js.snap index 25f1f8c0..f5efaf64 100644 --- a/tests/flow/symbol/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/symbol/__snapshots__/jsfmt.spec.js.snap @@ -4,13 +4,11 @@ exports[`symbol.js 1`] = ` var FOO = Symbol(); var BAR = Symbol('bar'); -// TODO: Expected error -var WAT = Symbol('foo', 'bar'); +var WAT = Symbol('foo', 'bar'); // Error - unused argument ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var FOO = Symbol(); var BAR = Symbol("bar"); -// TODO: Expected error -var WAT = Symbol("foo", "bar"); +var WAT = Symbol("foo", "bar"); // Error - unused argument `; diff --git a/tests/flow/symbol/symbol.js b/tests/flow/symbol/symbol.js index f8c625d1..aaacc4e6 100644 --- a/tests/flow/symbol/symbol.js +++ b/tests/flow/symbol/symbol.js @@ -1,5 +1,4 @@ var FOO = Symbol(); var BAR = Symbol('bar'); -// TODO: Expected error -var WAT = Symbol('foo', 'bar'); +var WAT = Symbol('foo', 'bar'); // Error - unused argument diff --git a/tests/flow/union_new/lib/__snapshots__/jsfmt.spec.js.snap b/tests/flow/union_new/lib/__snapshots__/jsfmt.spec.js.snap index 1d1f8604..9e5bf12e 100644 --- a/tests/flow/union_new/lib/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/union_new/lib/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,7 @@ declare class SomeLibClass {} exports[`test25_lib.js 1`] = ` declare class Set { - add(): Set; + add(x: any): Set; } declare class Row { @@ -31,7 +31,7 @@ declare class Rows { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare class Set { - add(): Set + add(x: any): Set } declare class Row { diff --git a/tests/flow/union_new/lib/test25_lib.js b/tests/flow/union_new/lib/test25_lib.js index d79c71a2..0578483c 100644 --- a/tests/flow/union_new/lib/test25_lib.js +++ b/tests/flow/union_new/lib/test25_lib.js @@ -1,5 +1,5 @@ declare class Set { - add(): Set; + add(x: any): Set; } declare class Row { diff --git a/tests/flow/unused_function_args/__snapshots__/jsfmt.spec.js.snap b/tests/flow/unused_function_args/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..eb81faf6 --- /dev/null +++ b/tests/flow/unused_function_args/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,54 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test.js 1`] = ` +function foo() {} +const args = [3, 4]; + +foo(1, 2); // 2 errors +foo( + 1, // error + 2, // error +); +foo(...args); // 2 errors + +foo.call(null, 1, 2); // 2 errors +foo.call(null, ...args); // 2 errors +foo.call(null, 1, 2, ...args); // 4 errors + +foo.apply(null, [1, 2]); // 2 errors +foo.apply(null, args); // 2 errors + +foo.bind(null, 1, 2); // 2 errors +foo.bind(null, ...args); // 2 errors +foo.bind(null, 1, 2, ...args); // 4 errors + +new foo(1, 2); // 2 errors +new foo(...args); // 2 errors +new foo(1, 2, ...args); // 4 errors +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +function foo() {} +const args = [3, 4]; + +foo(1, 2); // 2 errors +foo( + 1, // error + 2 // error +); +foo(...args); // 2 errors + +foo.call(null, 1, 2); // 2 errors +foo.call(null, ...args); // 2 errors +foo.call(null, 1, 2, ...args); // 4 errors + +foo.apply(null, [1, 2]); // 2 errors +foo.apply(null, args); // 2 errors + +foo.bind(null, 1, 2); // 2 errors +foo.bind(null, ...args); // 2 errors +foo.bind(null, 1, 2, ...args); // 4 errors + +new foo(1, 2); // 2 errors +new foo(...args); // 2 errors +new foo(1, 2, ...args); // 4 errors + +`; diff --git a/tests/flow/unused_function_args/jsfmt.spec.js b/tests/flow/unused_function_args/jsfmt.spec.js new file mode 100644 index 00000000..989047bc --- /dev/null +++ b/tests/flow/unused_function_args/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname); diff --git a/tests/flow/unused_function_args/test.js b/tests/flow/unused_function_args/test.js new file mode 100644 index 00000000..5f8d5237 --- /dev/null +++ b/tests/flow/unused_function_args/test.js @@ -0,0 +1,24 @@ +function foo() {} +const args = [3, 4]; + +foo(1, 2); // 2 errors +foo( + 1, // error + 2, // error +); +foo(...args); // 2 errors + +foo.call(null, 1, 2); // 2 errors +foo.call(null, ...args); // 2 errors +foo.call(null, 1, 2, ...args); // 4 errors + +foo.apply(null, [1, 2]); // 2 errors +foo.apply(null, args); // 2 errors + +foo.bind(null, 1, 2); // 2 errors +foo.bind(null, ...args); // 2 errors +foo.bind(null, 1, 2, ...args); // 4 errors + +new foo(1, 2); // 2 errors +new foo(...args); // 2 errors +new foo(1, 2, ...args); // 4 errors