Skip to content

Commit 194b153

Browse files
committed
style: update to ESLint v9 and rework lint config
1 parent f1fb8dd commit 194b153

22 files changed

+182
-145
lines changed

.eslintignore

-6
This file was deleted.

.eslintrc.cjs

-45
This file was deleted.

.github/dependabot.yml

-9
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ updates:
2323
development:
2424
dependency-type: 'development'
2525

26-
# TODO(mcous, 2024-04-30): update to ESLint v9 + flat config
27-
ignore:
28-
- dependency-name: 'eslint'
29-
versions: ['>=9']
30-
- dependency-name: 'eslint-plugin-n'
31-
versions: ['>=17']
32-
- dependency-name: 'eslint-plugin-promise'
33-
versions: ['>=7']
34-
3526
# Update GitHub Actions dependencies
3627
- package-ecosystem: 'github-actions'
3728
directory: '/'

.prettierignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
scripts/*
2-
.eslintignore
3-
.prettierignore
41
.all-contributorsrc

.prettierrc.yaml

-9
This file was deleted.

eslint.config.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import js from '@eslint/js'
2+
import eslintPluginVitest from '@vitest/eslint-plugin'
3+
import eslintConfigPrettier from 'eslint-config-prettier'
4+
import eslintPluginJestDom from 'eslint-plugin-jest-dom'
5+
import eslintPluginPromise from 'eslint-plugin-promise'
6+
import eslintPluginSimpleImportSort from 'eslint-plugin-simple-import-sort'
7+
import eslintPluginSvelte from 'eslint-plugin-svelte'
8+
import eslintPluginTestingLibrary from 'eslint-plugin-testing-library'
9+
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
10+
import globals from 'globals'
11+
import tseslint from 'typescript-eslint'
12+
13+
export default tseslint.config(
14+
js.configs.recommended,
15+
tseslint.configs.strict,
16+
tseslint.configs.stylistic,
17+
eslintPluginUnicorn.configs['flat/recommended'],
18+
eslintPluginPromise.configs['flat/recommended'],
19+
eslintPluginSvelte.configs['flat/recommended'],
20+
eslintPluginSvelte.configs['flat/prettier'],
21+
eslintConfigPrettier,
22+
{
23+
name: 'settings',
24+
languageOptions: {
25+
ecmaVersion: 'latest',
26+
sourceType: 'module',
27+
parserOptions: {
28+
parser: tseslint.parser,
29+
extraFileExtensions: ['.svelte'],
30+
},
31+
globals: {
32+
...globals.browser,
33+
...globals.node,
34+
...globals.jest,
35+
},
36+
},
37+
},
38+
{
39+
name: 'ignores',
40+
ignores: ['coverage', 'types'],
41+
},
42+
{
43+
name: 'simple-import-sort',
44+
plugins: {
45+
'simple-import-sort': eslintPluginSimpleImportSort,
46+
},
47+
rules: {
48+
'simple-import-sort/imports': 'error',
49+
'simple-import-sort/exports': 'error',
50+
},
51+
},
52+
{
53+
name: 'tests',
54+
files: ['**/*.test.js'],
55+
extends: [
56+
eslintPluginVitest.configs.recommended,
57+
eslintPluginJestDom.configs['flat/recommended'],
58+
eslintPluginTestingLibrary.configs['flat/dom'],
59+
],
60+
rules: {
61+
'testing-library/no-node-access': [
62+
'error',
63+
{ allowContainerFirstChild: true },
64+
],
65+
},
66+
},
67+
{
68+
name: 'extras',
69+
rules: {
70+
'unicorn/prevent-abbreviations': 'off',
71+
},
72+
},
73+
{
74+
name: 'svelte-extras',
75+
files: ['**/*.svelte'],
76+
rules: {
77+
'svelte/no-unused-svelte-ignore': 'off',
78+
'unicorn/filename-case': ['error', { case: 'pascalCase' }],
79+
'unicorn/no-useless-undefined': 'off',
80+
},
81+
},
82+
{
83+
name: 'ts-extras',
84+
files: ['**/*.ts'],
85+
extends: [
86+
tseslint.configs.strictTypeChecked,
87+
tseslint.configs.stylisticTypeChecked,
88+
],
89+
languageOptions: {
90+
parserOptions: {
91+
projectService: true,
92+
},
93+
},
94+
}
95+
)

