Skip to content

Commit ea494af

Browse files
authored
chore: update to ESLint 9 (#10705)
1 parent 46c2b63 commit ea494af

File tree

9 files changed

+363
-484
lines changed

9 files changed

+363
-484
lines changed

.eslintignore

-4
This file was deleted.

.eslintrc.cjs

-140
This file was deleted.

.github/renovate.json5

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{
3535
groupName: 'lint',
3636
matchPackageNames: ['simple-git-hooks', 'lint-staged'],
37-
matchPackagePrefixes: ['@typescript-eslint', 'eslint', 'prettier'],
37+
matchPackagePrefixes: ['typescript-eslint', 'eslint', 'prettier'],
3838
},
3939
],
4040
ignoreDeps: [

eslint.config.js

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
import importX from 'eslint-plugin-import-x'
2+
import tseslint from 'typescript-eslint'
3+
import vitest from 'eslint-plugin-vitest'
4+
import { builtinModules } from 'node:module'
5+
6+
const DOMGlobals = ['window', 'document']
7+
const NodeGlobals = ['module', 'require']
8+
9+
const banConstEnum = {
10+
selector: 'TSEnumDeclaration[const=true]',
11+
message:
12+
'Please use non-const enums. This project automatically inlines enums.',
13+
}
14+
15+
export default tseslint.config(
16+
{
17+
files: ['**/*.js', '**/*.ts', '**/*.tsx'],
18+
extends: [tseslint.configs.base],
19+
plugins: {
20+
'import-x': importX,
21+
},
22+
rules: {
23+
'no-debugger': 'error',
24+
'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
25+
// most of the codebase are expected to be env agnostic
26+
'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals],
27+
28+
'no-restricted-syntax': [
29+
'error',
30+
banConstEnum,
31+
{
32+
selector: 'ObjectPattern > RestElement',
33+
message:
34+
'Our output target is ES2016, and object rest spread results in ' +
35+
'verbose helpers and should be avoided.',
36+
},
37+
{
38+
selector: 'ObjectExpression > SpreadElement',
39+
message:
40+
'esbuild transpiles object spread into very verbose inline helpers.\n' +
41+
'Please use the `extend` helper from @vue/shared instead.',
42+
},
43+
{
44+
selector: 'AwaitExpression',
45+
message:
46+
'Our output target is ES2016, so async/await syntax should be avoided.',
47+
},
48+
],
49+
'sort-imports': ['error', { ignoreDeclarationSort: true }],
50+
51+
'import-x/no-nodejs-modules': [
52+
'error',
53+
{ allow: builtinModules.map(mod => `node:${mod}`) },
54+
],
55+
// This rule enforces the preference for using '@ts-expect-error' comments in TypeScript
56+
// code to indicate intentional type errors, improving code clarity and maintainability.
57+
'@typescript-eslint/prefer-ts-expect-error': 'error',
58+
// Enforce the use of 'import type' for importing types
59+
'@typescript-eslint/consistent-type-imports': [
60+
'error',
61+
{
62+
fixStyle: 'inline-type-imports',
63+
disallowTypeAnnotations: false,
64+
},
65+
],
66+
// Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers
67+
'@typescript-eslint/no-import-type-side-effects': 'error',
68+
},
69+
},
70+
71+
// tests, no restrictions (runs in Node / Vitest with jsdom)
72+
{
73+
files: ['**/__tests__/**', 'packages/dts-test/**'],
74+
plugins: { vitest },
75+
languageOptions: {
76+
globals: {
77+
...vitest.environments.env.globals,
78+
},
79+
},
80+
rules: {
81+
'no-console': 'off',
82+
'no-restricted-globals': 'off',
83+
'no-restricted-syntax': 'off',
84+
'vitest/no-disabled-tests': 'error',
85+
'vitest/no-focused-tests': 'error',
86+
},
87+
},
88+
89+
// shared, may be used in any env
90+
{
91+
files: ['packages/shared/**', 'eslint.config.js'],
92+
rules: {
93+
'no-restricted-globals': 'off',
94+
},
95+
},
96+
97+
// Packages targeting DOM
98+
{
99+
files: ['packages/{vue,vue-compat,runtime-dom}/**'],
100+
rules: {
101+
'no-restricted-globals': ['error', ...NodeGlobals],
102+
},
103+
},
104+
105+
// Packages targeting Node
106+
{
107+
files: ['packages/{compiler-sfc,compiler-ssr,server-renderer}/**'],
108+
rules: {
109+
'no-restricted-globals': ['error', ...DOMGlobals],
110+
'no-restricted-syntax': ['error', banConstEnum],
111+
},
112+
},
113+
114+
// Private package, browser only + no syntax restrictions
115+
{
116+
files: ['packages/template-explorer/**', 'packages/sfc-playground/**'],
117+
rules: {
118+
'no-restricted-globals': ['error', ...NodeGlobals],
119+
'no-restricted-syntax': ['error', banConstEnum],
120+
'no-console': 'off',
121+
},
122+
},
123+
124+
// JavaScript files
125+
{
126+
files: ['*.js'],
127+
rules: {
128+
// We only do `no-unused-vars` checks for js files, TS files are checked by TypeScript itself.
129+
'no-unused-vars': ['error', { vars: 'all', args: 'none' }],
130+
},
131+
},
132+
133+
// Node scripts
134+
{
135+
files: [
136+
'eslint.config.js',
137+
'rollup.config.js',
138+
'scripts/**',
139+
'./*.{js,ts}',
140+
'packages/*/*.js',
141+
'packages/vue/*/*.js',
142+
],
143+
rules: {
144+
'no-restricted-globals': 'off',
145+
'no-restricted-syntax': ['error', banConstEnum],
146+
'no-console': 'off',
147+
},
148+
},
149+
150+
// Import nodejs modules in compiler-sfc
151+
{
152+
files: ['packages/compiler-sfc/src/**'],
153+
rules: {
154+
'import-x/no-nodejs-modules': ['error', { allow: builtinModules }],
155+
},
156+
},
157+
158+
{
159+
ignores: [
160+
'**/dist/',
161+
'**/temp/',
162+
'**/coverage/',
163+
'.idea/',
164+
'explorations/',
165+
'dts-build/packages',
166+
],
167+
},
168+
)

package.json

+16-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"size-esm-runtime": "node scripts/build.js vue -f esm-bundler-runtime",
1414
"size-esm": "node scripts/build.js runtime-dom runtime-core reactivity shared -f esm-bundler",
1515
"check": "tsc --incremental --noEmit",
16-
"lint": "eslint --cache --ext .js,.ts,.tsx . --ignore-path .gitignore",
16+
"lint": "eslint --cache .",
1717
"format": "prettier --write --cache .",
1818
"format-check": "prettier --check --cache .",
1919
"test": "vitest",
@@ -72,18 +72,15 @@
7272
"@types/minimist": "^1.2.5",
7373
"@types/node": "^20.12.5",
7474
"@types/semver": "^7.5.8",
75-
"@typescript-eslint/eslint-plugin": "^7.4.0",
76-
"@typescript-eslint/parser": "^7.4.0",
7775
"@vitest/coverage-istanbul": "^1.4.0",
7876
"@vue/consolidate": "1.0.0",
7977
"conventional-changelog-cli": "^4.1.0",
8078
"enquirer": "^2.4.1",
8179
"esbuild": "^0.20.2",
8280
"esbuild-plugin-polyfill-node": "^0.3.0",
83-
"eslint": "^8.57.0",
84-
"eslint-define-config": "^2.1.0",
85-
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
86-
"eslint-plugin-jest": "^27.9.0",
81+
"eslint": "^9.0.0",
82+
"eslint-plugin-import-x": "^0.5.0",
83+
"eslint-plugin-vitest": "^0.5.3",
8784
"estree-walker": "^2.0.2",
8885
"execa": "^8.0.1",
8986
"jsdom": "^24.0.0",
@@ -112,7 +109,19 @@
112109
"tslib": "^2.6.2",
113110
"tsx": "^4.7.2",
114111
"typescript": "~5.4.5",
112+
"typescript-eslint": "^7.6.0",
115113
"vite": "^5.2.7",
116114
"vitest": "^1.4.0"
115+
},
116+
"pnpm": {
117+
"peerDependencyRules": {
118+
"allowedVersions": {
119+
"typescript-eslint>eslint": "^9.0.0",
120+
"@typescript-eslint/eslint-plugin>eslint": "^9.0.0",
121+
"@typescript-eslint/parser>eslint": "^9.0.0",
122+
"@typescript-eslint/type-utils>eslint": "^9.0.0",
123+
"@typescript-eslint/utils>eslint": "^9.0.0"
124+
}
125+
}
117126
}
118127
}

packages/compiler-core/__tests__/parse.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import {
1616
import { baseParse } from '../src/parser'
1717
import type { Program } from '@babel/types'
1818

19-
/* eslint jest/no-disabled-tests: "off" */
20-
2119
describe('compiler: parse', () => {
2220
describe('Text', () => {
2321
test('simple text', () => {

packages/runtime-core/src/components/Suspense.ts

-1
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,6 @@ function hydrateSuspense(
814814
suspense.resolve(false, true)
815815
}
816816
return result
817-
/* eslint-enable no-restricted-globals */
818817
}
819818

820819
function normalizeSuspenseChildren(vnode: VNode) {

0 commit comments

Comments
 (0)