|
| 1 | +import { fixupConfigRules } from "@eslint/compat"; |
| 2 | +import { FlatCompat } from "@eslint/eslintrc"; |
| 3 | +import eslint from "@eslint/js"; |
| 4 | +import vitestPlugin from "@vitest/eslint-plugin"; |
| 5 | +import prettierConfig from "eslint-config-prettier"; |
| 6 | +import importPlugin from "eslint-plugin-import-x"; |
| 7 | +import unicornPlugin from "eslint-plugin-unicorn"; |
| 8 | +import unusedImportsPlugin from "eslint-plugin-unused-imports"; |
| 9 | +import globals from "globals"; |
| 10 | +import tseslint from "typescript-eslint"; |
| 11 | + |
| 12 | +const compat = new FlatCompat(); |
| 13 | +const standard = fixupConfigRules(compat.config({ extends: ["standard"] })); |
| 14 | + |
| 15 | +/** @type {import("eslint").Linter.Config[]} */ |
| 16 | +const config = [ |
| 17 | + eslint.configs.recommended, |
| 18 | + ...standard, |
| 19 | + { |
| 20 | + ignores: [ |
| 21 | + "**/fixtures/**", |
| 22 | + "**/dist/**", |
| 23 | + "**/build/**", |
| 24 | + "**/node_modules/**", |
| 25 | + "worker-configuration.d.ts", |
| 26 | + ".wrangler", |
| 27 | + "example/**", |
| 28 | + "*.config.js", |
| 29 | + ], |
| 30 | + }, |
| 31 | + { |
| 32 | + files: ["**/*.{js,ts,tsx}"], |
| 33 | + languageOptions: { |
| 34 | + ecmaVersion: 2024, |
| 35 | + sourceType: "module", |
| 36 | + parser: tseslint.parser, |
| 37 | + parserOptions: { |
| 38 | + project: true, |
| 39 | + }, |
| 40 | + }, |
| 41 | + rules: { |
| 42 | + "no-void": "off", |
| 43 | + "no-unreachable": "error", |
| 44 | + "no-restricted-imports": "off", |
| 45 | + "lines-between-class-members": "off", |
| 46 | + "no-array-constructor": "off", |
| 47 | + "no-console": "error", |
| 48 | + "newline-before-return": "error", |
| 49 | + "no-unused-vars": "off", |
| 50 | + camelcase: [ |
| 51 | + "error", |
| 52 | + { |
| 53 | + ignoreImports: true, |
| 54 | + properties: "never", |
| 55 | + allow: [], |
| 56 | + }, |
| 57 | + ], |
| 58 | + }, |
| 59 | + }, |
| 60 | + { |
| 61 | + files: ["**/*.{js,ts,tsx}"], |
| 62 | + languageOptions: { |
| 63 | + ecmaVersion: 2024, |
| 64 | + sourceType: "module", |
| 65 | + parser: tseslint.parser, |
| 66 | + parserOptions: { |
| 67 | + project: true, |
| 68 | + }, |
| 69 | + globals: { |
| 70 | + ...globals.es2024, |
| 71 | + CloudflareEnv: "readonly", |
| 72 | + Queue: "readonly", |
| 73 | + ExecutionContext: "readonly", |
| 74 | + ExportedHandler: "readonly", |
| 75 | + DurableObjectNamespace: "readonly", |
| 76 | + WebSocket: "readonly", |
| 77 | + DurableObjectStub: "readonly", |
| 78 | + DurableObjectTransaction: "readonly", |
| 79 | + DurableObjectState: "readonly", |
| 80 | + WebSocketPair: "readonly", |
| 81 | + RequestInfo: "readonly", |
| 82 | + }, |
| 83 | + }, |
| 84 | + plugins: { |
| 85 | + "@typescript-eslint": tseslint.plugin, |
| 86 | + "import-x": importPlugin, |
| 87 | + "unused-imports": unusedImportsPlugin, |
| 88 | + unicorn: unicornPlugin, |
| 89 | + }, |
| 90 | + rules: { |
| 91 | + ...importPlugin.configs.recommended.rules, |
| 92 | + "@typescript-eslint/no-unused-vars": [ |
| 93 | + "error", |
| 94 | + { |
| 95 | + argsIgnorePattern: "^_", |
| 96 | + varsIgnorePattern: "^_", |
| 97 | + caughtErrorsIgnorePattern: "^_", |
| 98 | + destructuredArrayIgnorePattern: "^_", |
| 99 | + }, |
| 100 | + ], |
| 101 | + "@typescript-eslint/no-use-before-define": "off", |
| 102 | + "@typescript-eslint/interface-name-prefix": "off", |
| 103 | + "@typescript-eslint/explicit-module-boundary-types": "off", |
| 104 | + "@typescript-eslint/no-explicit-any": "error", |
| 105 | + "@typescript-eslint/no-var-requires": "error", |
| 106 | + "@typescript-eslint/no-floating-promises": "error", |
| 107 | + "@typescript-eslint/no-array-constructor": "error", |
| 108 | + "@typescript-eslint/no-unnecessary-condition": "error", |
| 109 | + "@typescript-eslint/strict-boolean-expressions": "error", |
| 110 | + "@typescript-eslint/no-unnecessary-boolean-literal-compare": "error", |
| 111 | + "@typescript-eslint/consistent-generic-constructors": [ |
| 112 | + "error", |
| 113 | + "constructor", |
| 114 | + ], |
| 115 | + "@typescript-eslint/array-type": ["error", { default: "array" }], |
| 116 | + "@typescript-eslint/consistent-type-exports": [ |
| 117 | + "error", |
| 118 | + { |
| 119 | + fixMixedExportsWithInlineTypeSpecifier: false, |
| 120 | + }, |
| 121 | + ], |
| 122 | + "@typescript-eslint/consistent-type-imports": [ |
| 123 | + "error", |
| 124 | + { |
| 125 | + prefer: "type-imports", |
| 126 | + }, |
| 127 | + ], |
| 128 | + "import-x/default": "off", |
| 129 | + "import-x/no-named-as-default-member": "off", |
| 130 | + "import-x/order": [ |
| 131 | + "error", |
| 132 | + { |
| 133 | + groups: [ |
| 134 | + "builtin", |
| 135 | + "external", |
| 136 | + "internal", |
| 137 | + "parent", |
| 138 | + "sibling", |
| 139 | + "index", |
| 140 | + "object", |
| 141 | + "type", |
| 142 | + ], |
| 143 | + "newlines-between": "always", |
| 144 | + pathGroupsExcludedImportTypes: ["builtin"], |
| 145 | + alphabetize: { order: "asc", caseInsensitive: true }, |
| 146 | + pathGroups: [ |
| 147 | + { pattern: "./types/**", group: "internal", position: "before" }, |
| 148 | + ], |
| 149 | + }, |
| 150 | + ], |
| 151 | + "import-x/no-unresolved": [ |
| 152 | + "error", |
| 153 | + { |
| 154 | + ignore: ["^cloudflare:"], |
| 155 | + }, |
| 156 | + ], |
| 157 | + "unused-imports/no-unused-imports": "warn", |
| 158 | + "unicorn/prefer-node-protocol": "error", |
| 159 | + "unicorn/filename-case": ["error", { case: "kebabCase" }], |
| 160 | + "unicorn/better-regex": "error", |
| 161 | + }, |
| 162 | + settings: { |
| 163 | + "import-x/resolver": { |
| 164 | + typescript: true, |
| 165 | + node: true, |
| 166 | + }, |
| 167 | + "import-x/parsers": { |
| 168 | + "@typescript-eslint/parser": [".js", ".jsx", ".ts", ".tsx"], |
| 169 | + }, |
| 170 | + }, |
| 171 | + }, |
| 172 | + { |
| 173 | + files: ["**/*.test.{ts,tsx}"], |
| 174 | + plugins: { |
| 175 | + vitest: vitestPlugin, |
| 176 | + }, |
| 177 | + languageOptions: { |
| 178 | + globals: { |
| 179 | + ...globals.vitest, |
| 180 | + }, |
| 181 | + }, |
| 182 | + rules: { |
| 183 | + ...vitestPlugin.configs.recommended.rules, |
| 184 | + "@typescript-eslint/no-unused-vars": "off", |
| 185 | + "no-console": "off", |
| 186 | + "vitest/max-nested-describe": ["error", { max: 3 }], |
| 187 | + }, |
| 188 | + }, |
| 189 | + prettierConfig, |
| 190 | +]; |
| 191 | + |
| 192 | +export default config; |
0 commit comments