Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sachinraja committed Jul 31, 2022
1 parent fb3abce commit 28aef17
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 18 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"root": true,
"extends": "@sachinraja",
"ignorePatterns": ["/infinite"]
"ignorePatterns": ["/infinite", "next-env.d.ts"],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"unicorn/no-null": "off"
}
}
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
public-hoist-pattern[]=*types*
public-hoist-pattern[]=*eslint*
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"editor.defaultFormatter": "dprint.dprint",
"dprint.path": "node_modules/dprint/dprint",
"testing.automaticallyOpenPeekView": "never"
"eslint.workingDirectories": ["./", "./playground"]
}
1 change: 1 addition & 0 deletions playground/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ const nextConfig = {
},
}

// eslint-disable-next-line no-undef
module.exports = nextConfig
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface TRPCContextState<TRouter extends AnyRouter> {
>(
pathAndInput: [path: TPath, ...args: inferHandlerInput<TProcedure>],
data?: WrapPromiseAndMutatorCallback<TOutput>,
opts?: boolean | MutatorOptions<TOutput>,
options?: boolean | MutatorOptions<TOutput>,
): Promise<TOutput | undefined>
}

Expand Down
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'
import _useSWR, { Key, MutatorOptions, SWRConfiguration, SWRResponse, useSWRConfig } from 'swr'
import { TRPCContext, TRPCContextState } from './context'
import { inferProcedures, WrapPromiseAndMutatorCallback } from './types'
import { getClientArgs } from './utils'
import { getClientArguments } from './utils'

export interface UseSWROptions<TData, TError> extends TRPCRequestOptions, SWRConfiguration<TData, TError> {}

Expand Down Expand Up @@ -46,7 +46,7 @@ export function createSWRHooks<TRouter extends AnyRouter>() {
return _useSWR(
pathAndInput,
// @ts-expect-error normalize args
() => client.query(...getClientArgs(pathAndInput, config)),
() => client.query(...getClientArguments(pathAndInput, config)),
config,
)
}
Expand Down
12 changes: 6 additions & 6 deletions src/infinite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useContext } from 'react'
import useSWRInfinite, { SWRInfiniteConfiguration, SWRInfiniteResponse } from 'swr/infinite'
import { TRPCContext, TRPCContextState } from './context'
import { inferProcedures } from './types'
import { getClientArgs } from './utils'
import { getClientArguments } from './utils'

export interface UseSWRInfiniteOptions<TData, TError>
extends TRPCRequestOptions, SWRInfiniteConfiguration<TData, TError>
Expand All @@ -30,14 +30,14 @@ export const getUseSWRInfinite = <TRouter extends AnyRouter>() => {
const { client } = useContext(Context)

return useSWRInfinite(
(...keyArgs) => {
const args = getKey(...keyArgs)
if (args === null) return null
(...keyArguments) => {
const arguments_ = getKey(...keyArguments)
if (arguments_ === null) return null

return [path, ...args]
return [path, ...arguments_]
},
// @ts-expect-error normalize args
(...args) => client.query(...getClientArgs(args, config)),
(...arguments_) => client.query(...getClientArguments(arguments_, config)),
config,
)
}
Expand Down
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { MutatorCallback } from 'swr'
export type WrapPromiseAndMutatorCallback<TData> = TData | Promise<TData> | MutatorCallback<TData>

export type inferProcedures<
TObj extends ProcedureRecord<any, any, any, any, any, any>,
TObject extends ProcedureRecord<any, any, any, any, any, any>,
> = {
[TPath in keyof TObj]: {
input: inferProcedureInput<TObj[TPath]>
output: inferProcedureOutput<TObj[TPath]>
[TPath in keyof TObject]: {
input: inferProcedureInput<TObject[TPath]>
output: inferProcedureOutput<TObject[TPath]>
}
}
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function getClientArgs<TPathAndInput extends unknown[], TOptions>(
export function getClientArguments<TPathAndInput extends unknown[], TOptions>(
pathAndInput: TPathAndInput,
opts: TOptions,
options: TOptions,
) {
const [path, input] = pathAndInput
return [path, input, opts] as const
return [path, input, options] as const
}

0 comments on commit 28aef17

Please sign in to comment.