From e56d58cf847596fa4fc09afa36880d13e3d1e6d6 Mon Sep 17 00:00:00 2001 From: Eugene Kuzmenko Date: Mon, 30 Jan 2017 21:32:44 +0100 Subject: [PATCH] [fixed] flowtype - prefer shorthand array --- interfaces/chai.js | 2 +- interfaces/cheerio.js | 2 +- interfaces/eslint.js | 4 +-- interfaces/express.js | 60 ++++++++++++++++---------------- interfaces/fb-watchman.js | 2 +- interfaces/jsdom.js | 2 +- interfaces/postcss.js | 4 +-- interfaces/serve-static.js | 2 +- interfaces/sinon.js | 8 ++--- interfaces/webcompiler.js | 24 ++++++------- interfaces/webpack-dev-server.js | 2 +- interfaces/webpack.js | 4 +-- src/JS.js | 8 ++--- src/JSLint.js | 2 +- src/NativeProcess.js | 2 +- src/SASS.js | 6 ++-- src/SASSCompiler.js | 4 +-- src/SASSLint.js | 2 +- src/highlight.js | 2 +- src/jsx.js | 8 ++--- src/markdown.js | 2 +- src/typedef.js | 2 +- test/mock.js | 2 +- 23 files changed, 78 insertions(+), 78 deletions(-) diff --git a/interfaces/chai.js b/interfaces/chai.js index 2d84edf..d290f7f 100644 --- a/interfaces/chai.js +++ b/interfaces/chai.js @@ -3,7 +3,7 @@ type Assert = { not: Assert; a(type: string): void; - calledWith(...args: Array): void; + calledWith(...args: any[]): void; called: void; equal(obj: any): void; eql(obj: any): void; diff --git a/interfaces/cheerio.js b/interfaces/cheerio.js index 7b0f2c4..942b32c 100644 --- a/interfaces/cheerio.js +++ b/interfaces/cheerio.js @@ -1,7 +1,7 @@ /* @flow */ type DOM = { - toArray(): Array; + toArray(): Object[]; html(): string; children(): DOM; each(iteratee: (i: number, el: Object) => any): DOM; diff --git a/interfaces/eslint.js b/interfaces/eslint.js index ec1ee0d..acd648f 100644 --- a/interfaces/eslint.js +++ b/interfaces/eslint.js @@ -9,13 +9,13 @@ type ESLintMessage = { }; type ESLintResult = { filePath: string; - messages: Array; + messages: ESLintMessage[]; }; declare module 'eslint' { declare class CLIEngine { options: {configFile: string}; constructor(config: Object): void; - executeOnFiles(files: Array): {results: Array}; + executeOnFiles(files: string[]): {results: ESLintResult[]}; } } diff --git a/interfaces/express.js b/interfaces/express.js index fb8275f..3e6c667 100644 --- a/interfaces/express.js +++ b/interfaces/express.js @@ -12,7 +12,7 @@ declare class Request { fresh: boolean; hostname: string; ip: string; - ips: Array; + ips: string[]; method: string; params: Object | any[]; path: string; @@ -22,12 +22,12 @@ declare class Request { secure: boolean; signedCookies: Object; stale: boolean; - subdomains: Array; + subdomains: string[]; xhr: boolean; accepts(types: string | string[]): ?string; - acceptsCharsets(...charset: Array): ?string; - acceptsEncodings(...encoding: Array): ?string; - acceptsLanguages(...lang: Array): ?string; + acceptsCharsets(...charset: string[]): ?string; + acceptsEncodings(...encoding: string[]): ?string; + acceptsLanguages(...lang: string[]): ?string; get(field: string): ?string; is(type: string): boolean; range(size: number, options?: {combine: boolean}): number | Array<{start: number; end: number}>; @@ -99,15 +99,15 @@ type ExpressMiddleware = (req: Request, res: Response, next?: Function) => void; declare class ExpressApplication extends EventEmitter { locals: Object; mountpath: string | string[]; - all(path: string, ...callback: Array): ExpressApplication; - delete(path: string, ...callback: Array): ExpressApplication; + all(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + delete(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; disable(name: string): ExpressApplication; disabled(name: string): boolean; enable(name: string): ExpressApplication; enabled(name: string): boolean; engine(ext: string, callback: (path: string, options: Object, callback: Function) => void): ExpressApplication; get(name: string): any; - get(path: string, ...callback: Array): ExpressApplication; + get(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; listen(port: number): ExpressApplication; listen(port: number, hostname: string): ExpressApplication; listen(port: number, backlog: number): ExpressApplication; @@ -116,33 +116,33 @@ declare class ExpressApplication extends EventEmitter { listen(port: number, hostname: string, callback: Function): ExpressApplication; listen(port: number, backlog: number, callback: Function): ExpressApplication; listen(port: number, hostname: string, backlog: number, callback: Function): ExpressApplication; - checkout(path: string, ...callback: Array): ExpressApplication; - copy(path: string, ...callback: Array): ExpressApplication; - head(path: string, ...callback: Array): ExpressApplication; - lock(path: string, ...callback: Array): ExpressApplication; - merge(path: string, ...callback: Array): ExpressApplication; - mkactivity(path: string, ...callback: Array): ExpressApplication; - mkcol(path: string, ...callback: Array): ExpressApplication; - move(path: string, ...callback: Array): ExpressApplication; - notify(path: string, ...callback: Array): ExpressApplication; - options(path: string, ...callback: Array): ExpressApplication; - patch(path: string, ...callback: Array): ExpressApplication; - purge(path: string, ...callback: Array): ExpressApplication; - report(path: string, ...callback: Array): ExpressApplication; - search(path: string, ...callback: Array): ExpressApplication; - subscribe(path: string, ...callback: Array): ExpressApplication; - trace(path: string, ...callback: Array): ExpressApplication; - unlock(path: string, ...callback: Array): ExpressApplication; - unsubscribe(path: string, ...callback: Array): ExpressApplication; + checkout(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + copy(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + head(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + lock(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + merge(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + mkactivity(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + mkcol(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + move(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + notify(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + options(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + patch(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + purge(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + report(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + search(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + subscribe(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + trace(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + unlock(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + unsubscribe(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; param(callback: (req: Request, res: Response, next: Function, id: string) => void): ExpressApplication; param(name: string, callback: (req: Request, res: Response, next: Function, id: string) => void): ExpressApplication; path(): string; - post(path: string, ...callback: Array): ExpressApplication; - put(path: string, ...callback: Array): ExpressApplication; + post(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; + put(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; render(view: string, callback: RenderCallback): ExpressApplication; render(view: string, locals: Object, callback: RenderCallback): ExpressApplication; route(path: string): ExpressApplication; set(name: string, value: any): ExpressApplication; - use(...callback: Array): ExpressApplication; - use(path: string, ...callback: Array): ExpressApplication; + use(...callback: ExpressMiddleware[]): ExpressApplication; + use(path: string, ...callback: ExpressMiddleware[]): ExpressApplication; } diff --git a/interfaces/fb-watchman.js b/interfaces/fb-watchman.js index a87b2b2..8229c1d 100644 --- a/interfaces/fb-watchman.js +++ b/interfaces/fb-watchman.js @@ -8,6 +8,6 @@ import EventEmitter from 'events'; declare module 'fb-watchman' { declare class Client extends EventEmitter { capabilityCheck(config: Object, callback: (error: ?Error) => void): void; - command(cmd: Array, callback: ObjectOrErrorCallback): void; + command(cmd: any[], callback: ObjectOrErrorCallback): void; } } diff --git a/interfaces/jsdom.js b/interfaces/jsdom.js index b595ea0..0babfe5 100644 --- a/interfaces/jsdom.js +++ b/interfaces/jsdom.js @@ -9,7 +9,7 @@ declare module 'jsdom' { setEnd(): void; setStart(): void; getBoundingClientRect(): Object; - getClientRects(): Array; + getClientRects(): any[]; }; }; }; diff --git a/interfaces/postcss.js b/interfaces/postcss.js index 938a324..8d75718 100644 --- a/interfaces/postcss.js +++ b/interfaces/postcss.js @@ -5,7 +5,7 @@ import type {PostCSSWarning} from '../src/typedef'; type PostCSSResult = { css: string; map: Object; - warnings(): Array; + warnings(): PostCSSWarning[]; }; type PostCSSPromise = { @@ -13,5 +13,5 @@ type PostCSSPromise = { }; declare module 'postcss' { - declare function exports(plugins: Array): {process: (code: string, config: Object) => PostCSSPromise}; + declare function exports(plugins: any[]): {process: (code: string, config: Object) => PostCSSPromise}; } diff --git a/interfaces/serve-static.js b/interfaces/serve-static.js index d2b3a5d..135c9dc 100644 --- a/interfaces/serve-static.js +++ b/interfaces/serve-static.js @@ -4,7 +4,7 @@ declare module 'serve-static' { declare function exports(root: string, options?: { dotfiles?: string; etag?: boolean; - extensions?: boolean | Array; + extensions?: boolean | string[]; fallthrough?: boolean; index?: any; lastModified?: boolean; diff --git a/interfaces/sinon.js b/interfaces/sinon.js index 4bc7e28..d4c5800 100644 --- a/interfaces/sinon.js +++ b/interfaces/sinon.js @@ -1,22 +1,22 @@ /* @flow */ type Spy = { - (...args: Array): any; + (...args: any[]): any; callCount: number; }; type Stub = { - (...args: Array): any; + (...args: any[]): any; returns(obj: any): any; returnsArg(i: number): any; throws(err: Error): any; callsArg(i: number): any; - callsArgWith(i: number, ...args: Array): any; + callsArgWith(i: number, ...args: any[]): any; }; declare module 'sinon' { declare function spy(obj: ?any, method: ?string): Spy; - declare function stub(obj: ?any, method: ?string, func: ?(...args: Array) => any): Stub; + declare function stub(obj: ?any, method: ?string, func: ?(...args: any[]) => any): Stub; declare var match: { (callback: (value: any) => boolean): void; func: void; diff --git a/interfaces/webcompiler.js b/interfaces/webcompiler.js index b1c778f..62879c5 100644 --- a/interfaces/webcompiler.js +++ b/interfaces/webcompiler.js @@ -7,7 +7,7 @@ declare module 'webcompiler' { declare class NativeProcess { constructor(task: string): void; - run(callback: ?StringOrErrorCallback, args: ?Array, opts: ?Object): void; + run(callback: ?StringOrErrorCallback, args: ?string[], opts: ?Object): void; kill(): void; } @@ -16,12 +16,12 @@ declare module 'webcompiler' { run(callback: () => void): void; } - declare function flatten(...args: Array): Array; - declare function arrayToJSX(arr: ?Array): Array; + declare function flatten(...args: any[]): any[]; + declare function arrayToJSX(arr: ?Array): any[]; declare function htmlToArray(html: ?string): Array; - declare function htmlToJSX(html: ?string): Array; + declare function htmlToJSX(html: ?string): any[]; declare function markdownToArray(markdown: ?string): Array; - declare function markdownToJSX(markdown: ?string): Array; + declare function markdownToJSX(markdown: ?string): any[]; declare function markdownToHTML(markdown: ?string): string; declare function highlightHTML(code: ?string): string; declare function highlightArray(code: ?string): Array; @@ -72,7 +72,7 @@ declare module 'webcompiler' { declare class JSLint { constructor(rules: ?Object): void; - run(paths: Array, callback: LintCallback): void; + run(paths: string[], callback: LintCallback): void; } declare class JSCompiler { @@ -83,7 +83,7 @@ declare module 'webcompiler' { declare class SASSLint { constructor(...excludeLinter: Array): void; - run(paths: Array, callback: LintCallback): void; + run(paths: string[], callback: LintCallback): void; } declare class SASSCompiler { @@ -96,17 +96,17 @@ declare module 'webcompiler' { compiler: JSCompiler; constructor(compress: ?boolean, lintRules: ?Object): void; typecheck(callback: () => void): void; - lint(paths: Array, callback: () => void): void; - be(inPath: string, outPath: string, lintPaths: ?Array, callback: ?() => void): void; - fe(inPath: string, outPath: string, lintPaths: ?Array, callback: ?() => void): void; + lint(paths: string[], callback: () => void): void; + be(inPath: string, outPath: string, lintPaths: ?string[], callback: ?() => void): void; + fe(inPath: string, outPath: string, lintPaths: ?string[], callback: ?() => void): void; } declare class SASS { compiler: SASSCompiler; constructor(compress: ?boolean, includePaths: ?Array, excludeLinter: ?Array, importOnceOptions: ?Object): void; - lint(paths: Array, callback: () => void): void; - fe(inPath: string, outPath: string, lintPaths: ?Array, callback: ?() => void): void; + lint(paths: string[], callback: () => void): void; + fe(inPath: string, outPath: string, lintPaths: ?string[], callback: ?() => void): void; } declare class DevServer { diff --git a/interfaces/webpack-dev-server.js b/interfaces/webpack-dev-server.js index 75de9b0..d41b1aa 100644 --- a/interfaces/webpack-dev-server.js +++ b/interfaces/webpack-dev-server.js @@ -4,7 +4,7 @@ declare module 'webpack-dev-server' { declare class exports { app: ExpressApplication; constructor(webpack: Object): void; - use(...callback: Array): void; + use(...callback: ExpressMiddleware[]): void; listen(port: number, host: string, callback: (error: ?Error) => void): void; } } diff --git a/interfaces/webpack.js b/interfaces/webpack.js index 8b8ae84..6e3f13b 100644 --- a/interfaces/webpack.js +++ b/interfaces/webpack.js @@ -2,8 +2,8 @@ type WebPackStats = { toJson(): { - errors: Array; - warnings: Array; + errors: string[]; + warnings: string[]; }; }; type WebPackCallback = (error: ?Error, stats: WebPackStats) => void; diff --git a/src/JS.js b/src/JS.js index e2e802f..130de03 100644 --- a/src/JS.js +++ b/src/JS.js @@ -95,7 +95,7 @@ export class JS { * // successfully linted * }); */ - lint(paths: Array, callback: () => void) { + lint(paths: string[], callback: () => void) { this.linter.run(paths, linterErr => { if (linterErr) { return logLintingErrors(linterErr, 'JavaScript'); @@ -119,7 +119,7 @@ export class JS { * // successfully validated * }); */ - validate(inPath: string, lintPaths: Array, callback: () => void) { + validate(inPath: string, lintPaths: string[], callback: () => void) { JS.typecheck(() => { this.lint(lintPaths.concat([inPath]), callback); }); @@ -141,7 +141,7 @@ export class JS { * // the code has passed all the checks and has been compiled successfully * }); */ - be(inPath: string, outPath: string, lintPaths: Array = [], callback: () => void = noop) { + be(inPath: string, outPath: string, lintPaths: string[] = [], callback: () => void = noop) { this.validate(inPath, lintPaths, () => { this.compiler.be(inPath, outPath, callback); }); @@ -163,7 +163,7 @@ export class JS { * // the code has passed all the checks and has been compiled successfully * }); */ - fe(inPath: string, outPath: string, lintPaths: Array = [], callback: () => void = noop) { + fe(inPath: string, outPath: string, lintPaths: string[] = [], callback: () => void = noop) { this.validate(inPath, lintPaths, () => { this.compiler.fe(inPath, outPath, callback); }); diff --git a/src/JSLint.js b/src/JSLint.js index 1f24377..6be468d 100644 --- a/src/JSLint.js +++ b/src/JSLint.js @@ -61,7 +61,7 @@ export class JSLint { * // there were no linting errors * }); */ - run(paths: Array, callback: LintCallback) { + run(paths: string[], callback: LintCallback) { const {results} = this.linter.executeOnFiles(paths), errors = []; diff --git a/src/NativeProcess.js b/src/NativeProcess.js index 71c5502..037d6f2 100644 --- a/src/NativeProcess.js +++ b/src/NativeProcess.js @@ -94,7 +94,7 @@ export class NativeProcess { * // created a directory named "example" in cwd * }, ['example']); */ - run(callback: StringOrErrorCallback = noop, args: Array = [], opts: Object = {}) { + run(callback: StringOrErrorCallback = noop, args: string[] = [], opts: Object = {}) { if (this.proc) { return callback(new Error('Still working'), ''); } diff --git a/src/SASS.js b/src/SASS.js index 906e55a..9cd6da4 100644 --- a/src/SASS.js +++ b/src/SASS.js @@ -58,7 +58,7 @@ export class SASS { linter: SASSLint; /* eslint-disable require-jsdoc */ - constructor(compress: boolean = true, includePaths: Array = [], configFile: string = defaultConfigFile, + constructor(compress: boolean = true, includePaths: string[] = [], configFile: string = defaultConfigFile, importOnceOptions: Object = {}) { /* eslint-enable require-jsdoc */ this.compiler = new SASSCompiler(compress, includePaths, importOnceOptions); @@ -80,7 +80,7 @@ export class SASS { * // successfully linted * }); */ - lint(paths: Array, callback: () => void) { + lint(paths: string[], callback: () => void) { this.linter.run(paths, linterErr => { if (linterErr) { return logLintingErrors(linterErr, 'SASS'); @@ -107,7 +107,7 @@ export class SASS { * // the code has passed all the checks and has been compiled successfully * }); */ - fe(inPath: string, outPath: string, lintPaths: Array = [], callback: () => void = noop) { + fe(inPath: string, outPath: string, lintPaths: string[] = [], callback: () => void = noop) { this.lint(lintPaths.concat([inPath]), () => { this.compiler.fe(inPath, outPath, callback); }); diff --git a/src/SASSCompiler.js b/src/SASSCompiler.js index 4ab700d..24cfc2a 100644 --- a/src/SASSCompiler.js +++ b/src/SASSCompiler.js @@ -55,7 +55,7 @@ export class SASSCompiler extends Compiler { * @private * @instance */ - includePaths: Array; + includePaths: string[]; /** * importOnce resolver configuration @@ -68,7 +68,7 @@ export class SASSCompiler extends Compiler { importOnce: Object; /* eslint-disable require-jsdoc */ - constructor(compress: boolean = true, includePaths: Array = [], importOnceOptions: Object = {}) { + constructor(compress: boolean = true, includePaths: string[] = [], importOnceOptions: Object = {}) { /* eslint-enable require-jsdoc */ super(compress); this.includePaths = defaultIncludePaths.concat(includePaths); diff --git a/src/SASSLint.js b/src/SASSLint.js index cb8adf0..f578cd0 100644 --- a/src/SASSLint.js +++ b/src/SASSLint.js @@ -64,7 +64,7 @@ export class SASSLint { * // there were no linting errors * }); */ - run(paths: Array, callback: LintCallback) { + run(paths: string[], callback: LintCallback) { lint({configFile: this.configFile, files: paths}).then(({results}) => { const errors = []; diff --git a/src/highlight.js b/src/highlight.js index f77c5e2..316520b 100644 --- a/src/highlight.js +++ b/src/highlight.js @@ -123,6 +123,6 @@ export function highlightArray(code: string = ''): Array { * *
{highlightJSX('function myScript(){return 100;}')}
*/ -export function highlightJSX(code: string = ''): Array { +export function highlightJSX(code: string = ''): any[] { return arrayToJSX(highlightArray(code)); } diff --git a/src/jsx.js b/src/jsx.js index b15ade8..cd60c2f 100644 --- a/src/jsx.js +++ b/src/jsx.js @@ -121,7 +121,7 @@ export function transformElement({name: type, attribs: props, children: childEle * @param {Array} [elements=[]] - Cheerio Elements * @return {Array} an array of plain objects describing React Elements */ -export function transformElements(elements: Array = []): Array { +export function transformElements(elements: Object[] = []): Array { return map(reject(elements, ['type', 'comment']), el => 'text' === el.type ? el.data : transformElement(el)); } @@ -143,7 +143,7 @@ export function transformElements(elements: Array = []): Array): Array { +export function flatten(...args: any[]): any[] { return transform(flattenDeep(args), (accumulator, value) => { if (!value) { return; @@ -173,7 +173,7 @@ export function flatten(...args: Array): Array { * *
{arrayToJSX([{type: 'h1', children: ['Hello world!']}])}
*/ -export function arrayToJSX(arr: Array = []): Array { +export function arrayToJSX(arr: Array = []): any[] { return map(arr, (el, key: number) => { if (isString(el)) { return el; @@ -221,6 +221,6 @@ export function htmlToArray(html: string = ''): Array { * *
{htmlToJSX('

Hello world!

')}
*/ -export function htmlToJSX(html: string = ''): Array { +export function htmlToJSX(html: string = ''): any[] { return arrayToJSX(htmlToArray(html)); } diff --git a/src/markdown.js b/src/markdown.js index 40e03bf..02a5286 100644 --- a/src/markdown.js +++ b/src/markdown.js @@ -75,7 +75,7 @@ export function markdownToArray(markdown: string = ''): Array { * *
{markdownToJSX('# Hello world!')}
*/ -export function markdownToJSX(markdown: string = ''): Array { +export function markdownToJSX(markdown: string = ''): any[] { markdown = trim(markdown); return markdown ? htmlToJSX(markdownToUnwrappedHTML(markdown)) : []; diff --git a/src/typedef.js b/src/typedef.js index 44d0450..c2b8d75 100644 --- a/src/typedef.js +++ b/src/typedef.js @@ -189,7 +189,7 @@ export type WatchmanFile = { export type WatchmanResponse = { root: string; subscription: string; - files: Array; + files: WatchmanFile[]; }; /** diff --git a/test/mock.js b/test/mock.js index 2dbba1b..1acd21a 100644 --- a/test/mock.js +++ b/test/mock.js @@ -34,7 +34,7 @@ dom.html = constant('html string'); const cheerioLoad = constant(dom); -function createElement(...args: Array) { +function createElement(...args: any[]) { return args; }