Skip to content

Commit 0943575

Browse files
authored
ci(*): init ESLint configurations to include 'vitest/expect-expect' rule as error across multiple packages gradually (#9104)
* chore(*): init ESLint configurations to include 'vitest/expect-expect' rule as error across multiple packages gradually * chore(query-core): remove unused import from ESLint configuration * chore(angular-query-experimental): update eslint rule * chore: integrate vitest ESLint plugin and apply recommended rules across multiple packages * chore(react-query-devtools): add vitest ESLint plugin to configuration
1 parent 127bd01 commit 0943575

27 files changed

Lines changed: 212 additions & 35 deletions

File tree

eslint.config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ export default [
4545
{
4646
files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
4747
plugins: { vitest },
48-
rules: {
49-
...vitest.configs.recommended.rules,
50-
'vitest/expect-expect': 'warn',
51-
},
48+
rules: vitest.configs.recommended.rules,
5249
settings: { vitest: { typecheck: true } },
5350
},
5451
]

packages/angular-query-experimental/eslint.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-check
22

33
import pluginJsdoc from 'eslint-plugin-jsdoc'
4+
import vitest from '@vitest/eslint-plugin'
45
import rootConfig from './root.eslint.config.js'
56

67
export default [
@@ -28,4 +29,13 @@ export default [
2829
],
2930
},
3031
},
32+
{
33+
plugins: { vitest },
34+
rules: {
35+
'vitest/expect-expect': [
36+
'error',
37+
{ assertFunctionNames: ['expect', 'expectSignals'] },
38+
],
39+
},
40+
},
3141
]

packages/angular-query-experimental/src/__tests__/inject-query.test-d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,14 @@ describe('initialData', () => {
108108
})
109109

110110
describe('structuralSharing', () => {
111-
it('should restrict to same types', () => {
111+
it('should be able to use structuralSharing with unknown types', () => {
112+
// https://github.com/TanStack/query/issues/6525#issuecomment-1938411343
112113
injectQuery(() => ({
113114
queryKey: ['key'],
114115
queryFn: () => 5,
115-
structuralSharing: (_oldData, newData) => {
116+
structuralSharing: (oldData, newData) => {
117+
expectTypeOf(oldData).toBeUnknown()
118+
expectTypeOf(newData).toBeUnknown()
116119
return newData
117120
},
118121
}))

packages/angular-query-experimental/src/__tests__/mutation-options.test-d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { mutationOptions } from '../mutation-options'
22

33
describe('mutationOptions', () => {
44
test('should not allow excess properties', () => {
5-
return mutationOptions({
6-
mutationFn: () => Promise.resolve(5),
7-
mutationKey: ['key'],
8-
// @ts-expect-error this is a good error, because onMutates does not exist!
9-
onMutates: 1000,
10-
})
5+
expectTypeOf(mutationOptions).parameter(0).not.toHaveProperty('onMutates')
116
})
127

138
test('should infer types for callbacks', () => {

packages/angular-query-experimental/src/__tests__/query-options.test-d.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ import type { Signal } from '@angular/core'
44

55
describe('queryOptions', () => {
66
test('should not allow excess properties', () => {
7-
return queryOptions({
8-
queryKey: ['key'],
9-
queryFn: () => Promise.resolve(5),
10-
// @ts-expect-error this is a good error, because stallTime does not exist!
11-
stallTime: 1000,
12-
})
7+
expectTypeOf(queryOptions).parameter(0).not.toHaveProperty('stallTime')
138
})
149

1510
test('should infer types for callbacks', () => {
16-
return queryOptions({
11+
queryOptions({
1712
queryKey: ['key'],
1813
queryFn: () => Promise.resolve(5),
1914
staleTime: 1000,
@@ -24,7 +19,7 @@ describe('queryOptions', () => {
2419
})
2520

2621
test('should allow undefined response in initialData', () => {
27-
return (id: string | null) =>
22+
const options = (id: string | null) =>
2823
queryOptions({
2924
queryKey: ['todo', id],
3025
queryFn: () =>
@@ -40,6 +35,10 @@ describe('queryOptions', () => {
4035
title: 'Initial Data',
4136
},
4237
})
38+
39+
expectTypeOf(options(null).initialData).returns.toEqualTypeOf<
40+
{ id: string; title: string } | undefined
41+
>()
4342
})
4443
})
4544

packages/eslint-plugin-query/eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default [
88
{
99
plugins: { vitest },
1010
rules: {
11+
...vitest.configs.recommended.rules,
1112
'vitest/expect-expect': [
1213
'warn',
1314
{
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]

packages/query-codemods/eslint.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

56
export default [
@@ -15,4 +16,11 @@ export default [
1516
'sort-imports': 'off',
1617
},
1718
},
19+
{
20+
plugins: { vitest },
21+
rules: {
22+
...vitest.configs.recommended.rules,
23+
'vitest/expect-expect': 'warn',
24+
},
25+
},
1826
]
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// @ts-check
22

3+
import vitest from '@vitest/eslint-plugin'
34
import rootConfig from './root.eslint.config.js'
45

5-
export default [...rootConfig]
6+
export default [
7+
...rootConfig,
8+
{
9+
plugins: { vitest },
10+
rules: {
11+
...vitest.configs.recommended.rules,
12+
'vitest/expect-expect': 'warn',
13+
},
14+
},
15+
]

0 commit comments

Comments
 (0)