chore: add @vitest/eslint-plugin (#630)

This commit is contained in:
Marco Pasqualetti
2025-03-08 21:11:28 +01:00
committed by GitHub
parent 81e7af6f5e
commit da194524ee
9 changed files with 69 additions and 11 deletions
+30 -2
View File
@@ -5,9 +5,19 @@ import eslintPluginImport from 'eslint-plugin-import'
import eslintPluginReact from 'eslint-plugin-react'
// @ts-expect-error no types are available for this plugin
import eslintPluginReactHooks from 'eslint-plugin-react-hooks'
import eslintPluginVitest from '@vitest/eslint-plugin'
const REACT_FILES_MATCH =
'packages/{tuono,tuono-router}/**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'
const JS_EXTENSIONS_MATCH = [
'js',
'mjs',
'cjs',
'jsx',
'mjsx',
'ts',
'tsx',
'mtsx',
].join(',')
const REACT_FILES_MATCH = `packages/{tuono,tuono-router}/**/*.{${JS_EXTENSIONS_MATCH}}`
/** @type import('typescript-eslint').ConfigArray */
const tuonoEslintConfig = tseslint.config(
@@ -172,6 +182,24 @@ const tuonoEslintConfig = tseslint.config(
// #endregion misc
},
},
{
files: [`packages/**/*.spec.{${JS_EXTENSIONS_MATCH}}`],
plugins: { vitest: eslintPluginVitest },
rules: {
...eslintPluginVitest.configs.recommended.rules,
'vitest/consistent-test-filename': [
'error',
{
pattern: '.*\\.spec\\.[tj]sx?$',
allTestPattern: '.*\\.(test|spec)\\.[tj]sx?$',
},
],
'vitest/consistent-test-it': 'error',
'vitest/max-expects': 'error',
'vitest/max-nested-describe': ['error', { max: 3 }],
},
},
)
export default tuonoEslintConfig
+1
View File
@@ -28,6 +28,7 @@
"@eslint/js": "9.20.0",
"@playwright/test": "1.50.1",
"@types/node": "22.13.9",
"@vitest/eslint-plugin": "1.1.36",
"eslint": "9.20.0",
"eslint-import-resolver-typescript": "3.7.0",
"eslint-plugin-import": "2.31.0",
@@ -63,7 +63,7 @@ const routes = [
]
describe('buildRouteConfig works', () => {
it('Should build the correct config', () => {
it('should build the correct config', () => {
const config = buildRouteConfig(routes)
expect(config).toStrictEqual(
'PostsMyPostRoute,PostsIndexRoute,PostspostIndexRoute',
@@ -72,13 +72,15 @@ const dynamicRoute = {
}
describe('hasParentRoute works', () => {
it('Should detect parent route', () => {
it('should detect parent route', () => {
const parentRoute = hasParentRoute(routes, myPost, myPost.path)
expect(parentRoute).toStrictEqual(parent)
})
it('Should detect parent route for dynamic routes', () => {
it('should detect parent route for dynamic routes', () => {
const parentRoute = hasParentRoute(routes, dynamicRoute, dynamicRoute.path)
expect(parentRoute).toStrictEqual(parent)
})
})
@@ -108,8 +108,9 @@ const expectedSorting = [
]
describe('sortRouteNodes works', () => {
it('Should correctly sort the nodes', () => {
it('should correctly sort the nodes', () => {
const sorted = sortRouteNodes(routes)
expect(sorted).toStrictEqual(expectedSorting)
})
})
@@ -33,7 +33,7 @@ vi.mock('react-intersection-observer', () => ({
},
}))
describe('Link Component', () => {
describe('Link component', () => {
beforeEach(() => {
pushMock.mockReset()
preloadMock.mockReset()
@@ -1,5 +1,5 @@
import type { JSX } from 'react'
import { afterEach, describe, expect, test, vi } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { cleanup, render, screen } from '@testing-library/react'
@@ -51,7 +51,7 @@ vi.mock('../hooks/useServerPayloadData.ts', () => ({
describe('Test RouteMatch component', () => {
afterEach(cleanup)
test('It should correctly render nested routes', () => {
it('should correctly render nested routes', () => {
render(<RouteMatch route={route} serverInitialData={{}} />)
expect(screen.getByTestId('root')).toMatchInlineSnapshot(
@@ -1,4 +1,4 @@
import { afterEach, describe, expect, test, vi } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { cleanup } from '@testing-library/react'
import { useRoute } from './useRoute'
@@ -21,7 +21,7 @@ describe('useRoute', () => {
useRouterContextMock.mockReset()
})
test('match routes by ids', () => {
it('should match routes by ids', () => {
useRouterContextMock.mockReturnValue({
router: {
routesById: {
@@ -36,6 +36,7 @@ describe('useRoute', () => {
},
})
/* eslint-disable vitest/max-expects */
expect(useRoute('/')?.id).toBe('/')
expect(useRoute('/not-found')?.id).toBe(undefined)
expect(useRoute('/about')?.id).toBe('/about')
@@ -50,5 +51,6 @@ describe('useRoute', () => {
expect(useRoute('/blog/catch_all/catch_all')?.id).toBe(
'/blog/[...catch_all]',
)
/* eslint-enable vitest/max-expects */
})
})
+24
View File
@@ -17,6 +17,9 @@ importers:
'@types/node':
specifier: 22.13.9
version: 22.13.9
'@vitest/eslint-plugin':
specifier: 1.1.36
version: 1.1.36(@typescript-eslint/utils@8.24.0(eslint@9.20.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.20.0(jiti@2.4.2))(typescript@5.7.3)(vitest@3.0.7(@types/debug@4.1.12)(@types/node@22.13.9)(happy-dom@17.2.2)(jiti@2.4.2)(lightningcss@1.29.1)(sugarss@4.0.1(postcss@8.5.3)))
eslint:
specifier: 9.20.0
version: 9.20.0(jiti@2.4.2)
@@ -1143,6 +1146,19 @@ packages:
peerDependencies:
vite: ^4 || ^5 || ^6
'@vitest/eslint-plugin@1.1.36':
resolution: {integrity: sha512-IjBV/fcL9NJRxGw221ieaDsqKqj8qUo7rvSupDxMjTXyhsCusHC6M+jFUNqBp4PCkYFcf5bjrKxeZoCEWoPxig==}
peerDependencies:
'@typescript-eslint/utils': ^8.24.0
eslint: '>= 8.57.0'
typescript: '>= 5.0.0'
vitest: '*'
peerDependenciesMeta:
typescript:
optional: true
vitest:
optional: true
'@vitest/expect@3.0.7':
resolution: {integrity: sha512-QP25f+YJhzPfHrHfYHtvRn+uvkCFCqFtW9CktfBxmB+25QqWsx7VB2As6f4GmwllHLDhXNHvqedwhvMmSnNmjw==}
@@ -3594,6 +3610,14 @@ snapshots:
transitivePeerDependencies:
- '@swc/helpers'
'@vitest/eslint-plugin@1.1.36(@typescript-eslint/utils@8.24.0(eslint@9.20.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.20.0(jiti@2.4.2))(typescript@5.7.3)(vitest@3.0.7(@types/debug@4.1.12)(@types/node@22.13.9)(happy-dom@17.2.2)(jiti@2.4.2)(lightningcss@1.29.1)(sugarss@4.0.1(postcss@8.5.3)))':
dependencies:
'@typescript-eslint/utils': 8.24.0(eslint@9.20.0(jiti@2.4.2))(typescript@5.7.3)
eslint: 9.20.0(jiti@2.4.2)
optionalDependencies:
typescript: 5.7.3
vitest: 3.0.7(@types/debug@4.1.12)(@types/node@22.13.9)(happy-dom@17.2.2)(jiti@2.4.2)(lightningcss@1.29.1)(sugarss@4.0.1(postcss@8.5.3))
'@vitest/expect@3.0.7':
dependencies:
'@vitest/spy': 3.0.7