Skip to content

ci(*): init ESLint configurations to include 'vitest/expect-expect' rule as error across multiple packages gradually #9104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
5 changes: 1 addition & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export default [
{
files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
Comment on lines -48 to -51
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initiate eslint vitest/expect-expect as error for all package

rules: vitest.configs.recommended.rules,
settings: { vitest: { typecheck: true } },
},
]
10 changes: 10 additions & 0 deletions packages/angular-query-experimental/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check

import pluginJsdoc from 'eslint-plugin-jsdoc'
import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [
Expand Down Expand Up @@ -28,4 +29,13 @@ export default [
],
},
},
{
plugins: { vitest },
rules: {
'vitest/expect-expect': [
'error',
{ assertFunctionNames: ['expect', 'expectSignals'] },
],
},
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ describe('initialData', () => {
})

describe('structuralSharing', () => {
it('should restrict to same types', () => {
it('should be able to use structuralSharing with unknown types', () => {
// https://github.com/TanStack/query/issues/6525#issuecomment-1938411343
injectQuery(() => ({
queryKey: ['key'],
queryFn: () => 5,
structuralSharing: (_oldData, newData) => {
structuralSharing: (oldData, newData) => {
expectTypeOf(oldData).toBeUnknown()
expectTypeOf(newData).toBeUnknown()
return newData
},
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { mutationOptions } from '../mutation-options'

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

test('should infer types for callbacks', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ import type { Signal } from '@angular/core'

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

test('should infer types for callbacks', () => {
return queryOptions({
queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
staleTime: 1000,
Expand All @@ -24,7 +19,7 @@ describe('queryOptions', () => {
})

test('should allow undefined response in initialData', () => {
return (id: string | null) =>
const options = (id: string | null) =>
queryOptions({
queryKey: ['todo', id],
queryFn: () =>
Expand All @@ -40,6 +35,10 @@ describe('queryOptions', () => {
title: 'Initial Data',
},
})

expectTypeOf(options(null).initialData).returns.toEqualTypeOf<
{ id: string; title: string } | undefined
>()
})
})

Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-query/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default [
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': [
'warn',
{
Expand Down
12 changes: 11 additions & 1 deletion packages/query-async-storage-persister/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [...rootConfig]
export default [
...rootConfig,
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
12 changes: 11 additions & 1 deletion packages/query-broadcast-client-experimental/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [...rootConfig]
export default [
...rootConfig,
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
8 changes: 8 additions & 0 deletions packages/query-codemods/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [
Expand All @@ -15,4 +16,11 @@ export default [
'sort-imports': 'off',
},
},
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
12 changes: 11 additions & 1 deletion packages/query-core/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [...rootConfig]
export default [
...rootConfig,
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
2 changes: 1 addition & 1 deletion packages/query-core/src/__tests__/query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ describe('query', () => {
const key = queryKey()

const queryFn = vi
.fn()
.fn<() => Promise<string>>()
.mockImplementation(() => sleep(10).then(() => 'data'))

queryClient.prefetchQuery({
Expand Down
12 changes: 11 additions & 1 deletion packages/query-persist-client-core/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [...rootConfig]
export default [
...rootConfig,
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
12 changes: 11 additions & 1 deletion packages/query-sync-storage-persister/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [...rootConfig]
export default [
...rootConfig,
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
8 changes: 8 additions & 0 deletions packages/react-query-devtools/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import pluginReact from '@eslint-react/eslint-plugin'
import pluginReactHooks from 'eslint-plugin-react-hooks'
import rootConfig from './root.eslint.config.js'
Expand All @@ -19,4 +20,11 @@ export default [
'react-hooks/rules-of-hooks': 'error',
},
},
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
8 changes: 8 additions & 0 deletions packages/react-query-next-experimental/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import pluginReact from '@eslint-react/eslint-plugin'
import pluginReactHooks from 'eslint-plugin-react-hooks'
import rootConfig from './root.eslint.config.js'
Expand All @@ -20,4 +21,11 @@ export default [
'react-hooks/rules-of-hooks': 'error',
},
},
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
8 changes: 8 additions & 0 deletions packages/react-query-persist-client/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import pluginReact from '@eslint-react/eslint-plugin'
import pluginReactHooks from 'eslint-plugin-react-hooks'
import rootConfig from './root.eslint.config.js'
Expand All @@ -19,4 +20,11 @@ export default [
'react-hooks/rules-of-hooks': 'error',
},
},
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
8 changes: 8 additions & 0 deletions packages/react-query/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import pluginReact from '@eslint-react/eslint-plugin'
// @ts-expect-error
import pluginReactCompiler from 'eslint-plugin-react-compiler'
Expand Down Expand Up @@ -31,4 +32,11 @@ export default [
'react-compiler/react-compiler': 'off',
},
},
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
7 changes: 5 additions & 2 deletions packages/react-query/src/__tests__/useQuery.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,14 @@ describe('useQuery', () => {
})

describe('structuralSharing', () => {
it('should restrict to same types', () => {
it('should be able to use structuralSharing with unknown types', () => {
// https://github.com/TanStack/query/issues/6525#issuecomment-1938411343
useQuery({
queryKey: ['key'],
queryFn: () => 5,
structuralSharing: (_oldData, newData) => {
structuralSharing: (oldData, newData) => {
expectTypeOf(oldData).toBeUnknown()
expectTypeOf(newData).toBeUnknown()
return newData
},
})
Expand Down
12 changes: 11 additions & 1 deletion packages/solid-query-devtools/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [...rootConfig]
export default [
...rootConfig,
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
12 changes: 11 additions & 1 deletion packages/solid-query-persist-client/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [...rootConfig]
export default [
...rootConfig,
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
12 changes: 11 additions & 1 deletion packages/solid-query/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [...rootConfig]
export default [
...rootConfig,
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
8 changes: 8 additions & 0 deletions packages/svelte-query-devtools/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import pluginSvelte from 'eslint-plugin-svelte'
import rootConfig from './root.eslint.config.js'

Expand All @@ -13,4 +14,11 @@ export default [
'svelte/valid-compile': 'off',
},
},
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
},
]
Loading
Loading