|
| 1 | +// @ts-check |
| 2 | +import { builtinModules } from 'node:module' |
| 3 | +import eslint from '@eslint/js' |
| 4 | +import pluginN from 'eslint-plugin-n' |
| 5 | +import pluginImportX from 'eslint-plugin-import-x' |
| 6 | +import pluginRegExp from 'eslint-plugin-regexp' |
| 7 | +import tseslint from 'typescript-eslint' |
| 8 | +import globals from 'globals' |
| 9 | + |
| 10 | +export default tseslint.config( |
| 11 | + { |
| 12 | + ignores: ['**/dist/**', '**/playground-temp/**', '**/temp/**'], |
| 13 | + }, |
| 14 | + eslint.configs.recommended, |
| 15 | + ...tseslint.configs.recommended, |
| 16 | + ...tseslint.configs.stylistic, |
| 17 | + pluginN.configs['flat/recommended'], |
| 18 | + pluginRegExp.configs['flat/recommended'], |
| 19 | + { |
| 20 | + name: 'main', |
| 21 | + languageOptions: { |
| 22 | + parser: tseslint.parser, |
| 23 | + parserOptions: { |
| 24 | + sourceType: 'module', |
| 25 | + ecmaVersion: 2021, |
| 26 | + }, |
| 27 | + globals: { |
| 28 | + ...globals.es2021, |
| 29 | + ...globals.node, |
| 30 | + }, |
| 31 | + }, |
| 32 | + plugins: { |
| 33 | + n: pluginN, |
| 34 | + 'import-x': pluginImportX, |
| 35 | + }, |
| 36 | + rules: { |
| 37 | + eqeqeq: ['warn', 'always', { null: 'never' }], |
| 38 | + 'no-debugger': ['error'], |
| 39 | + 'no-empty': ['warn', { allowEmptyCatch: true }], |
| 40 | + 'prefer-const': [ |
| 41 | + 'warn', |
| 42 | + { |
| 43 | + destructuring: 'all', |
| 44 | + }, |
| 45 | + ], |
| 46 | + |
| 47 | + 'n/no-process-exit': 'off', |
| 48 | + 'n/no-deprecated-api': 'off', |
| 49 | + 'n/no-unpublished-import': 'off', |
| 50 | + 'n/no-unpublished-require': 'off', |
| 51 | + 'n/no-unsupported-features/es-syntax': 'off', |
| 52 | + 'n/no-missing-import': [ |
| 53 | + 'error', |
| 54 | + { |
| 55 | + tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'], |
| 56 | + }, |
| 57 | + ], |
| 58 | + |
| 59 | + '@typescript-eslint/explicit-module-boundary-types': [ |
| 60 | + 'error', |
| 61 | + { allowArgumentsExplicitlyTypedAsAny: true }, |
| 62 | + ], |
| 63 | + '@typescript-eslint/no-empty-function': [ |
| 64 | + 'error', |
| 65 | + { allow: ['arrowFunctions'] }, |
| 66 | + ], |
| 67 | + '@typescript-eslint/no-empty-interface': 'off', |
| 68 | + '@typescript-eslint/no-explicit-any': 'off', |
| 69 | + 'no-extra-semi': 'off', |
| 70 | + '@typescript-eslint/no-extra-semi': 'off', // conflicts with prettier |
| 71 | + '@typescript-eslint/no-inferrable-types': 'off', |
| 72 | + '@typescript-eslint/no-unused-vars': [ |
| 73 | + 'error', |
| 74 | + { |
| 75 | + args: 'all', |
| 76 | + argsIgnorePattern: '^_', |
| 77 | + caughtErrors: 'all', |
| 78 | + caughtErrorsIgnorePattern: '^_', |
| 79 | + destructuredArrayIgnorePattern: '^_', |
| 80 | + varsIgnorePattern: '^_', |
| 81 | + ignoreRestSiblings: true, |
| 82 | + }, |
| 83 | + ], |
| 84 | + '@typescript-eslint/no-var-requires': 'off', |
| 85 | + '@typescript-eslint/consistent-type-imports': [ |
| 86 | + 'error', |
| 87 | + { prefer: 'type-imports', disallowTypeAnnotations: false }, |
| 88 | + ], |
| 89 | + // disable rules set in @typescript-eslint/stylistic which conflict with current code |
| 90 | + // we should discuss if we want to enable these as they encourage consistent code |
| 91 | + '@typescript-eslint/array-type': 'off', |
| 92 | + '@typescript-eslint/consistent-type-definitions': 'off', |
| 93 | + '@typescript-eslint/prefer-for-of': 'off', |
| 94 | + '@typescript-eslint/prefer-function-type': 'off', |
| 95 | + |
| 96 | + 'import-x/no-nodejs-modules': [ |
| 97 | + 'error', |
| 98 | + { allow: builtinModules.map((mod) => `node:${mod}`) }, |
| 99 | + ], |
| 100 | + 'import-x/no-duplicates': 'error', |
| 101 | + 'import-x/order': 'error', |
| 102 | + 'sort-imports': [ |
| 103 | + 'error', |
| 104 | + { |
| 105 | + ignoreCase: false, |
| 106 | + ignoreDeclarationSort: true, |
| 107 | + ignoreMemberSort: false, |
| 108 | + memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], |
| 109 | + allowSeparatedGroups: false, |
| 110 | + }, |
| 111 | + ], |
| 112 | + |
| 113 | + 'regexp/prefer-regexp-exec': 'error', |
| 114 | + 'regexp/prefer-regexp-test': 'error', |
| 115 | + // in some cases using explicit letter-casing is more performant than the `i` flag |
| 116 | + 'regexp/use-ignore-case': 'off', |
| 117 | + }, |
| 118 | + }, |
| 119 | + { |
| 120 | + name: 'vite/globals', |
| 121 | + files: ['packages/**/*.?([cm])[jt]s?(x)'], |
| 122 | + ignores: ['**/__tests__/**'], |
| 123 | + rules: { |
| 124 | + 'no-restricted-globals': ['error', 'require', '__dirname', '__filename'], |
| 125 | + }, |
| 126 | + }, |
| 127 | + { |
| 128 | + name: 'disables/playground', |
| 129 | + files: [ |
| 130 | + 'playground/**/*.?([cm])[jt]s?(x)', |
| 131 | + 'packages/plugin-react-swc/playground/**/*.?([cm])[jt]s?(x)', |
| 132 | + ], |
| 133 | + rules: { |
| 134 | + 'n/no-extraneous-import': 'off', |
| 135 | + 'n/no-extraneous-require': 'off', |
| 136 | + 'n/no-missing-import': 'off', |
| 137 | + 'n/no-missing-require': 'off', |
| 138 | + 'n/no-unsupported-features/es-builtins': 'off', |
| 139 | + 'n/no-unsupported-features/node-builtins': 'off', |
| 140 | + '@typescript-eslint/explicit-module-boundary-types': 'off', |
| 141 | + '@typescript-eslint/no-unused-expressions': 'off', |
| 142 | + '@typescript-eslint/no-unused-vars': 'off', |
| 143 | + 'no-undef': 'off', |
| 144 | + 'no-empty': 'off', |
| 145 | + 'no-constant-condition': 'off', |
| 146 | + '@typescript-eslint/no-empty-function': 'off', |
| 147 | + }, |
| 148 | + }, |
| 149 | + { |
| 150 | + name: 'disables/js', |
| 151 | + files: ['**/*.js', '**/*.mjs', '**/*.cjs'], |
| 152 | + rules: { |
| 153 | + '@typescript-eslint/explicit-module-boundary-types': 'off', |
| 154 | + '@typescript-eslint/no-unused-vars': 'off', |
| 155 | + }, |
| 156 | + }, |
| 157 | + { |
| 158 | + name: 'disables/dts', |
| 159 | + files: ['**/*.d.ts'], |
| 160 | + rules: { |
| 161 | + '@typescript-eslint/consistent-indexed-object-style': 'off', |
| 162 | + '@typescript-eslint/triple-slash-reference': 'off', |
| 163 | + }, |
| 164 | + }, |
| 165 | +) |
0 commit comments