Skip to content

Commit

Permalink
add import type rule
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 authored and markerikson committed Jun 13, 2023
1 parent 94c09f4 commit b5f7ec9
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 40 deletions.
32 changes: 26 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
"react": {
"version": "detect"
},
"import/ignore": ["react-native"],
"import/ignore": [
"react-native"
],
"import/resolver": {
"node": {
"extensions": [".js", ".ts", ".tsx"]
"extensions": [
".js",
".ts",
".tsx"
]
}
}
},
Expand All @@ -38,12 +44,26 @@
"react/jsx-wrap-multilines": 2,
"react/no-string-refs": 0,
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error"],
"@typescript-eslint/no-unused-vars": [
"error"
],
"no-redeclare": "off",
"@typescript-eslint/no-redeclare": ["error"]
"@typescript-eslint/no-redeclare": [
"error"
],
"@typescript-eslint/consistent-type-imports": [
"error",
{
"prefer": "type-imports"
}
]
},
"plugins": ["@typescript-eslint", "import", "react"],
"plugins": [
"@typescript-eslint",
"import",
"react"
],
"globals": {
"JSX": true
}
}
}
8 changes: 5 additions & 3 deletions src/components/Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { Context, ReactNode, useMemo } from 'react'
import { ReactReduxContext, ReactReduxContextValue } from './Context'
import type { Context, ReactNode } from 'react'
import React, { useMemo } from 'react'
import type { ReactReduxContextValue } from './Context'
import { ReactReduxContext } from './Context'
import { createSubscription } from '../utils/Subscription'
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
import { Action, AnyAction, Store } from 'redux'
import type { Action, AnyAction, Store } from 'redux'
import type { CheckFrequency } from '../hooks/useSelector'

export interface ProviderProps<A extends Action = AnyAction, S = unknown> {
Expand Down
13 changes: 8 additions & 5 deletions src/components/connect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable valid-jsdoc, @typescript-eslint/no-unused-vars */
import hoistStatics from 'hoist-non-react-statics'
import React, { ComponentType, useContext, useMemo, useRef } from 'react'
import type { ComponentType } from 'react'
import React, { useContext, useMemo, useRef } from 'react'
import { isValidElementType, isContextConsumer } from 'react-is'

import type { Store } from 'redux'
Expand All @@ -14,27 +15,29 @@ import type {
ConnectPropsMaybeWithoutContext,
} from '../types'

import defaultSelectorFactory, {
import type {
MapStateToPropsParam,
MapDispatchToPropsParam,
MergeProps,
MapDispatchToPropsNonObject,
SelectorFactoryOptions,
} from '../connect/selectorFactory'
import defaultSelectorFactory from '../connect/selectorFactory'
import { mapDispatchToPropsFactory } from '../connect/mapDispatchToProps'
import { mapStateToPropsFactory } from '../connect/mapStateToProps'
import { mergePropsFactory } from '../connect/mergeProps'

import { createSubscription, Subscription } from '../utils/Subscription'
import type { Subscription } from '../utils/Subscription'
import { createSubscription } from '../utils/Subscription'
import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'
import shallowEqual from '../utils/shallowEqual'
import warning from '../utils/warning'

import {
ReactReduxContext,
import type {
ReactReduxContextValue,
ReactReduxContextInstance,
} from './Context'
import { ReactReduxContext } from './Context'

import type { uSES } from '../utils/useSyncExternalStore'
import { notInitialized } from '../utils/useSyncExternalStore'
Expand Down
4 changes: 2 additions & 2 deletions src/connect/wrapMapToProps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionCreatorsMapObject, Dispatch, ActionCreator } from 'redux'
import type { ActionCreatorsMapObject, Dispatch, ActionCreator } from 'redux'

import { FixTypeLater } from '../types'
import type { FixTypeLater } from '../types'
import verifyPlainObject from '../utils/verifyPlainObject'

type AnyState = { [key: string]: any }
Expand Down
10 changes: 4 additions & 6 deletions src/hooks/useDispatch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Action, AnyAction, Dispatch } from 'redux'
import { Context } from 'react'
import type { Action, AnyAction, Dispatch } from 'redux'
import type { Context } from 'react'

import {
ReactReduxContext,
ReactReduxContextValue,
} from '../components/Context'
import type { ReactReduxContextValue } from '../components/Context'
import { ReactReduxContext } from '../components/Context'
import { useStore as useDefaultStore, createStoreHook } from './useStore'

/**
Expand Down
12 changes: 5 additions & 7 deletions src/hooks/useStore.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Context } from 'react'
import { Action as BasicAction, AnyAction, Store } from 'redux'
import type { Context } from 'react'
import type { Action as BasicAction, AnyAction, Store } from 'redux'
import type { ReactReduxContextValue } from '../components/Context'
import { ReactReduxContext } from '../components/Context'
import {
ReactReduxContext,
ReactReduxContextValue,
} from '../components/Context'
import {
createReduxContextHook,
useReduxContext as useDefaultReduxContext,
createReduxContextHook,
} from './useReduxContext'

/**
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
import type {
ClassAttributes,
ComponentClass,
ComponentType,
FunctionComponent,
} from 'react'

import { Action, AnyAction, Dispatch } from 'redux'
import type { Action, AnyAction, Dispatch } from 'redux'

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

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

import { UseSelectorOptions } from './hooks/useSelector'
import type { UseSelectorOptions } from './hooks/useSelector'

export type FixTypeLater = any

Expand Down
2 changes: 1 addition & 1 deletion src/utils/bindActionCreators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionCreatorsMapObject, Dispatch } from 'redux'
import type { ActionCreatorsMapObject, Dispatch } from 'redux'

export default function bindActionCreators(
actionCreators: ActionCreatorsMapObject,
Expand Down
3 changes: 2 additions & 1 deletion test/components/Provider.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*eslint-disable react/prop-types*/

import React, { Component, Dispatch } from 'react'
import type { Dispatch } from 'react'
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import { createStore } from 'redux'
import { Provider, connect, ReactReduxContext } from '../../src/index'
Expand Down
4 changes: 2 additions & 2 deletions test/components/connect.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*eslint-disable react/prop-types*/

import React, { Component, MouseEvent } from 'react'
import React, { Component } from 'react'
import { createStore, applyMiddleware } from 'redux'
import { Provider as ProviderMock, connect } from '../../src/index'
import * as rtl from '@testing-library/react'
import '@testing-library/jest-dom/extend-expect'
import type { ReactNode, Dispatch, ElementType } from 'react'
import type { ReactNode, Dispatch, ElementType, MouseEvent } from 'react'
import type {
Store,
Dispatch as ReduxDispatch,
Expand Down
8 changes: 4 additions & 4 deletions test/hooks/useSelector.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import React, {
useState,
useContext,
} from 'react'
import { Action, createStore } from 'redux'
import { createStore } from 'redux'
import * as rtl from '@testing-library/react'
import {
Provider,
ProviderProps,
useSelector,
useDispatch,
shallowEqual,
connect,
createSelectorHook,
ReactReduxContext,
Subscription,
} from '../../src/index'
import type {
TypedUseSelectorHook,
ReactReduxContextValue,
ProviderProps,
Subscription,
} from '../../src/index'
import type { FunctionComponent, DispatchWithoutAction, ReactNode } from 'react'
import type { Store, AnyAction } from 'redux'
import type { Store, AnyAction, Action } from 'redux'
import type { UseSelectorOptions } from '../../src/hooks/useSelector'

// disable checks by default
Expand Down

0 comments on commit b5f7ec9

Please sign in to comment.