Skip to content

Commit 8f16765

Browse files
authoredMay 27, 2024··
chore: move to eslint flat config (#16743)
1 parent 8e4e932 commit 8f16765

File tree

9 files changed

+341
-308
lines changed

9 files changed

+341
-308
lines changed
 

‎.eslintignore

-3
This file was deleted.

‎.eslintrc.cjs

-260
This file was deleted.

‎docs/.vitepress/buildEnd.config.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import path from 'path'
2-
import { writeFileSync } from 'fs'
1+
import path from 'node:path'
2+
import { writeFileSync } from 'node:fs'
33
import { Feed } from 'feed'
4-
import { createContentLoader, type SiteConfig } from 'vitepress'
4+
import type { SiteConfig } from 'vitepress'
5+
import { createContentLoader } from 'vitepress'
56

67
const siteUrl = 'https://vitejs.dev'
78
const blogUrl = `${siteUrl}/blog`
89

9-
export const buildEnd = async (config: SiteConfig) => {
10+
export const buildEnd = async (config: SiteConfig): Promise<void> => {
1011
const feed = new Feed({
1112
title: 'Vite',
1213
description: 'Next Generation Frontend Tooling',

‎docs/.vitepress/config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { defineConfig, DefaultTheme } from 'vitepress'
1+
import type { DefaultTheme } from 'vitepress'
2+
import { defineConfig } from 'vitepress'
23
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
34
import { buildEnd } from './buildEnd.config'
45

‎docs/.vitepress/theme/composables/sponsor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ref, onMounted, onUnmounted } from 'vue'
1+
import { onMounted, onUnmounted, ref } from 'vue'
22

33
interface Sponsors {
44
special: Sponsor[]

‎eslint.config.js

+289
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
// @ts-check
2+
import { builtinModules, createRequire } from 'node:module'
3+
import eslint from '@eslint/js'
4+
import pluginN from 'eslint-plugin-n'
5+
import * as pluginI from 'eslint-plugin-i'
6+
import pluginRegExp from 'eslint-plugin-regexp'
7+
import tsParser from '@typescript-eslint/parser'
8+
import tseslint from 'typescript-eslint'
9+
import globals from 'globals'
10+
11+
const require = createRequire(import.meta.url)
12+
const pkg = require('./package.json')
13+
const pkgVite = require('./packages/vite/package.json')
14+
15+
export default tseslint.config(
16+
{
17+
ignores: [
18+
'packages/create-vite/template-*',
19+
'**/dist/**',
20+
'**/fixtures/**',
21+
'**/playground-temp/**',
22+
'**/temp/**',
23+
'**/.vitepress/cache/**',
24+
'**/*.snap',
25+
],
26+
},
27+
eslint.configs.recommended,
28+
...tseslint.configs.recommended,
29+
...tseslint.configs.stylistic,
30+
/** @type {any} */ (pluginRegExp.configs['flat/recommended']),
31+
{
32+
name: 'main',
33+
languageOptions: {
34+
parser: tsParser,
35+
parserOptions: {
36+
sourceType: 'module',
37+
ecmaVersion: 2022,
38+
},
39+
globals: {
40+
...globals.es2021,
41+
...globals.node,
42+
},
43+
},
44+
plugins: {
45+
n: pluginN,
46+
i: pluginI,
47+
},
48+
rules: {
49+
'n/no-exports-assign': 'error',
50+
'n/no-unpublished-bin': 'error',
51+
'n/no-unsupported-features/es-builtins': 'error',
52+
'n/no-unsupported-features/node-builtins': 'error',
53+
'n/process-exit-as-throw': 'error',
54+
'n/hashbang': 'error',
55+
56+
eqeqeq: ['warn', 'always', { null: 'never' }],
57+
'no-debugger': ['error'],
58+
'no-empty': ['warn', { allowEmptyCatch: true }],
59+
'no-process-exit': 'off',
60+
'no-useless-escape': 'off',
61+
'prefer-const': [
62+
'warn',
63+
{
64+
destructuring: 'all',
65+
},
66+
],
67+
68+
'n/no-missing-require': [
69+
'error',
70+
{
71+
// for try-catching yarn pnp
72+
allowModules: ['pnpapi', 'vite'],
73+
tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'],
74+
},
75+
],
76+
'n/no-extraneous-import': [
77+
'error',
78+
{
79+
allowModules: ['vite', 'less', 'sass', 'vitest', 'unbuild'],
80+
},
81+
],
82+
'n/no-extraneous-require': [
83+
'error',
84+
{
85+
allowModules: ['vite'],
86+
},
87+
],
88+
89+
'@typescript-eslint/ban-ts-comment': 'error',
90+
'@typescript-eslint/ban-types': 'off', // TODO: we should turn this on in a new PR
91+
'@typescript-eslint/explicit-module-boundary-types': [
92+
'error',
93+
{ allowArgumentsExplicitlyTypedAsAny: true },
94+
],
95+
'@typescript-eslint/no-empty-function': [
96+
'error',
97+
{ allow: ['arrowFunctions'] },
98+
],
99+
'@typescript-eslint/no-empty-interface': 'off',
100+
'@typescript-eslint/no-explicit-any': 'off', // maybe we should turn this on in a new PR
101+
'no-extra-semi': 'off',
102+
'@typescript-eslint/no-extra-semi': 'off', // conflicts with prettier
103+
'@typescript-eslint/no-inferrable-types': 'off',
104+
'@typescript-eslint/no-unused-vars': 'off', // maybe we should turn this on in a new PR
105+
'@typescript-eslint/no-var-requires': 'off',
106+
'@typescript-eslint/consistent-type-imports': [
107+
'error',
108+
{ prefer: 'type-imports', disallowTypeAnnotations: false },
109+
],
110+
// disable rules set in @typescript-eslint/stylistic v6 that wasn't set in @typescript-eslint/recommended v5 and which conflict with current code
111+
// maybe we should turn them on in a new PR
112+
'@typescript-eslint/array-type': 'off',
113+
'@typescript-eslint/ban-tslint-comment': 'off',
114+
'@typescript-eslint/consistent-generic-constructors': 'off',
115+
'@typescript-eslint/consistent-indexed-object-style': 'off',
116+
'@typescript-eslint/consistent-type-definitions': 'off',
117+
'@typescript-eslint/prefer-for-of': 'off',
118+
'@typescript-eslint/prefer-function-type': 'off',
119+
120+
'i/no-nodejs-modules': [
121+
'error',
122+
{ allow: builtinModules.map((mod) => `node:${mod}`) },
123+
],
124+
'i/no-duplicates': 'error',
125+
'i/order': 'error',
126+
'sort-imports': [
127+
'error',
128+
{
129+
ignoreCase: false,
130+
ignoreDeclarationSort: true,
131+
ignoreMemberSort: false,
132+
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
133+
allowSeparatedGroups: false,
134+
},
135+
],
136+
137+
'regexp/no-contradiction-with-assertion': 'error',
138+
// in some cases using explicit letter-casing is more performant than the `i` flag
139+
'regexp/use-ignore-case': 'off',
140+
},
141+
},
142+
{
143+
name: 'vite/globals',
144+
files: ['packages/**/*.?([cm])[jt]s?(x)'],
145+
ignores: ['**/__tests__/**'],
146+
rules: {
147+
'no-restricted-globals': ['error', 'require', '__dirname', '__filename'],
148+
},
149+
},
150+
{
151+
name: 'vite/node',
152+
files: ['packages/vite/src/node/**/*.?([cm])[jt]s?(x)'],
153+
rules: {
154+
'no-console': ['error'],
155+
'n/no-restricted-require': [
156+
'error',
157+
Object.keys(pkgVite.devDependencies).map((d) => ({
158+
name: d,
159+
message:
160+
`devDependencies can only be imported using ESM syntax so ` +
161+
`that they are included in the rollup bundle. If you are trying to ` +
162+
`lazy load a dependency, use (await import('dependency')).default instead.`,
163+
})),
164+
],
165+
},
166+
},
167+
{
168+
name: 'playground/enforce-esm',
169+
files: ['playground/**/*.?([cm])[jt]s?(x)'],
170+
ignores: [
171+
'playground/ssr-resolve/**',
172+
'playground/**/*{commonjs,cjs}*/**',
173+
'playground/**/*{commonjs,cjs}*',
174+
'playground/**/*dep*/**',
175+
'playground/resolve/browser-module-field2/index.web.js',
176+
'playground/resolve/browser-field/**',
177+
'playground/tailwind/**', // blocked by https://github.com/postcss/postcss-load-config/issues/239
178+
],
179+
rules: {
180+
'i/no-commonjs': 'error',
181+
},
182+
},
183+
{
184+
name: 'playground/test',
185+
files: ['playground/**/__tests__/**/*.?([cm])[jt]s?(x)'],
186+
rules: {
187+
// engine field doesn't exist in playgrounds
188+
'n/no-unsupported-features/es-builtins': [
189+
'error',
190+
{
191+
version: pkg.engines.node,
192+
},
193+
],
194+
'n/no-unsupported-features/node-builtins': [
195+
'error',
196+
{
197+
version: pkg.engines.node,
198+
// ideally we would like to allow all experimental features
199+
// https://github.com/eslint-community/eslint-plugin-n/issues/199
200+
ignores: ['fetch'],
201+
},
202+
],
203+
},
204+
},
205+
206+
{
207+
name: 'disables/vite/client',
208+
files: ['packages/vite/src/client/**/*.?([cm])[jt]s?(x)'],
209+
ignores: ['**/__tests__/**'],
210+
rules: {
211+
'n/no-unsupported-features/node-builtins': 'off',
212+
},
213+
},
214+
{
215+
name: 'disables/vite/types',
216+
files: [
217+
'packages/vite/src/types/**/*.?([cm])[jt]s?(x)',
218+
'packages/vite/scripts/**/*.?([cm])[jt]s?(x)',
219+
'**/*.spec.ts',
220+
],
221+
rules: {
222+
'n/no-extraneous-import': 'off',
223+
},
224+
},
225+
{
226+
name: 'disables/create-vite/templates',
227+
files: [
228+
'packages/create-vite/template-*/**/*.?([cm])[jt]s?(x)',
229+
'**/build.config.ts',
230+
],
231+
rules: {
232+
'no-undef': 'off',
233+
'n/no-missing-import': 'off',
234+
'n/no-extraneous-import': 'off',
235+
'n/no-extraneous-require': 'off',
236+
'@typescript-eslint/explicit-module-boundary-types': 'off',
237+
},
238+
},
239+
{
240+
name: 'disables/playground',
241+
files: ['playground/**/*.?([cm])[jt]s?(x)', 'docs/**/*.?([cm])[jt]s?(x)'],
242+
rules: {
243+
'n/no-extraneous-import': 'off',
244+
'n/no-extraneous-require': 'off',
245+
'n/no-missing-import': 'off',
246+
'n/no-missing-require': 'off',
247+
'n/no-unsupported-features/es-builtins': 'off',
248+
'n/no-unsupported-features/node-builtins': 'off',
249+
'@typescript-eslint/explicit-module-boundary-types': 'off',
250+
'no-undef': 'off',
251+
'no-empty': 'off',
252+
'no-constant-condition': 'off',
253+
'@typescript-eslint/no-empty-function': 'off',
254+
},
255+
},
256+
{
257+
name: 'disables/playground/tsconfig-json',
258+
files: [
259+
'playground/tsconfig-json/**/*.?([cm])[jt]s?(x)',
260+
'playground/tsconfig-json-load-error/**/*.?([cm])[jt]s?(x)',
261+
],
262+
ignores: ['**/__tests__/**'],
263+
rules: {
264+
'@typescript-eslint/ban-ts-comment': 'off',
265+
},
266+
},
267+
{
268+
name: 'disables/js',
269+
files: ['**/*.js', '**/*.mjs', '**/*.cjs'],
270+
rules: {
271+
'@typescript-eslint/explicit-module-boundary-types': 'off',
272+
},
273+
},
274+
{
275+
name: 'disables/dts',
276+
files: ['**/*.d.ts'],
277+
rules: {
278+
'@typescript-eslint/triple-slash-reference': 'off',
279+
},
280+
},
281+
{
282+
name: 'disables/test',
283+
files: ['**/__tests__/**/*.?([cm])[jt]s?(x)'],
284+
rules: {
285+
'no-console': 'off',
286+
'@typescript-eslint/ban-ts-comment': 'off',
287+
},
288+
},
289+
)

‎package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"devDependencies": {
4343
"@babel/types": "^7.24.6",
44-
"@eslint-types/typescript-eslint": "^7.5.0",
44+
"@eslint/js": "^9.3.0",
4545
"@rollup/plugin-typescript": "^11.1.6",
4646
"@types/babel__core": "^7.20.5",
4747
"@types/babel__preset-env": "^7.9.6",
@@ -70,6 +70,7 @@
7070
"execa": "^9.1.0",
7171
"feed": "^4.2.2",
7272
"fs-extra": "^11.2.0",
73+
"globals": "^15.3.0",
7374
"lint-staged": "^15.2.5",
7475
"npm-run-all2": "^6.2.0",
7576
"picocolors": "^1.0.1",
@@ -82,6 +83,7 @@
8283
"tslib": "^2.6.2",
8384
"tsx": "^4.11.0",
8485
"typescript": "^5.2.2",
86+
"typescript-eslint": "^7.10.0",
8587
"unbuild": "^2.0.0",
8688
"vite": "workspace:*",
8789
"vitest": "^1.6.0"

‎packages/vite/types/customEvent.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface WebSocketConnectionPayload {
2323
* This might be removed in the future if we didn't find reasonable use cases.
2424
* If you find this useful, please open an issue with details so we can discuss and make it stable API.
2525
*/
26+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
2627
webSocket: WebSocket
2728
}
2829

‎pnpm-lock.yaml

+40-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.