jest.config.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
22

33
const SVELTE_TRANSFORM_PATTERN =
4-
SVELTE_VERSION >= '5' ? '^.+\\.svelte(?:\\.js)?$' : '^.+\\.svelte$'
4+
SVELTE_VERSION >= '5'
5+
? String.raw`^.+\.svelte(?:\.js)?$`
6+
: String.raw`^.+\.svelte$`
57

68
export default {
79
testMatch: ['<rootDir>/tests/**/*.test.js'],
@@ -15,7 +17,7 @@ export default {
1517
injectGlobals: false,
1618
moduleNameMapper: {
1719
'^vitest$': '<rootDir>/tests/_jest-vitest-alias.js',
18-
'^@testing-library\\/svelte$': '<rootDir>/src/index.js',
20+
[String.raw`^@testing-library\/svelte$`]: '<rootDir>/src/index.js',
1921
},
2022
resetMocks: true,
2123
restoreMocks: true,

package.json

+11-9
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,25 @@
9090
"@testing-library/dom": "9.x.x || 10.x.x"
9191
},
9292
"devDependencies": {
93+
"@eslint/js": "^9.26.0",
9394
"@jest/globals": "^29.7.0",
9495
"@sveltejs/vite-plugin-svelte": "^5.0.3",
9596
"@testing-library/jest-dom": "^6.6.3",
9697
"@testing-library/user-event": "^14.6.1",
97-
"@typescript-eslint/eslint-plugin": "^8.0.0",
98-
"@typescript-eslint/parser": "^8.0.0",
9998
"@vitest/coverage-v8": "^3.1.3",
99+
"@vitest/eslint-plugin": "^1.1.44",
100100
"all-contributors-cli": "^6.26.1",
101101
"doctoc": "^2.2.1",
102-
"eslint": "^8.57.0",
103-
"eslint-config-prettier": "^9.1.0",
104-
"eslint-config-standard": "^17.1.0",
105-
"eslint-plugin-import": "^2.29.1",
106-
"eslint-plugin-n": "^16.6.2",
107-
"eslint-plugin-promise": "^6.4.0",
102+
"eslint": "^9.26.0",
103+
"eslint-config-prettier": "^10.1.5",
104+
"eslint-plugin-jest-dom": "^5.5.0",
105+
"eslint-plugin-promise": "^7.2.1",
108106
"eslint-plugin-simple-import-sort": "^12.1.1",
109-
"eslint-plugin-svelte": "^2.42.0",
107+
"eslint-plugin-svelte": "^3.5.1",
108+
"eslint-plugin-testing-library": "^7.1.1",
109+
"eslint-plugin-unicorn": "^59.0.1",
110110
"expect-type": "^1.2.1",
111+
"globals": "^16.1.0",
111112
"happy-dom": "^17.4.6",
112113
"jest": "^29.7.0",
113114
"jest-environment-jsdom": "^29.7.0",
@@ -119,6 +120,7 @@
119120
"svelte-check": "^4.1.7",
120121
"svelte-jester": "^5.0.0",
121122
"typescript": "^5.8.3",
123+
"typescript-eslint": "^8.32.0",
122124
"typescript-svelte-plugin": "^0.3.46",
123125
"vite": "^6.3.5",
124126
"vitest": "^3.1.3"

prettier.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default {
2+
semi: false,
3+
singleQuote: true,
4+
trailingComma: 'es5',
5+
plugins: ['prettier-plugin-svelte'],
6+
overrides: [
7+
{
8+
files: '*.svelte',
9+
options: {
10+
parser: 'svelte',
11+
},
12+
},
13+
],
14+
}

src/core/index.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,13 @@
77
*/
88
import * as LegacyCore from './legacy.js'
99
import * as ModernCore from './modern.svelte.js'
10-
import {
11-
createValidateOptions,
12-
UnknownSvelteOptionsError,
13-
} from './validate-options.js'
10+
import { createValidateOptions } from './validate-options.js'
1411

1512
const { mount, unmount, updateProps, allowedOptions } =
1613
ModernCore.IS_MODERN_SVELTE ? ModernCore : LegacyCore
1714

1815
/** Validate component options. */
1916
const validateOptions = createValidateOptions(allowedOptions)
2017

21-
export {
22-
mount,
23-
UnknownSvelteOptionsError,
24-
unmount,
25-
updateProps,
26-
validateOptions,
27-
}
18+
export { mount, unmount, updateProps, validateOptions }
19+
export { UnknownSvelteOptionsError } from './validate-options.js'

src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable import/export */
21
import { act, cleanup } from './pure.js'
32

43
// If we're running in a test runner that supports afterEach

src/pure.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const render = (Component, options = {}, renderOptions = {}) => {
6565
const queries = getQueriesForElement(baseElement, renderOptions.queries)
6666

6767
const target =
68+
// eslint-disable-next-line unicorn/prefer-dom-node-append
6869
options.target ?? baseElement.appendChild(document.createElement('div'))
6970

7071
targetCache.add(target)
@@ -116,14 +117,18 @@ const cleanupTarget = (target) => {
116117
const inCache = targetCache.delete(target)
117118

118119
if (inCache && target.parentNode === document.body) {
119-
document.body.removeChild(target)
120+
target.remove()
120121
}
121122
}
122123

123124
/** Unmount all components and remove elements added to `<body>`. */
124125
const cleanup = () => {
125-
componentCache.forEach(cleanupComponent)
126-
targetCache.forEach(cleanupTarget)
126+
for (const component of componentCache) {
127+
cleanupComponent(component)
128+
}
129+
for (const target of targetCache) {
130+
cleanupTarget(target)
131+
}
127132
}
128133

129134
/**
@@ -163,12 +168,12 @@ const fireEvent = async (...args) => {
163168
return event
164169
}
165170

166-
Object.keys(baseFireEvent).forEach((key) => {
171+
for (const [key, baseEvent] of Object.entries(baseFireEvent)) {
167172
fireEvent[key] = async (...args) => {
168-
const event = baseFireEvent[key](...args)
173+
const event = baseEvent(...args)
169174
await tick()
170175
return event
171176
}
172-
})
177+
}
173178

174179
export { act, cleanup, fireEvent, render }

src/vite.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { dirname, join } from 'node:path'
2-
import { fileURLToPath } from 'node:url'
1+
import path from 'node:path'
2+
import url from 'node:url'
33

44
/**
55
* Vite plugin to configure @testing-library/svelte.
@@ -50,8 +50,8 @@ const addBrowserCondition = (config) => {
5050
const browserConditionIndex = conditions.indexOf('browser')
5151

5252
if (
53-
nodeConditionIndex >= 0 &&
54-
(nodeConditionIndex < browserConditionIndex || browserConditionIndex < 0)
53+
nodeConditionIndex !== -1 &&
54+
(nodeConditionIndex < browserConditionIndex || browserConditionIndex === -1)
5555
) {
5656
conditions.splice(nodeConditionIndex, 0, 'browser')
5757
}
@@ -77,7 +77,9 @@ const addAutoCleanup = (config) => {
7777
setupFiles = [setupFiles]
7878
}
7979

80-
setupFiles.push(join(dirname(fileURLToPath(import.meta.url)), './vitest.js'))
80+
setupFiles.push(
81+
path.join(path.dirname(url.fileURLToPath(import.meta.url)), './vitest.js')
82+
)
8183

8284
test.setupFiles = setupFiles
8385
config.test = test

tests/_env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
22

3-
export const IS_JSDOM = window.navigator.userAgent.includes('jsdom')
3+
export const IS_JSDOM = globalThis.navigator.userAgent.includes('jsdom')
44

55
export const IS_HAPPYDOM = !IS_JSDOM // right now it's happy or js
66

0 commit comments

Comments
 (0)