From 60e56c268fa43cee750cd410275f6d32dd4cf478 Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 17 Jan 2017 08:06:10 -0800 Subject: [PATCH] react-router: Lint (#14063) --- react-router/index.d.ts | 6 ++--- react-router/lib/Route.d.ts | 4 ++-- react-router/lib/RouteContext.d.ts | 2 +- react-router/lib/Router.d.ts | 32 +++++++++++++------------- react-router/lib/routerHistory.d.ts | 10 ++++---- react-router/lib/useRouterHistory.d.ts | 6 +---- react-router/lib/withRouter.d.ts | 2 +- react-router/tslint.json | 7 ++++++ 8 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 react-router/tslint.json diff --git a/react-router/index.d.ts b/react-router/index.d.ts index 59f33e1960..80b1b97154 100644 --- a/react-router/index.d.ts +++ b/react-router/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-router v2.0.0 +// Type definitions for react-router 2.0 // Project: https://github.com/rackt/react-router // Definitions by: Sergey Buturlakin , Yuichi Murata , Václav Ostrožlík , Nathan Brown , Alex Wendland , Kostya Esmukov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -9,9 +9,9 @@ export as namespace ReactRouter; import * as React from 'react'; -export const routerShape: React.Requireable +export const routerShape: React.Requireable; -export const locationShape: React.Requireable +export const locationShape: React.Requireable; import Router from "./lib/Router"; import Link from "./lib/Link"; diff --git a/react-router/lib/Route.d.ts b/react-router/lib/Route.d.ts index 2f5425b55a..cf1e6a7fc4 100644 --- a/react-router/lib/Route.d.ts +++ b/react-router/lib/Route.d.ts @@ -12,8 +12,8 @@ declare namespace self { path?: Router.RoutePattern; component?: Router.RouteComponent; components?: Router.RouteComponents; - getComponent?: (nextState: Router.RouterState, cb: (error: any, component?: Router.RouteComponent) => void) => void - getComponents?: (nextState: Router.RouterState, cb: (error: any, components?: Router.RouteComponents) => void) => void + getComponent?: (nextState: Router.RouterState, cb: (error: any, component?: Router.RouteComponent) => void) => void; + getComponents?: (nextState: Router.RouterState, cb: (error: any, components?: Router.RouteComponents) => void) => void; onEnter?: Router.EnterHook; onLeave?: Router.LeaveHook; onChange?: Router.ChangeHook; diff --git a/react-router/lib/RouteContext.d.ts b/react-router/lib/RouteContext.d.ts index c35ab92a80..19225af17e 100644 --- a/react-router/lib/RouteContext.d.ts +++ b/react-router/lib/RouteContext.d.ts @@ -1,5 +1,5 @@ import * as React from 'react'; -declare const RouteContext: React.Mixin +declare const RouteContext: React.Mixin; export default RouteContext; diff --git a/react-router/lib/Router.d.ts b/react-router/lib/Router.d.ts index a9c5417f47..a7dff58369 100644 --- a/react-router/lib/Router.d.ts +++ b/react-router/lib/Router.d.ts @@ -16,7 +16,7 @@ export default Router; declare namespace Router { type RouteConfig = React.ReactNode | PlainRoute | PlainRoute[]; type RoutePattern = string; - type RouteComponents = { [key: string]: RouteComponent }; + interface RouteComponents { [key: string]: RouteComponent; } type ParseQueryString = (queryString: QueryString) => Query; type StringifyQuery = (queryObject: Query) => QueryString; @@ -29,15 +29,15 @@ declare namespace Router { type ChangeHook = (prevState: RouterState, nextState: RouterState, replace: RedirectFunction, callback: Function) => void; type RouteHook = (nextLocation?: Location) => any; - type Params = { [param: string]: string }; + interface Params { [param: string]: string; } type RouterListener = (error: Error, nextState: RouterState) => void; - type LocationDescriptor = { - pathname?: Pathname - query?: Query - hash?: Href - state?: HLocationState + interface LocationDescriptor { + pathname?: Pathname; + query?: Query; + hash?: Href; + state?: HLocationState; } interface RedirectFunction { @@ -103,14 +103,14 @@ declare namespace Router { // https://github.com/reactjs/react-router/blob/v2.4.0/upgrade-guides/v2.4.0.md interface InjectedRouter { - push: (pathOrLoc: Path | LocationDescriptor) => void - replace: (pathOrLoc: Path | LocationDescriptor) => void - go: (n: number) => void - goBack: () => void - goForward: () => void - setRouteLeaveHook(route: PlainRoute, callback: RouteHook): void - createPath(path: History.Path, query?: History.Query): History.Path - createHref(path: History.Path, query?: History.Query): History.Href - isActive: (pathOrLoc: Path | LocationDescriptor, indexOnly?: boolean) => boolean + push: (pathOrLoc: Path | LocationDescriptor) => void; + replace: (pathOrLoc: Path | LocationDescriptor) => void; + go: (n: number) => void; + goBack: () => void; + goForward: () => void; + setRouteLeaveHook(route: PlainRoute, callback: RouteHook): void; + createPath(path: History.Path, query?: History.Query): History.Path; + createHref(path: History.Path, query?: History.Query): History.Href; + isActive: (pathOrLoc: Path | LocationDescriptor, indexOnly?: boolean) => boolean; } } diff --git a/react-router/lib/routerHistory.d.ts b/react-router/lib/routerHistory.d.ts index 660af424b4..93558ff11f 100644 --- a/react-router/lib/routerHistory.d.ts +++ b/react-router/lib/routerHistory.d.ts @@ -4,11 +4,11 @@ import * as H from 'history'; export default History; export interface HistoryRoutes { - listen(listener: Router.RouterListener): Function - listenBeforeLeavingRoute(route: Router.PlainRoute, hook: Router.RouteHook): void - match(location: H.Location, callback: (error: any, nextState: Router.RouterState, nextLocation: H.Location) => void): void - isActive(pathname: H.Pathname, query?: H.Query, indexOnly?: boolean): boolean - setRouteLeaveHook(route: Router.PlainRoute, callback: Router.RouteHook): void + listen(listener: Router.RouterListener): Function; + listenBeforeLeavingRoute(route: Router.PlainRoute, hook: Router.RouteHook): void; + match(location: H.Location, callback: (error: any, nextState: Router.RouterState, nextLocation: H.Location) => void): void; + isActive(pathname: H.Pathname, query?: H.Query, indexOnly?: boolean): boolean; + setRouteLeaveHook(route: Router.PlainRoute, callback: Router.RouteHook): void; } export interface HistoryBase extends H.History { diff --git a/react-router/lib/useRouterHistory.d.ts b/react-router/lib/useRouterHistory.d.ts index d3e043b609..160375d2f0 100644 --- a/react-router/lib/useRouterHistory.d.ts +++ b/react-router/lib/useRouterHistory.d.ts @@ -1,7 +1,3 @@ import { History, HistoryOptions, HistoryQueries, CreateHistory } from 'history'; -interface CreateRouterHistory { - (options?: HistoryOptions): History & HistoryQueries; -} - -export default function useRouterHistory(createHistory: CreateHistory): CreateRouterHistory; +export default function useRouterHistory(createHistory: CreateHistory): (options?: HistoryOptions) => History & HistoryQueries; diff --git a/react-router/lib/withRouter.d.ts b/react-router/lib/withRouter.d.ts index f698d94fd0..71330bbb21 100644 --- a/react-router/lib/withRouter.d.ts +++ b/react-router/lib/withRouter.d.ts @@ -1,4 +1,4 @@ import * as React from 'react'; -declare function withRouter | React.StatelessComponent | React.PureComponent>(component: C): C +declare function withRouter | React.StatelessComponent | React.PureComponent>(component: C): C; export default withRouter; diff --git a/react-router/tslint.json b/react-router/tslint.json new file mode 100644 index 0000000000..e050abdce9 --- /dev/null +++ b/react-router/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "../tslint.json", + "rules": { + "forbidden-types": false, + "no-empty-interface": false + } +} \ No newline at end of file