Skip to content

Commit c2f5e59

Browse files
committed
fix test error
1 parent b82ff3a commit c2f5e59

File tree

17 files changed

+141
-129
lines changed

17 files changed

+141
-129
lines changed

.github/workflows/test-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
e2e:
3232
runs-on: ubuntu-latest
3333
container:
34-
image: mcr.microsoft.com/playwright:v1.55.0-focal
34+
image: mcr.microsoft.com/playwright:v1.55.0-noble
3535
steps:
3636
- name: Checkout
3737
uses: actions/checkout@v4

eslint.config.mjs

Lines changed: 85 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -18,85 +18,100 @@ const compat = new FlatCompat({
1818
});
1919

2020
export default defineConfig([
21-
globalIgnores(["**/dist/", "**/node_modules", "**/scripts", "**/examples"]),
22-
{
23-
extends: compat.extends(
24-
"eslint:recommended",
25-
"plugin:react/recommended",
26-
"plugin:@typescript-eslint/recommended",
27-
"prettier",
28-
"plugin:jest-dom/recommended",
29-
"plugin:testing-library/react",
30-
"plugin:react/jsx-runtime",
31-
),
21+
globalIgnores([
22+
'**/dist/',
23+
'**/node_modules',
24+
'**/scripts',
25+
'**/examples',
26+
'**/.next',
27+
'**/next.config.js',
28+
'eslint.config.mjs',
29+
'playwright.config.js'
30+
]),
31+
{
32+
extends: compat.extends(
33+
'eslint:recommended',
34+
'plugin:react/recommended',
35+
'plugin:@typescript-eslint/recommended',
36+
'prettier',
37+
'plugin:jest-dom/recommended',
38+
'plugin:testing-library/react',
39+
'plugin:react/jsx-runtime'
40+
),
3241

33-
plugins: {
34-
"@typescript-eslint": typescriptEslint,
35-
"react-hooks": fixupPluginRules(reactHooks),
36-
},
37-
38-
languageOptions: {
39-
globals: {
40-
...globals.browser,
41-
...globals.node,
42-
...globals.jest,
43-
},
42+
plugins: {
43+
'@typescript-eslint': typescriptEslint,
44+
'react-hooks': fixupPluginRules(reactHooks)
45+
},
4446

45-
parser: tsParser,
46-
ecmaVersion: 8,
47-
sourceType: "module",
47+
languageOptions: {
48+
globals: {
49+
...globals.browser,
50+
...globals.node,
51+
...globals.jest
52+
},
4853

49-
parserOptions: {
50-
ecmaFeatures: {
51-
impliedStrict: true,
52-
experimentalObjectRestSpread: true,
53-
},
54+
parser: tsParser,
55+
ecmaVersion: 8,
56+
sourceType: 'module',
5457

55-
allowImportExportEverywhere: true,
56-
project: ["**/tsconfig.json"],
57-
},
58+
parserOptions: {
59+
ecmaFeatures: {
60+
impliedStrict: true,
61+
experimentalObjectRestSpread: true
5862
},
5963

60-
settings: {
61-
react: {
62-
version: "detect",
63-
},
64-
},
64+
allowImportExportEverywhere: true,
65+
project: ['**/tsconfig.json']
66+
}
67+
},
6568

66-
rules: {
67-
"func-names": [2, "as-needed"],
68-
"no-shadow": 0,
69-
"@typescript-eslint/no-shadow": 2,
70-
"@typescript-eslint/explicit-function-return-type": 0,
69+
settings: {
70+
react: {
71+
version: 'detect'
72+
}
73+
},
7174

72-
"@typescript-eslint/no-unused-vars": [0, {
73-
argsIgnorePattern: "^_",
74-
}],
75+
rules: {
76+
'func-names': [2, 'as-needed'],
77+
'no-shadow': 0,
78+
'@typescript-eslint/no-shadow': 2,
79+
'@typescript-eslint/explicit-function-return-type': 0,
7580

76-
"@typescript-eslint/no-use-before-define": 0,
77-
"@typescript-eslint/ban-ts-ignore": 0,
78-
"@typescript-eslint/no-empty-function": 0,
79-
"@typescript-eslint/ban-ts-comment": 0,
80-
"@typescript-eslint/no-var-requires": 0,
81-
"@typescript-eslint/no-explicit-any": 0,
82-
"@typescript-eslint/explicit-module-boundary-types": 0,
81+
'@typescript-eslint/no-unused-vars': [
82+
0,
83+
{
84+
argsIgnorePattern: '^_'
85+
}
86+
],
8387

84-
"@typescript-eslint/consistent-type-imports": [2, {
85-
prefer: "type-imports",
86-
}],
88+
'@typescript-eslint/no-use-before-define': 0,
89+
'@typescript-eslint/ban-ts-ignore': 0,
90+
'@typescript-eslint/no-empty-function': 0,
91+
'@typescript-eslint/ban-ts-comment': 0,
92+
'@typescript-eslint/no-var-requires': 0,
93+
'@typescript-eslint/no-explicit-any': 0,
94+
'@typescript-eslint/explicit-module-boundary-types': 0,
8795

88-
"@typescript-eslint/ban-types": 0,
89-
"react-hooks/rules-of-hooks": 2,
90-
"react-hooks/exhaustive-deps": 1,
91-
"react/prop-types": 0,
92-
"testing-library/no-unnecessary-act": 0,
93-
},
94-
},
95-
{
96-
files: ["e2e/**/*.ts"],
96+
'@typescript-eslint/consistent-type-imports': [
97+
2,
98+
{
99+
prefer: 'type-imports'
100+
}
101+
],
97102

98-
rules: {
99-
"testing-library/prefer-screen-queries": "off",
100-
},
101-
},
102-
]);
103+
'@typescript-eslint/ban-types': 0,
104+
'react-hooks/rules-of-hooks': 2,
105+
'react-hooks/exhaustive-deps': 1,
106+
'react/prop-types': 0,
107+
'testing-library/no-unnecessary-act': 0
108+
}
109+
},
110+
{
111+
files: ['e2e/**/*.ts'],
112+
113+
rules: {
114+
'testing-library/prefer-screen-queries': 'off'
115+
}
116+
}
117+
])

