2021-03-31 21:20:10 +00:00
|
|
|
// @ts-check
|
2022-08-03 13:57:50 +00:00
|
|
|
const { builtinModules } = require('node:module')
|
2021-03-31 21:20:10 +00:00
|
|
|
const { defineConfig } = require('eslint-define-config')
|
|
|
|
|
|
|
|
module.exports = defineConfig({
|
2020-12-08 10:55:12 +00:00
|
|
|
root: true,
|
2021-04-25 11:34:25 +00:00
|
|
|
extends: [
|
|
|
|
'eslint:recommended',
|
2023-04-18 11:45:47 +00:00
|
|
|
'plugin:n/recommended',
|
2022-11-14 12:23:27 +00:00
|
|
|
'plugin:@typescript-eslint/recommended',
|
2023-07-15 06:09:56 +00:00
|
|
|
'plugin:@typescript-eslint/stylistic',
|
2022-11-14 12:23:27 +00:00
|
|
|
'plugin:regexp/recommended',
|
2021-04-25 11:34:25 +00:00
|
|
|
],
|
2023-04-20 07:56:12 +00:00
|
|
|
ignorePatterns: ['packages/create-vite/template-**'],
|
2022-11-14 12:23:27 +00:00
|
|
|
plugins: ['import', 'regexp'],
|
2020-12-08 10:55:12 +00:00
|
|
|
parser: '@typescript-eslint/parser',
|
|
|
|
parserOptions: {
|
|
|
|
sourceType: 'module',
|
2021-09-23 15:33:07 +00:00
|
|
|
ecmaVersion: 2021,
|
2020-12-08 10:55:12 +00:00
|
|
|
},
|
|
|
|
rules: {
|
2021-07-13 15:05:08 +00:00
|
|
|
eqeqeq: ['warn', 'always', { null: 'never' }],
|
2020-12-19 02:29:04 +00:00
|
|
|
'no-debugger': ['error'],
|
2021-04-25 11:34:25 +00:00
|
|
|
'no-empty': ['warn', { allowEmptyCatch: true }],
|
|
|
|
'no-process-exit': 'off',
|
|
|
|
'no-useless-escape': 'off',
|
|
|
|
'prefer-const': [
|
|
|
|
'warn',
|
|
|
|
{
|
|
|
|
destructuring: 'all',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
2023-04-18 11:45:47 +00:00
|
|
|
'n/no-process-exit': 'off',
|
|
|
|
'n/no-missing-import': 'off',
|
|
|
|
'n/no-missing-require': [
|
2020-12-08 10:55:12 +00:00
|
|
|
'error',
|
|
|
|
{
|
2020-12-16 22:24:02 +00:00
|
|
|
// for try-catching yarn pnp
|
2021-09-24 20:21:04 +00:00
|
|
|
allowModules: ['pnpapi', 'vite'],
|
2021-03-15 14:19:44 +00:00
|
|
|
tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'],
|
2020-12-08 10:55:12 +00:00
|
|
|
},
|
|
|
|
],
|
2023-04-18 11:45:47 +00:00
|
|
|
'n/no-extraneous-import': [
|
2020-12-09 08:26:05 +00:00
|
|
|
'error',
|
|
|
|
{
|
2023-04-18 11:45:47 +00:00
|
|
|
allowModules: ['vite', 'less', 'sass', 'vitest', 'unbuild'],
|
2020-12-09 08:26:05 +00:00
|
|
|
},
|
|
|
|
],
|
2023-04-18 11:45:47 +00:00
|
|
|
'n/no-extraneous-require': [
|
2020-12-09 20:41:13 +00:00
|
|
|
'error',
|
|
|
|
{
|
|
|
|
allowModules: ['vite'],
|
|
|
|
},
|
|
|
|
],
|
2023-04-18 11:45:47 +00:00
|
|
|
'n/no-deprecated-api': 'off',
|
|
|
|
'n/no-unpublished-import': 'off',
|
|
|
|
'n/no-unpublished-require': 'off',
|
|
|
|
'n/no-unsupported-features/es-syntax': 'off',
|
2021-04-25 11:34:25 +00:00
|
|
|
|
2022-12-12 10:59:02 +00:00
|
|
|
'@typescript-eslint/ban-ts-comment': 'error',
|
2021-04-25 11:34:25 +00:00
|
|
|
'@typescript-eslint/ban-types': 'off', // TODO: we should turn this on in a new PR
|
2022-05-28 20:08:56 +00:00
|
|
|
'@typescript-eslint/explicit-module-boundary-types': [
|
|
|
|
'error',
|
|
|
|
{ allowArgumentsExplicitlyTypedAsAny: true },
|
|
|
|
],
|
2021-04-25 11:34:25 +00:00
|
|
|
'@typescript-eslint/no-empty-function': [
|
|
|
|
'error',
|
|
|
|
{ allow: ['arrowFunctions'] },
|
|
|
|
],
|
2021-07-28 05:11:23 +00:00
|
|
|
'@typescript-eslint/no-empty-interface': 'off',
|
2021-04-25 11:34:25 +00:00
|
|
|
'@typescript-eslint/no-explicit-any': 'off', // maybe we should turn this on in a new PR
|
2023-07-15 06:09:56 +00:00
|
|
|
'no-extra-semi': 'off',
|
2021-04-25 11:34:25 +00:00
|
|
|
'@typescript-eslint/no-extra-semi': 'off', // conflicts with prettier
|
|
|
|
'@typescript-eslint/no-inferrable-types': 'off',
|
|
|
|
'@typescript-eslint/no-unused-vars': 'off', // maybe we should turn this on in a new PR
|
2021-12-19 11:35:25 +00:00
|
|
|
'@typescript-eslint/no-var-requires': 'off',
|
|
|
|
'@typescript-eslint/consistent-type-imports': [
|
|
|
|
'error',
|
2023-07-22 09:37:17 +00:00
|
|
|
{ prefer: 'type-imports', disallowTypeAnnotations: false },
|
2022-05-11 08:44:14 +00:00
|
|
|
],
|
2023-07-15 06:09:56 +00:00
|
|
|
// disable rules set in @typescript-eslint/stylistic v6 that wasn't set in @typescript-eslint/recommended v5 and which conflict with current code
|
|
|
|
// maybe we should turn them on in a new PR
|
|
|
|
'@typescript-eslint/array-type': 'off',
|
|
|
|
'@typescript-eslint/ban-tslint-comment': 'off',
|
|
|
|
'@typescript-eslint/consistent-generic-constructors': 'off',
|
|
|
|
'@typescript-eslint/consistent-indexed-object-style': 'off',
|
|
|
|
'@typescript-eslint/consistent-type-definitions': 'off',
|
|
|
|
'@typescript-eslint/prefer-for-of': 'off',
|
|
|
|
'@typescript-eslint/prefer-function-type': 'off',
|
2022-05-11 08:44:14 +00:00
|
|
|
|
2022-08-03 13:57:50 +00:00
|
|
|
'import/no-nodejs-modules': [
|
|
|
|
'error',
|
|
|
|
{ allow: builtinModules.map((mod) => `node:${mod}`) },
|
|
|
|
],
|
2022-05-17 14:32:43 +00:00
|
|
|
'import/no-duplicates': 'error',
|
2022-05-11 08:44:14 +00:00
|
|
|
'import/order': 'error',
|
|
|
|
'sort-imports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
ignoreCase: false,
|
|
|
|
ignoreDeclarationSort: true,
|
|
|
|
ignoreMemberSort: false,
|
|
|
|
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
|
|
|
|
allowSeparatedGroups: false,
|
|
|
|
},
|
2022-11-14 12:23:27 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
'regexp/no-contradiction-with-assertion': 'error',
|
2020-12-18 22:13:18 +00:00
|
|
|
},
|
|
|
|
overrides: [
|
2022-08-01 05:39:26 +00:00
|
|
|
{
|
|
|
|
files: ['packages/**'],
|
|
|
|
excludedFiles: '**/__tests__/**',
|
|
|
|
rules: {
|
|
|
|
'no-restricted-globals': [
|
|
|
|
'error',
|
|
|
|
'require',
|
|
|
|
'__dirname',
|
|
|
|
'__filename',
|
2022-12-04 07:19:06 +00:00
|
|
|
],
|
2022-08-01 05:39:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: 'packages/vite/**/*.*',
|
|
|
|
rules: {
|
2023-04-18 11:45:47 +00:00
|
|
|
'n/no-restricted-require': [
|
2022-08-01 05:39:26 +00:00
|
|
|
'error',
|
|
|
|
Object.keys(
|
|
|
|
require('./packages/vite/package.json').devDependencies,
|
|
|
|
).map((d) => ({
|
|
|
|
name: d,
|
|
|
|
message:
|
|
|
|
`devDependencies can only be imported using ESM syntax so ` +
|
|
|
|
`that they are included in the rollup bundle. If you are trying to ` +
|
|
|
|
`lazy load a dependency, use (await import('dependency')).default instead.`,
|
|
|
|
})),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2020-12-18 22:13:18 +00:00
|
|
|
{
|
|
|
|
files: ['packages/vite/src/node/**'],
|
|
|
|
rules: {
|
|
|
|
'no-console': ['error'],
|
|
|
|
},
|
2020-12-19 05:23:51 +00:00
|
|
|
},
|
2021-09-24 20:21:04 +00:00
|
|
|
{
|
2023-06-19 13:46:46 +00:00
|
|
|
files: [
|
|
|
|
'packages/vite/src/types/**',
|
|
|
|
'packages/vite/scripts/**',
|
|
|
|
'*.spec.ts',
|
|
|
|
],
|
2021-09-24 20:21:04 +00:00
|
|
|
rules: {
|
2023-04-18 11:45:47 +00:00
|
|
|
'n/no-extraneous-import': 'off',
|
2021-09-24 20:21:04 +00:00
|
|
|
},
|
|
|
|
},
|
2022-05-19 01:23:45 +00:00
|
|
|
{
|
2022-08-01 05:39:26 +00:00
|
|
|
files: ['packages/create-vite/template-*/**', '**/build.config.ts'],
|
2022-05-19 01:23:45 +00:00
|
|
|
rules: {
|
2022-08-01 05:39:26 +00:00
|
|
|
'no-undef': 'off',
|
2023-04-18 11:45:47 +00:00
|
|
|
'n/no-missing-import': 'off',
|
2022-08-01 05:39:26 +00:00
|
|
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
2022-05-19 01:23:45 +00:00
|
|
|
},
|
|
|
|
},
|
2020-12-19 05:23:51 +00:00
|
|
|
{
|
2022-05-09 07:36:14 +00:00
|
|
|
files: ['playground/**'],
|
2020-12-19 05:23:51 +00:00
|
|
|
rules: {
|
2023-04-18 11:45:47 +00:00
|
|
|
'n/no-extraneous-import': 'off',
|
|
|
|
'n/no-extraneous-require': 'off',
|
|
|
|
'n/no-missing-import': 'off',
|
|
|
|
'n/no-missing-require': 'off',
|
2022-05-29 17:34:03 +00:00
|
|
|
// engine field doesn't exist in playgrounds
|
2023-04-18 11:45:47 +00:00
|
|
|
'n/no-unsupported-features/es-builtins': [
|
2022-05-29 17:34:03 +00:00
|
|
|
'error',
|
|
|
|
{
|
2022-07-15 13:23:41 +00:00
|
|
|
version: '^14.18.0 || >=16.0.0',
|
2022-05-29 17:34:03 +00:00
|
|
|
},
|
|
|
|
],
|
2023-04-18 11:45:47 +00:00
|
|
|
'n/no-unsupported-features/node-builtins': [
|
2022-05-29 17:34:03 +00:00
|
|
|
'error',
|
|
|
|
{
|
2022-07-15 13:23:41 +00:00
|
|
|
version: '^14.18.0 || >=16.0.0',
|
2022-05-29 17:34:03 +00:00
|
|
|
},
|
2022-08-01 05:39:26 +00:00
|
|
|
],
|
|
|
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
2020-12-19 05:23:51 +00:00
|
|
|
},
|
2021-01-05 06:04:20 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-01 05:39:26 +00:00
|
|
|
files: ['playground/**'],
|
|
|
|
excludedFiles: '**/__tests__/**',
|
2021-01-05 06:04:20 +00:00
|
|
|
rules: {
|
2022-08-01 05:39:26 +00:00
|
|
|
'no-undef': 'off',
|
|
|
|
'no-empty': 'off',
|
|
|
|
'no-constant-condition': 'off',
|
|
|
|
'@typescript-eslint/no-empty-function': 'off',
|
2021-01-05 06:04:20 +00:00
|
|
|
},
|
2021-05-29 23:45:39 +00:00
|
|
|
},
|
2023-05-09 09:33:34 +00:00
|
|
|
{
|
|
|
|
files: ['playground/**'],
|
|
|
|
excludedFiles: [
|
|
|
|
'playground/ssr-resolve/**',
|
|
|
|
'playground/**/*{commonjs,cjs}*/**',
|
|
|
|
'playground/**/*{commonjs,cjs}*',
|
|
|
|
'playground/**/*dep*/**',
|
|
|
|
'playground/resolve/browser-module-field2/index.web.js',
|
|
|
|
'playground/resolve/browser-field/**',
|
|
|
|
'playground/tailwind/**', // blocked by https://github.com/postcss/postcss-load-config/issues/239
|
|
|
|
],
|
|
|
|
rules: {
|
|
|
|
'import/no-commonjs': 'error',
|
|
|
|
},
|
|
|
|
},
|
2022-12-12 10:59:02 +00:00
|
|
|
{
|
|
|
|
files: [
|
|
|
|
'playground/tsconfig-json/**',
|
|
|
|
'playground/tsconfig-json-load-error/**',
|
|
|
|
],
|
|
|
|
excludedFiles: '**/__tests__/**',
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/ban-ts-comment': 'off',
|
|
|
|
},
|
|
|
|
},
|
2021-05-29 23:45:39 +00:00
|
|
|
{
|
2022-08-29 18:21:35 +00:00
|
|
|
files: ['*.js', '*.mjs', '*.cjs'],
|
2021-05-29 23:45:39 +00:00
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
|
|
},
|
2021-06-30 07:40:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['*.d.ts'],
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/triple-slash-reference': 'off',
|
|
|
|
},
|
2020-12-18 22:13:18 +00:00
|
|
|
},
|
2022-05-29 15:25:01 +00:00
|
|
|
],
|
|
|
|
reportUnusedDisableDirectives: true,
|
2021-03-31 21:20:10 +00:00
|
|
|
})
|