diff --git a/eslint.config.js b/eslint.config.js index 25fd11301cb0ac..50da4a14811a90 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,5 +1,4 @@ // @ts-check -import { createRequire } from 'node:module' import eslint from '@eslint/js' import pluginN from 'eslint-plugin-n' import pluginImportX from 'eslint-plugin-import-x' @@ -7,9 +6,7 @@ import pluginRegExp from 'eslint-plugin-regexp' import tseslint from 'typescript-eslint' import { defineConfig } from 'eslint/config' import globals from 'globals' - -const require = createRequire(import.meta.url) -const pkgVite = require('./packages/vite/package.json') +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 @@ -31,6 +28,8 @@ export default defineConfig( eslint.configs.recommended, ...tseslint.configs.recommended, ...tseslint.configs.stylistic, + ...(shouldTypeCheck ? tseslint.configs.recommendedTypeCheckedOnly : []), + ...(shouldTypeCheck ? tseslint.configs.stylisticTypeCheckedOnly : []), pluginRegExp.configs['flat/recommended'], { name: 'main', @@ -40,12 +39,7 @@ export default defineConfig( sourceType: 'module', ecmaVersion: 2022, isolatedDeclarations: true, - project: shouldTypeCheck - ? [ - './packages/*/tsconfig.json', - './packages/vite/src/*/tsconfig.json', - ] - : undefined, + projectService: shouldTypeCheck, }, globals: { ...globals.es2023, @@ -161,6 +155,33 @@ export default defineConfig( '@typescript-eslint/consistent-type-definitions': 'off', '@typescript-eslint/prefer-for-of': 'off', '@typescript-eslint/prefer-function-type': 'off', + // disable typecheck-specific rules (but worth revisiting again) + '@typescript-eslint/await-thenable': 'off', + '@typescript-eslint/dot-notation': 'off', + '@typescript-eslint/no-base-to-string': 'off', + '@typescript-eslint/no-duplicate-type-constituents': 'off', + '@typescript-eslint/no-implied-eval': 'off', + '@typescript-eslint/no-floating-promises': 'off', + '@typescript-eslint/no-misused-promises': 'off', + '@typescript-eslint/no-redundant-type-constituents': 'off', + '@typescript-eslint/no-unnecessary-type-assertion': 'off', + '@typescript-eslint/no-unsafe-argument': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-enum-comparison': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/non-nullable-type-assertion-style': 'off', + '@typescript-eslint/only-throw-error': 'off', + '@typescript-eslint/prefer-includes': 'off', + '@typescript-eslint/prefer-nullish-coalescing': 'off', + '@typescript-eslint/prefer-optional-chain': 'off', + '@typescript-eslint/prefer-promise-reject-errors': 'off', + '@typescript-eslint/prefer-string-starts-ends-with': 'off', + '@typescript-eslint/require-await': 'off', + '@typescript-eslint/restrict-plus-operands': 'off', + '@typescript-eslint/restrict-template-expressions': 'off', + '@typescript-eslint/unbound-method': 'off', 'import-x/no-duplicates': 'error', 'import-x/order': [ @@ -372,8 +393,9 @@ export default defineConfig( ], languageOptions: { parserOptions: { - project: false, + projectService: false, }, }, + extends: [tseslint.configs.disableTypeChecked], }, ) diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json index 990435e21331e7..543bd6a37445ba 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -17,6 +17,7 @@ "scripts": { "dev": "tsdown --watch", "build": "tsdown", + "typecheck": "tsc", "prepublishOnly": "npm run build" }, "engines": { diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index a57a2336c03e94..728b6866329577 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -73,6 +73,7 @@ function toOutputFilePathInHtml( if (relative && !config.build.ssr) { return toRelative(filename, hostId) } else { + // @ts-expect-error `decodedBase` is internal return joinUrlSegments(config.decodedBase, filename) } } diff --git a/packages/plugin-legacy/tsconfig.json b/packages/plugin-legacy/tsconfig.json index cbf0655e2187e0..1d348c263936c8 100644 --- a/packages/plugin-legacy/tsconfig.json +++ b/packages/plugin-legacy/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["src"], + "include": ["tsdown.config.ts", "src"], "exclude": ["**/*.spec.ts"], "compilerOptions": { "outDir": "dist", @@ -10,9 +10,7 @@ "isolatedDeclarations": true, "declaration": true, "sourceMap": true, - "noUnusedLocals": true, - "paths": { - "vite": ["../vite/src/node/index.js"] - } + "skipLibCheck": true, + "noUnusedLocals": true } } diff --git a/packages/plugin-legacy/tsdown.config.ts b/packages/plugin-legacy/tsdown.config.ts index 836521c90668f2..0e9930ba38c17a 100644 --- a/packages/plugin-legacy/tsdown.config.ts +++ b/packages/plugin-legacy/tsdown.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'tsdown' +import { type UserConfig, defineConfig } from 'tsdown' export default defineConfig({ entry: ['src/index.ts'], @@ -9,4 +9,4 @@ export default defineConfig({ deps: { onlyBundle: ['picocolors'], }, -}) +}) as UserConfig