Skip to content

Commit

Permalink
Merge pull request #2992 from thorn0/lint1
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson authored Jan 28, 2023
2 parents d9374c7 + e33dfb7 commit 0678c2e
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 49 deletions.
4 changes: 2 additions & 2 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@
"yargs": "^15.3.1"
},
"scripts": {
"build-ci": "yarn rimraf dist && yarn tsc && node scripts/cli.js --skipExtraction",
"build-ci": "yarn rimraf dist && yarn tsc && yarn lint && node scripts/cli.js --skipExtraction",
"build-prepare": "npm run build-ci",
"build": "yarn rimraf dist && yarn tsc && node scripts/cli.js --local --skipExtraction",
"build-only": "yarn rimraf dist && yarn tsc && node scripts/cli.js --skipExtraction",
"format": "prettier --write \"(src|examples)/**/*.{ts,tsx}\" \"**/*.md\"",
"format:check": "prettier --list-different \"(src|examples)/**/*.{ts,tsx}\" \"docs/*/**.md\"",
"lint": "eslint src examples",
"lint": "eslint src",
"test": "jest --runInBand",
"type-tests": "yarn tsc -p src/tests/tsconfig.typetests.json && yarn tsc -p src/query/tests/tsconfig.typetests.json",
"prepack": "npm run build-prepare"
Expand Down
16 changes: 8 additions & 8 deletions packages/toolkit/src/listenerMiddleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ export const createListenerEntry: TypedCreateListenerEntry<unknown> = (
return entry
}

const cancelActiveListeners = (
entry: ListenerEntry<unknown, Dispatch<AnyAction>>
) => {
entry.pending.forEach((controller) => {
abortControllerWithReason(controller, listenerCancelled)
})
}

const createClearListenerMiddleware = (
listenerMap: Map<string, ListenerEntry>
) => {
Expand Down Expand Up @@ -284,14 +292,6 @@ const defaultErrorHandler: ListenerErrorHandler = (...args: unknown[]) => {
console.error(`${alm}/error`, ...args)
}

const cancelActiveListeners = (
entry: ListenerEntry<unknown, Dispatch<AnyAction>>
) => {
entry.pending.forEach((controller) => {
abortControllerWithReason(controller, listenerCancelled)
})
}

/**
* @public
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import type {
Subscribers,
} from '../apiState'
import { produceWithPatches } from 'immer'
import { createSlice, PayloadAction, AnyAction } from '@reduxjs/toolkit'
import type { AnyAction } from '@reduxjs/toolkit';
import { createSlice, PayloadAction } from '@reduxjs/toolkit'

// Copied from https://github.com/feross/queue-microtask
let promise: Promise<any>
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/query/core/buildThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import type {
QueryActionCreatorResult,
} from './buildInitiate'
import { forceQueryFnSymbol, isUpsertQuery } from './buildInitiate'
import {
import type {
AssertTagTypes,
EndpointDefinition,
EndpointDefinitions,
isQueryDefinition,
MutationDefinition,
QueryArgFrom,
QueryDefinition,
ResultTypeFrom,
} from '../endpointDefinitions'
import { isQueryDefinition } from '../endpointDefinitions'
import { calculateProvidedBy } from '../endpointDefinitions'
import type { AsyncThunkPayloadCreator, Draft } from '@reduxjs/toolkit'
import {
Expand Down
6 changes: 2 additions & 4 deletions packages/toolkit/src/query/createApi.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type { Api, ApiContext, Module, ModuleName } from './apiTypes'
import type { CombinedState } from './core/apiState'
import type { BaseQueryArg, BaseQueryFn } from './baseQueryTypes'
import {
defaultSerializeQueryArgs,
SerializeQueryArgs,
} from './defaultSerializeQueryArgs'
import type { SerializeQueryArgs } from './defaultSerializeQueryArgs'
import { defaultSerializeQueryArgs } from './defaultSerializeQueryArgs'
import type {
EndpointBuilder,
EndpointDefinitions,
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/endpointDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnyAction, ThunkDispatch } from '@reduxjs/toolkit'
import { SerializeQueryArgs } from './defaultSerializeQueryArgs'
import type { SerializeQueryArgs } from './defaultSerializeQueryArgs'
import type { QuerySubState, RootState } from './core/apiState'
import type {
BaseQueryExtraOptions,
Expand Down
5 changes: 3 additions & 2 deletions packages/toolkit/src/query/react/ApiProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { configureStore } from '@reduxjs/toolkit'
import { Context, useEffect } from 'react'
import type { Context } from 'react'
import { useEffect } from 'react'
import React from 'react'
import type { ReactReduxContextValue } from 'react-redux'
import { Provider } from 'react-redux'
Expand Down Expand Up @@ -50,7 +51,7 @@ export function ApiProvider<A extends Api<any, {}, any, any>>(props: {
props.setupListeners === false
? undefined
: setupListeners(store.dispatch, props.setupListeners),
[props.setupListeners]
[props.setupListeners, store.dispatch]
)

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
BaseQueryExtraOptions,
BaseQueryFn,
} from './baseQueryTypes'
import { FetchBaseQueryError } from './fetchBaseQuery'
import type { FetchBaseQueryError } from './fetchBaseQuery'
import { HandledError } from './HandledError'

/**
Expand Down
7 changes: 2 additions & 5 deletions packages/toolkit/src/query/tests/buildHooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ import {
import { server } from './mocks/server'
import type { AnyAction } from 'redux'
import type { SubscriptionOptions } from '@reduxjs/toolkit/dist/query/core/apiState'
import {
createListenerMiddleware,
SerializedError,
configureStore,
} from '@reduxjs/toolkit'
import type { SerializedError } from '@reduxjs/toolkit'
import { createListenerMiddleware, configureStore } from '@reduxjs/toolkit'
import { renderHook } from '@testing-library/react'
import { delay } from '../../utils'

Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/tests/createApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from './helpers'
import { server } from './mocks/server'
import { rest } from 'msw'
import { SerializeQueryArgs } from '../defaultSerializeQueryArgs'
import type { SerializeQueryArgs } from '../defaultSerializeQueryArgs'
import { string } from 'yargs'

const originalEnv = process.env.NODE_ENV
Expand Down
7 changes: 2 additions & 5 deletions packages/toolkit/src/tests/autoBatchEnhancer.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { configureStore } from '../configureStore'
import { createSlice } from '../createSlice'
import {
autoBatchEnhancer,
prepareAutoBatched,
AutoBatchOptions,
} from '../autoBatchEnhancer'
import type { AutoBatchOptions } from '../autoBatchEnhancer'
import { autoBatchEnhancer, prepareAutoBatched } from '../autoBatchEnhancer'
import { delay } from '../utils'
import { debounce } from 'lodash'

Expand Down
43 changes: 27 additions & 16 deletions packages/toolkit/src/tests/configureStore.typetest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import type {
Reducer,
Store,
Action,
StoreEnhancer
StoreEnhancer,
} from 'redux'
import { applyMiddleware } from 'redux'
import type { PayloadAction } from '@reduxjs/toolkit'
import type { PayloadAction, ConfigureStoreOptions } from '@reduxjs/toolkit'
import {
configureStore,
getDefaultMiddleware,
createSlice,
ConfigureStoreOptions,
} from '@reduxjs/toolkit'
import type { ThunkMiddleware, ThunkAction, ThunkDispatch } from 'redux-thunk'
import thunk from 'redux-thunk'
Expand Down Expand Up @@ -144,10 +143,12 @@ const _anyMiddleware: any = () => () => () => {}
{
const store = configureStore({
reducer: () => 0,
enhancers: [applyMiddleware(() => next => next)]
enhancers: [applyMiddleware(() => (next) => next)],
})

expectType<Dispatch & ThunkDispatch<number, undefined, AnyAction>>(store.dispatch)
expectType<Dispatch & ThunkDispatch<number, undefined, AnyAction>>(
store.dispatch
)
}

configureStore({
Expand All @@ -159,7 +160,7 @@ const _anyMiddleware: any = () => () => () => {}
{
type SomePropertyStoreEnhancer = StoreEnhancer<{ someProperty: string }>

const somePropertyStoreEnhancer: SomePropertyStoreEnhancer = next => {
const somePropertyStoreEnhancer: SomePropertyStoreEnhancer = (next) => {
return (reducer, preloadedState) => {
return {
...next(reducer, preloadedState),
Expand All @@ -168,9 +169,13 @@ const _anyMiddleware: any = () => () => () => {}
}
}

type AnotherPropertyStoreEnhancer = StoreEnhancer<{ anotherProperty: number }>
type AnotherPropertyStoreEnhancer = StoreEnhancer<{
anotherProperty: number
}>

const anotherPropertyStoreEnhancer: AnotherPropertyStoreEnhancer = next => {
const anotherPropertyStoreEnhancer: AnotherPropertyStoreEnhancer = (
next
) => {
return (reducer, preloadedState) => {
return {
...next(reducer, preloadedState),
Expand All @@ -184,7 +189,9 @@ const _anyMiddleware: any = () => () => () => {}
enhancers: [somePropertyStoreEnhancer, anotherPropertyStoreEnhancer],
})

expectType<Dispatch & ThunkDispatch<number, undefined, AnyAction>>(store.dispatch)
expectType<Dispatch & ThunkDispatch<number, undefined, AnyAction>>(
store.dispatch
)
expectType<string>(store.someProperty)
expectType<number>(store.anotherProperty)
}
Expand Down Expand Up @@ -348,7 +355,9 @@ const _anyMiddleware: any = () => () => () => {}
{
const store = configureStore({
reducer: reducerA,
middleware: [] as any as readonly [Middleware<(a: StateA) => boolean, StateA>],
middleware: [] as any as readonly [
Middleware<(a: StateA) => boolean, StateA>
],
})
const result: boolean = store.dispatch(5)
// @ts-expect-error
Expand Down Expand Up @@ -532,21 +541,23 @@ const _anyMiddleware: any = () => () => () => {}
initialState: null as any,
reducers: {
set(state) {
return state;
return state
},
},
});
})

function configureMyStore<S>(options: Omit<ConfigureStoreOptions<S>, 'reducer'>) {
function configureMyStore<S>(
options: Omit<ConfigureStoreOptions<S>, 'reducer'>
) {
return configureStore({
...options,
reducer: someSlice.reducer,
});
})
}

const store = configureMyStore({});
const store = configureMyStore({})

expectType<Function>(store.dispatch);
expectType<Function>(store.dispatch)
}

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const rootReducer = combineSlices(sliceA, sliceB, {
// fileC.ts
// "naive" approach

import { rootReducer, RootState } from './reducer'
import type { RootState } from './reducer';
import { rootReducer } from './reducer'
import { createSlice } from '@reduxjs/toolkit'

interface SliceCState {
Expand Down

0 comments on commit 0678c2e

Please sign in to comment.