diff --git a/eslint.config.js b/eslint.config.js index a58c45ddd47bcd..3010cf40230e40 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -6,7 +6,6 @@ import pluginRegExp from 'eslint-plugin-regexp' import tseslint from 'typescript-eslint' import { defineConfig } from 'eslint/config' import globals from 'globals' -import pkgVite from './packages/vite/package.json' with { type: 'json' } // Some rules work better with typechecking enabled, but as enabling it is slow, // we only do so when linting in IDEs for now. If you want to lint with typechecking @@ -70,15 +69,14 @@ export default defineConfig( 'n/hashbang': 'error', eqeqeq: ['warn', 'always', { null: 'never' }], - 'no-debugger': ['error'], 'no-empty': ['warn', { allowEmptyCatch: true }], - 'no-process-exit': 'off', 'prefer-const': [ 'warn', { destructuring: 'all', }, ], + 'no-restricted-globals': ['error', 'require', '__dirname', '__filename'], 'n/no-missing-require': [ 'error', @@ -88,32 +86,10 @@ export default defineConfig( tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'], }, ], - 'n/no-extraneous-import': [ - 'error', - { - allowModules: [ - 'vite', - 'esbuild', - 'rolldown', - 'less', - 'sass', - 'sass-embedded', - 'terser', - 'lightningcss', - 'vitest', - 'unbuild', - ], - }, - ], - 'n/no-extraneous-require': [ - 'error', - { - allowModules: ['vite'], - }, - ], + 'n/no-extraneous-import': 'error', + 'n/no-extraneous-require': 'error', 'n/prefer-node-protocol': 'error', - '@typescript-eslint/ban-ts-comment': 'error', '@typescript-eslint/no-unsafe-function-type': 'off', '@typescript-eslint/explicit-module-boundary-types': [ 'error', @@ -127,11 +103,8 @@ export default defineConfig( 'error', { allowInterfaces: 'with-single-extends' }, ], - '@typescript-eslint/no-empty-interface': 'off', '@typescript-eslint/no-explicit-any': 'off', - 'no-extra-semi': 'off', - '@typescript-eslint/no-extra-semi': 'off', // conflicts with prettier - '@typescript-eslint/no-inferrable-types': 'off', + '@typescript-eslint/no-inferrable-types': 'off', // incompatible with `isolatedDeclarations` '@typescript-eslint/no-unused-vars': [ 'error', { @@ -144,7 +117,6 @@ export default defineConfig( ignoreRestSiblings: true, }, ], - '@typescript-eslint/no-require-imports': 'off', '@typescript-eslint/consistent-type-imports': [ 'error', { prefer: 'type-imports', disallowTypeAnnotations: false }, @@ -190,12 +162,6 @@ export default defineConfig( ], }, ], - 'sort-imports': [ - 'error', - { - ignoreDeclarationSort: true, - }, - ], 'regexp/prefer-regexp-exec': 'error', 'regexp/prefer-regexp-test': 'error', @@ -203,34 +169,16 @@ export default defineConfig( 'regexp/use-ignore-case': 'off', }, }, - { - name: 'vite/globals', - files: ['packages/**/*.?([cm])[jt]s?(x)'], - ignores: ['**/__tests__/**'], - rules: { - 'no-restricted-globals': ['error', 'require', '__dirname', '__filename'], - }, - }, { name: 'vite/node', - files: ['packages/vite/src/node/**/*.?([cm])[jt]s?(x)'], + files: ['packages/vite/src/node/**/*.{,c,m}[jt]s{,x}'], rules: { 'no-console': ['error'], - 'n/no-restricted-require': [ - 'error', - Object.keys(pkgVite.devDependencies).map((d) => ({ - name: d, - message: - `devDependencies can only be imported using ESM syntax so ` + - `that they are included in the rolldown bundle. If you are trying to ` + - `lazy load a dependency, use (await import('dependency')).default instead.`, - })), - ], }, }, { name: 'playground/enforce-esm', - files: ['playground/**/*.?([cm])[jt]s?(x)'], + files: ['playground/**/*.{,c,m}[jt]s{,x}'], ignores: [ 'playground/ssr-resolve/**', 'playground/**/*{commonjs,cjs}*/**', @@ -245,15 +193,11 @@ export default defineConfig( }, { name: 'tests', - files: ['**/__tests__/**/*.?([cm])[jt]s?(x)'], + files: ['**/__tests__/**/*.{,c,m}[jt]s{,x}'], rules: { 'n/no-unsupported-features/node-builtins': [ 'error', - { - // ideally we would like to allow all experimental features - // https://github.com/eslint-community/eslint-plugin-n/issues/199 - ignores: ['fetch', 'import.meta.dirname'], - }, + { allowExperimental: true }, ], }, }, @@ -266,80 +210,43 @@ export default defineConfig( rules: { 'n/no-unsupported-features/node-builtins': [ 'error', - { - // ideally we would like to allow all experimental features - // https://github.com/eslint-community/eslint-plugin-n/issues/199 - ignores: ['fetch', 'import.meta.dirname'], - }, + { allowExperimental: true }, ], }, }, { name: 'disables/vite/client', - files: ['packages/vite/src/client/**/*.?([cm])[jt]s?(x)'], + files: ['packages/vite/src/client/**/*.{,c,m}[jt]s{,x}'], ignores: ['**/__tests__/**'], rules: { 'n/no-unsupported-features/node-builtins': 'off', }, }, - { - name: 'disables/vite/types', - files: [ - 'packages/vite/src/types/**/*.?([cm])[jt]s?(x)', - 'packages/vite/scripts/**/*.?([cm])[jt]s?(x)', - '**/*.spec.ts', - ], - rules: { - 'n/no-extraneous-import': 'off', - }, - }, - { - name: 'disables/vite/cjs', - files: ['packages/vite/index.cjs'], - rules: { - 'no-restricted-globals': 'off', - 'n/no-missing-require': 'off', - }, - }, - { - name: 'disables/create-vite/templates', - files: [ - 'packages/create-vite/template-*/**/*.?([cm])[jt]s?(x)', - '**/build.config.ts', - ], - rules: { - 'no-undef': 'off', - 'n/no-missing-import': 'off', - 'n/no-extraneous-import': 'off', - 'n/no-extraneous-require': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - }, - }, { name: 'disables/playground', - files: ['playground/**/*.?([cm])[jt]s?(x)', 'docs/**/*.?([cm])[jt]s?(x)'], + files: ['playground/**/*.{,c,m}[jt]s{,x}', 'docs/**/*.{,c,m}[jt]s{,x}'], rules: { 'n/no-extraneous-import': 'off', 'n/no-extraneous-require': 'off', - 'n/no-missing-import': 'off', - 'n/no-missing-require': 'off', 'n/no-unsupported-features/es-builtins': 'off', 'n/no-unsupported-features/node-builtins': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-require-imports': 'off', '@typescript-eslint/no-unused-expressions': 'off', '@typescript-eslint/no-unused-vars': 'off', 'no-undef': 'off', 'no-empty': 'off', 'no-constant-condition': 'off', + 'no-restricted-globals': 'off', '@typescript-eslint/no-empty-function': 'off', }, }, { name: 'disables/playground/tsconfig-json', files: [ - 'playground/tsconfig-json/**/*.?([cm])[jt]s?(x)', - 'playground/tsconfig-json-load-error/**/*.?([cm])[jt]s?(x)', + 'playground/tsconfig-json/**/*.{,c,m}[jt]s{,x}', + 'playground/tsconfig-json-load-error/**/*.{,c,m}[jt]s{,x}', ], ignores: ['**/__tests__/**'], rules: { @@ -357,21 +264,23 @@ export default defineConfig( name: 'disables/dts', files: ['**/*.d.ts'], rules: { + 'n/no-extraneous-import': 'off', '@typescript-eslint/consistent-indexed-object-style': 'off', '@typescript-eslint/triple-slash-reference': 'off', }, }, { name: 'disables/test', - files: ['**/__tests__/**/*.?([cm])[jt]s?(x)'], + files: ['**/__tests__/**/*.{,c,m}[jt]s{,x}'], rules: { 'no-console': 'off', '@typescript-eslint/ban-ts-comment': 'off', + 'n/no-extraneous-import': 'off', }, }, { name: 'disables/test-dts', - files: ['**/__tests_dts__/**/*.?([cm])[jt]s?(x)'], + files: ['**/__tests_dts__/**/*.{,c,m}[jt]s{,x}'], rules: { // disable typecheck-specific rules '@typescript-eslint/no-duplicate-type-constituents': 'off', diff --git a/packages/vite/src/node/__tests__/utils.spec.ts b/packages/vite/src/node/__tests__/utils.spec.ts index 8205a031c33d7f..391443906b1f0a 100644 --- a/packages/vite/src/node/__tests__/utils.spec.ts +++ b/packages/vite/src/node/__tests__/utils.spec.ts @@ -506,8 +506,10 @@ describe('isFileReadable', () => { expect(isFileReadable('/does_not_exist')).toBe(false) }) - const testFile = - require.resolve('./utils/isFileReadable/permission-test-file') + const testFile = path.resolve( + import.meta.dirname, + './utils/isFileReadable/permission-test-file', + ) test('file with normal permission', async () => { expect(isFileReadable(testFile)).toBe(true) }) diff --git a/playground/optimize-deps/dep-with-optional-peer-dep-cjs/index.js b/playground/optimize-deps/dep-with-optional-peer-dep-cjs/index.js index c79822f8099cfd..8969406169a744 100644 --- a/playground/optimize-deps/dep-with-optional-peer-dep-cjs/index.js +++ b/playground/optimize-deps/dep-with-optional-peer-dep-cjs/index.js @@ -4,6 +4,7 @@ exports.callItself = function () { exports.callPeerDep = function () { try { + // eslint-disable-next-line n/no-missing-require return require('foobar') } catch { return 'fallback'