src/_internal/types.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ export type Fetcher<
2020
> = SWRKey extends () => infer Arg | null | undefined | false
2121
? (arg: Arg) => FetcherResponse<Data>
2222
: SWRKey extends null | undefined | false
23-
? never
24-
: SWRKey extends infer Arg
25-
? (arg: Arg) => FetcherResponse<Data>
26-
: never
23+
? never
24+
: SWRKey extends infer Arg
25+
? (arg: Arg) => FetcherResponse<Data>
26+
: never
2727

2828
export type BlockingData<
2929
Data = any,
3030
Options = SWROptions<Data>
3131
> = SWRGlobalConfig extends { suspense: true }
3232
? true
3333
: Options extends undefined
34-
? false
35-
: Options extends { suspense: true }
36-
? true
37-
: Options extends { fallbackData: Data | Promise<Data> }
38-
? true
39-
: false
34+
? false
35+
: Options extends { suspense: true }
36+
? true
37+
: Options extends { fallbackData: Data | Promise<Data> }
38+
? true
39+
: false
4040

4141
// Configuration types that are only used internally, not exposed to the user.
4242
export interface InternalConfiguration {
@@ -237,95 +237,95 @@ export interface SWRHook {
237237
Data = any,
238238
Error = any,
239239
SWRKey extends Key = StrictKey,
240-
SWROptions extends
240+
SWRHookOptions extends
241241
| SWRConfiguration<Data, Error, Fetcher<Data, SWRKey>>
242242
| undefined =
243243
| SWRConfiguration<Data, Error, Fetcher<Data, SWRKey>>
244244
| undefined
245245
>(
246246
key: SWRKey
247-
): SWRResponse<Data, Error, SWROptions>
247+
): SWRResponse<Data, Error, SWRHookOptions>
248248
<
249249
Data = any,
250250
Error = any,
251251
SWRKey extends Key = StrictKey,
252-
SWROptions extends
252+
SWRHookOptions extends
253253
| SWRConfiguration<Data, Error, Fetcher<Data, SWRKey>>
254254
| undefined =
255255
| SWRConfiguration<Data, Error, Fetcher<Data, SWRKey>>
256256
| undefined
257257
>(
258258
key: SWRKey,
259259
fetcher: Fetcher<Data, SWRKey> | null
260-
): SWRResponse<Data, Error, SWROptions>
260+
): SWRResponse<Data, Error, SWRHookOptions>
261261
<
262262
Data = any,
263263
Error = any,
264264
SWRKey extends Key = StrictKey,
265-
SWROptions extends
265+
SWRHookOptions extends
266266
| SWRConfiguration<Data, Error, Fetcher<Data, SWRKey>>
267267
| undefined =
268268
| SWRConfiguration<Data, Error, Fetcher<Data, SWRKey>>
269269
| undefined
270270
>(
271271
key: SWRKey,
272-
config: SWRConfigurationWithOptionalFallback<SWROptions>
273-
): SWRResponse<Data, Error, SWROptions>
272+
config: SWRConfigurationWithOptionalFallback<SWRHookOptions>
273+
): SWRResponse<Data, Error, SWRHookOptions>
274274
<
275275
Data = any,
276276
Error = any,
277277
SWRKey extends Key = StrictKey,
278-
SWROptions extends
278+
SWRHookOptions extends
279279
| SWRConfiguration<Data, Error, Fetcher<Data, SWRKey>>
280280
| undefined =
281281
| SWRConfiguration<Data, Error, Fetcher<Data, SWRKey>>
282282
| undefined
283283
>(
284284
key: SWRKey,
285285
fetcher: Fetcher<Data, SWRKey> | null,
286-
config: SWRConfigurationWithOptionalFallback<SWROptions>
287-
): SWRResponse<Data, Error, SWROptions>
286+
config: SWRConfigurationWithOptionalFallback<SWRHookOptions>
287+
): SWRResponse<Data, Error, SWRHookOptions>
288288
<Data = any, Error = any>(key: Key): SWRResponse<Data, Error>
289289
<
290290
Data = any,
291291
Error = any,
292-
SWROptions extends
292+
SWRHookOptions extends
293293
| SWRConfiguration<Data, Error, BareFetcher<Data>>
294294
| undefined = SWRConfiguration<Data, Error, BareFetcher<Data>> | undefined
295295
>(
296296
key: Key
297-
): SWRResponse<Data, Error, SWROptions>
297+
): SWRResponse<Data, Error, SWRHookOptions>
298298
<
299299
Data = any,
300300
Error = any,
301-
SWROptions extends
301+
SWRHookOptions extends
302302
| SWRConfiguration<Data, Error, BareFetcher<Data>>
303303
| undefined = SWRConfiguration<Data, Error, BareFetcher<Data>> | undefined
304304
>(
305305
key: Key,
306306
fetcher: BareFetcher<Data> | null
307-
): SWRResponse<Data, Error, SWROptions>
307+
): SWRResponse<Data, Error, SWRHookOptions>
308308
<
309309
Data = any,
310310
Error = any,
311-
SWROptions extends
311+
SWRHookOptions extends
312312
| SWRConfiguration<Data, Error, BareFetcher<Data>>
313313
| undefined = SWRConfiguration<Data, Error, BareFetcher<Data>> | undefined
314314
>(
315315
key: Key,
316-
config: SWRConfigurationWithOptionalFallback<SWROptions>
317-
): SWRResponse<Data, Error, SWROptions>
316+
config: SWRConfigurationWithOptionalFallback<SWRHookOptions>
317+
): SWRResponse<Data, Error, SWRHookOptions>
318318
<
319319
Data = any,
320320
Error = any,
321-
SWROptions extends
321+
SWRHookOptions extends
322322
| SWRConfiguration<Data, Error, BareFetcher<Data>>
323323
| undefined = SWRConfiguration<Data, Error, BareFetcher<Data>> | undefined
324324
>(
325325
key: Key,
326326
fetcher: BareFetcher<Data> | null,
327-
config: SWRConfigurationWithOptionalFallback<SWROptions>
328-
): SWRResponse<Data, Error, SWROptions>
327+
config: SWRConfigurationWithOptionalFallback<SWRHookOptions>
328+
): SWRResponse<Data, Error, SWRHookOptions>
329329
}
330330

