Skip to content

Commit 0be8522

Browse files
EskiMojo14markerikson
authored andcommitted
add import type rule
1 parent 084b87c commit 0be8522

File tree

11 files changed

+62
-40
lines changed

11 files changed

+62
-40
lines changed

.eslintrc

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@
1111
"react": {
1212
"version": "detect"
1313
},
14-
"import/ignore": ["react-native"],
14+
"import/ignore": [
15+
"react-native"
16+
],
1517
"import/resolver": {
1618
"node": {
17-
"extensions": [".js", ".ts", ".tsx"]
19+
"extensions": [
20+
".js",
21+
".ts",
22+
".tsx"
23+
]
1824
}
1925
}
2026
},
@@ -38,12 +44,26 @@
3844
"react/jsx-wrap-multilines": 2,
3945
"react/no-string-refs": 0,
4046
"no-unused-vars": "off",
41-
"@typescript-eslint/no-unused-vars": ["error"],
47+
"@typescript-eslint/no-unused-vars": [
48+
"error"
49+
],
4250
"no-redeclare": "off",
43-
"@typescript-eslint/no-redeclare": ["error"]
51+
"@typescript-eslint/no-redeclare": [
52+
"error"
53+
],
54+
"@typescript-eslint/consistent-type-imports": [
55+
"error",
56+
{
57+
"prefer": "type-imports"
58+
}
59+
]
4460
},
45-
"plugins": ["@typescript-eslint", "import", "react"],
61+
"plugins": [
62+
"@typescript-eslint",
63+
"import",
64+
"react"
65+
],
4666
"globals": {
4767
"JSX": true
4868
}
49-
}
69+
}

src/components/Provider.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import React, { Context, ReactNode, useMemo } from 'react'
2-
import { ReactReduxContext, ReactReduxContextValue } from './Context'
1+
import type { Context, ReactNode } from 'react'
2+
import React, { useMemo } from 'react'
3+
import type { ReactReduxContextValue } from './Context'
4+
import { ReactReduxContext } from './Context'
35
import { createSubscription } from '../utils/Subscription'
46
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
5-
import { Action, AnyAction, Store } from 'redux'
7+
import type { Action, AnyAction, Store } from 'redux'
68
import type { CheckFrequency } from '../hooks/useSelector'
79

810
export interface ProviderProps<A extends Action = AnyAction, S = unknown> {

src/components/connect.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable valid-jsdoc, @typescript-eslint/no-unused-vars */
22
import hoistStatics from 'hoist-non-react-statics'
3-
import React, { ComponentType, useContext, useMemo, useRef } from 'react'
3+
import type { ComponentType } from 'react'
4+
import React, { useContext, useMemo, useRef } from 'react'
45
import { isValidElementType, isContextConsumer } from 'react-is'
56

67
import type { Store } from 'redux'
@@ -14,27 +15,29 @@ import type {
1415
ConnectPropsMaybeWithoutContext,
1516
} from '../types'
1617

17-
import defaultSelectorFactory, {
18+
import type {
1819
MapStateToPropsParam,
1920
MapDispatchToPropsParam,
2021
MergeProps,
2122
MapDispatchToPropsNonObject,
2223
SelectorFactoryOptions,
2324
} from '../connect/selectorFactory'
25+
import defaultSelectorFactory from '../connect/selectorFactory'
2426
import { mapDispatchToPropsFactory } from '../connect/mapDispatchToProps'
2527
import { mapStateToPropsFactory } from '../connect/mapStateToProps'
2628
import { mergePropsFactory } from '../connect/mergeProps'
2729

28-
import { createSubscription, Subscription } from '../utils/Subscription'
30+
import type { Subscription } from '../utils/Subscription'
31+
import { createSubscription } from '../utils/Subscription'
2932
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
3033
import shallowEqual from '../utils/shallowEqual'
3134
import warning from '../utils/warning'
3235

33-
import {
34-
ReactReduxContext,
36+
import type {
3537
ReactReduxContextValue,
3638
ReactReduxContextInstance,
3739
} from './Context'
40+
import { ReactReduxContext } from './Context'
3841

3942
import type { uSES } from '../utils/useSyncExternalStore'
4043
import { notInitialized } from '../utils/useSyncExternalStore'

src/connect/wrapMapToProps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ActionCreatorsMapObject, Dispatch, ActionCreator } from 'redux'
1+
import type { ActionCreatorsMapObject, Dispatch, ActionCreator } from 'redux'
22

3-
import { FixTypeLater } from '../types'
3+
import type { FixTypeLater } from '../types'
44
import verifyPlainObject from '../utils/verifyPlainObject'
55

66
type AnyState = { [key: string]: any }

src/hooks/useDispatch.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { Action, AnyAction, Dispatch } from 'redux'
2-
import { Context } from 'react'
1+
import type { Action, AnyAction, Dispatch } from 'redux'
2+
import type { Context } from 'react'
33

4-
import {
5-
ReactReduxContext,
6-
ReactReduxContextValue,
7-
} from '../components/Context'
4+
import type { ReactReduxContextValue } from '../components/Context'
5+
import { ReactReduxContext } from '../components/Context'
86
import { useStore as useDefaultStore, createStoreHook } from './useStore'
97

108
/**

src/hooks/useStore.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { Context } from 'react'
2-
import { Action as BasicAction, AnyAction, Store } from 'redux'
1+
import type { Context } from 'react'
2+
import type { Action as BasicAction, AnyAction, Store } from 'redux'
3+
import type { ReactReduxContextValue } from '../components/Context'
4+
import { ReactReduxContext } from '../components/Context'
35
import {
4-
ReactReduxContext,
5-
ReactReduxContextValue,
6-
} from '../components/Context'
7-
import {
8-
createReduxContextHook,
96
useReduxContext as useDefaultReduxContext,
7+
createReduxContextHook,
108
} from './useReduxContext'
119

1210
/**

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import {
1+
import type {
22
ClassAttributes,
33
ComponentClass,
44
ComponentType,
55
FunctionComponent,
66
} from 'react'
77

8-
import { Action, AnyAction, Dispatch } from 'redux'
8+
import type { Action, AnyAction, Dispatch } from 'redux'
99

1010
import type { NonReactStatics } from 'hoist-non-react-statics'
1111

1212
import type { ConnectProps } from './components/connect'
1313

14-
import { UseSelectorOptions } from './hooks/useSelector'
14+
import type { UseSelectorOptions } from './hooks/useSelector'
1515

1616
export type FixTypeLater = any
1717

src/utils/bindActionCreators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ActionCreatorsMapObject, Dispatch } from 'redux'
1+
import type { ActionCreatorsMapObject, Dispatch } from 'redux'
22

33
export default function bindActionCreators(
44
actionCreators: ActionCreatorsMapObject,

test/components/Provider.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*eslint-disable react/prop-types*/
22

3-
import React, { Component, Dispatch } from 'react'
3+
import type { Dispatch } from 'react'
4+
import React, { Component } from 'react'
45
import ReactDOM from 'react-dom'
56
import { createStore } from 'redux'
67
import { Provider, connect, ReactReduxContext } from '../../src/index'

test/components/connect.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*eslint-disable react/prop-types*/
22

3-
import React, { Component, MouseEvent } from 'react'
3+
import React, { Component } from 'react'
44
import { createStore, applyMiddleware } from 'redux'
55
import { Provider as ProviderMock, connect } from '../../src/index'
66
import * as rtl from '@testing-library/react'
77
import '@testing-library/jest-dom/extend-expect'
8-
import type { ReactNode, Dispatch, ElementType } from 'react'
8+
import type { ReactNode, Dispatch, ElementType, MouseEvent } from 'react'
99
import type {
1010
Store,
1111
Dispatch as ReduxDispatch,

test/hooks/useSelector.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ import React, {
77
useState,
88
useContext,
99
} from 'react'
10-
import { Action, createStore } from 'redux'
10+
import { createStore } from 'redux'
1111
import * as rtl from '@testing-library/react'
1212
import {
1313
Provider,
14-
ProviderProps,
1514
useSelector,
1615
useDispatch,
1716
shallowEqual,
1817
connect,
1918
createSelectorHook,
2019
ReactReduxContext,
21-
Subscription,
2220
} from '../../src/index'
2321
import type {
2422
TypedUseSelectorHook,
2523
ReactReduxContextValue,
24+
ProviderProps,
25+
Subscription,
2626
} from '../../src/index'
2727
import type { FunctionComponent, DispatchWithoutAction, ReactNode } from 'react'
28-
import type { Store, AnyAction } from 'redux'
28+
import type { Store, AnyAction, Action } from 'redux'
2929
import type { UseSelectorOptions } from '../../src/hooks/useSelector'
3030

3131
// disable checks by default

0 commit comments

Comments
 (0)