331331
// Middleware guarantees that a SWRHook receives a key, fetcher, and config as the argument
@@ -403,10 +403,10 @@ export type MutatorWrapper<Fn> = Fn extends (
403403
? Parameters[3] extends boolean
404404
? Result
405405
: Parameters[3] extends Required<Pick<MutatorOptions, 'populateCache'>>
406-
? Parameters[3]['populateCache'] extends false
407-
? never
406+
? Parameters[3]['populateCache'] extends false
407+
? never
408+
: Result
408409
: Result
409-
: Result
410410
: never
411411

412412
export type Mutator<Data = any> = MutatorWrapper<MutatorFn<Data>>

src/_internal/utils/cache.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ export const initCache = <Data = any>(
108108
)
109109
)
110110
unmount = () => {
111+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
111112
releaseFocus && releaseFocus()
113+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
112114
releaseReconnect && releaseReconnect()
113115
// When un-mounting, we need to remove the cache provider from the state
114116
// storage too because it's a side-effect. Otherwise, when re-mounting we

src/_internal/utils/config-context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const SWRConfig: FC<
5959
// Unsubscribe events.
6060
useIsomorphicLayoutEffect(() => {
6161
if (cacheContext) {
62+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
6263
cacheContext[2] && cacheContext[2]()
6364
return cacheContext[3]
6465
}

src/mutation/state.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export const useStateWithDeps = <S = Record<string, any>>(
6363
// If the property has changed, update the state and mark rerender as
6464
// needed.
6565
if (currentState[k] !== payload[k]) {
66-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
6766
currentState[k] = payload[k]!
6867

6968
// If the property is accessed by the component, a rerender should be

src/subscription/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const subscription = (<Data = any, Error = any>(useSWRNext: SWRHook) =>
4848
])
4949
}
5050

51-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
5251
const [subscriptions, disposers] = subscriptionStorage.get(cache)!
5352

5453
useIsomorphicLayoutEffect(() => {
@@ -83,7 +82,6 @@ export const subscription = (<Data = any, Error = any>(useSWRNext: SWRHook) =>
8382
}
8483

8584
return () => {
86-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8785
const count = subscriptions.get(subscriptionKey)! - 1
8886

8987
subscriptions.set(subscriptionKey, count)
@@ -94,8 +92,6 @@ export const subscription = (<Data = any, Error = any>(useSWRNext: SWRHook) =>
9492
dispose?.()
9593
}
9694
}
97-
98-
// eslint-disable-next-line react-hooks/exhaustive-deps
9995
}, [subscriptionKey])
10096

10197
return {

0 commit comments

Comments
 (0)