|
| 1 | +const { defineConfig, globalIgnores } = require("eslint/config"); |
| 2 | + |
| 3 | +const globals = require("globals"); |
| 4 | + |
| 5 | +const { fixupConfigRules, fixupPluginRules } = require("@eslint/compat"); |
| 6 | + |
| 7 | +const tsParser = require("@typescript-eslint/parser"); |
| 8 | +const promise = require("eslint-plugin-promise"); |
| 9 | +const typescriptEslint = require("@typescript-eslint/eslint-plugin"); |
| 10 | +const _import = require("eslint-plugin-import"); |
| 11 | +const react = require("eslint-plugin-react"); |
| 12 | +const js = require("@eslint/js"); |
| 13 | + |
| 14 | +const { FlatCompat } = require("@eslint/eslintrc"); |
| 15 | + |
| 16 | +const compat = new FlatCompat({ |
| 17 | + baseDirectory: __dirname, |
| 18 | + recommendedConfig: js.configs.recommended, |
| 19 | + allConfig: js.configs.all, |
| 20 | +}); |
| 21 | + |
| 22 | +const sharedSettings = { |
| 23 | + react: { |
| 24 | + // Avoid "React version detect" warning in a monorepo root |
| 25 | + version: "18.0", |
| 26 | + }, |
| 27 | + "import/parsers": { |
| 28 | + "@typescript-eslint/parser": [".ts", ".tsx"], |
| 29 | + }, |
| 30 | + "import/resolver": { |
| 31 | + typescript: { |
| 32 | + alwaysTryTypes: true, |
| 33 | + project: [ |
| 34 | + "./tsconfig.base.json", |
| 35 | + "./server/tsconfig.json", |
| 36 | + "./frontend/tsconfig.json", |
| 37 | + "./shared/tsconfig.json", |
| 38 | + ], |
| 39 | + }, |
| 40 | + node: true, |
| 41 | + }, |
| 42 | +}; |
| 43 | + |
| 44 | +const sharedRules = { |
| 45 | + "import/extensions": [ |
| 46 | + "error", |
| 47 | + "ignorePackages", |
| 48 | + { js: "never", jsx: "never", ts: "never", tsx: "never" }, |
| 49 | + ], |
| 50 | + "linebreak-style": "off", |
| 51 | + |
| 52 | + // The codebase uses the React 17+ JSX runtime (no need for `import React`) |
| 53 | + "react/react-in-jsx-scope": "off", |
| 54 | + "react/jsx-uses-react": "off", |
| 55 | + |
| 56 | + // Keep CI green while we gradually clean up the repo. |
| 57 | + "no-empty": ["warn", { allowEmptyCatch: true }], |
| 58 | + "no-useless-assignment": "warn", |
| 59 | + "no-constant-binary-expression": "warn", |
| 60 | + "react/jsx-key": "warn", |
| 61 | + "preserve-caught-error": "warn", |
| 62 | + "react/prop-types": "off", |
| 63 | + "react/no-unescaped-entities": "off", |
| 64 | + "react/display-name": "off", |
| 65 | +}; |
| 66 | + |
| 67 | +const tsRules = { |
| 68 | + // Keep CI green while we gradually clean up the repo. |
| 69 | + "@typescript-eslint/no-unused-vars": [ |
| 70 | + "warn", |
| 71 | + { |
| 72 | + args: "after-used", |
| 73 | + argsIgnorePattern: "^_", |
| 74 | + varsIgnorePattern: "^_", |
| 75 | + caughtErrors: "all", |
| 76 | + caughtErrorsIgnorePattern: "^_", |
| 77 | + ignoreRestSiblings: true, |
| 78 | + }, |
| 79 | + ], |
| 80 | + "@typescript-eslint/no-unused-expressions": [ |
| 81 | + "warn", |
| 82 | + { allowShortCircuit: true, allowTernary: true, allowTaggedTemplates: true }, |
| 83 | + ], |
| 84 | + "@typescript-eslint/no-empty-object-type": "warn", |
| 85 | + "@typescript-eslint/ban-ts-comment": "warn", |
| 86 | + |
| 87 | + "@typescript-eslint/explicit-function-return-type": "off", |
| 88 | + "@typescript-eslint/explicit-module-boundary-types": "off", |
| 89 | + "@typescript-eslint/no-explicit-any": "off", |
| 90 | + "@typescript-eslint/no-empty-function": "off", |
| 91 | + "@typescript-eslint/no-non-null-assertion": "off", |
| 92 | +}; |
| 93 | + |
| 94 | +module.exports = defineConfig([ |
| 95 | + // JS / JSX |
| 96 | + { |
| 97 | + files: ["**/*.{js,jsx,cjs,mjs}"], |
| 98 | + ignores: ["eslint.config.js", ".eslintrc.js"], |
| 99 | + languageOptions: { |
| 100 | + globals: { |
| 101 | + ...globals.browser, |
| 102 | + ...globals.node, |
| 103 | + Atomics: "readonly", |
| 104 | + SharedArrayBuffer: "readonly", |
| 105 | + }, |
| 106 | + ecmaVersion: "latest", |
| 107 | + sourceType: "module", |
| 108 | + }, |
| 109 | + extends: fixupConfigRules( |
| 110 | + compat.extends( |
| 111 | + "eslint:recommended", |
| 112 | + "plugin:react/recommended", |
| 113 | + "plugin:react/jsx-runtime", |
| 114 | + "plugin:import/errors", |
| 115 | + "plugin:import/warnings", |
| 116 | + "prettier", |
| 117 | + ), |
| 118 | + ), |
| 119 | + plugins: { |
| 120 | + promise, |
| 121 | + import: fixupPluginRules(_import), |
| 122 | + react: fixupPluginRules(react), |
| 123 | + }, |
| 124 | + rules: sharedRules, |
| 125 | + settings: sharedSettings, |
| 126 | + }, |
| 127 | + |
| 128 | + // TS / TSX |
| 129 | + { |
| 130 | + files: ["**/*.{ts,tsx}"], |
| 131 | + languageOptions: { |
| 132 | + globals: { |
| 133 | + ...globals.browser, |
| 134 | + ...globals.node, |
| 135 | + Atomics: "readonly", |
| 136 | + SharedArrayBuffer: "readonly", |
| 137 | + }, |
| 138 | + parser: tsParser, |
| 139 | + ecmaVersion: "latest", |
| 140 | + sourceType: "module", |
| 141 | + parserOptions: {}, |
| 142 | + }, |
| 143 | + extends: fixupConfigRules( |
| 144 | + compat.extends( |
| 145 | + "eslint:recommended", |
| 146 | + "plugin:@typescript-eslint/recommended", |
| 147 | + "plugin:react/recommended", |
| 148 | + "plugin:react/jsx-runtime", |
| 149 | + "plugin:import/errors", |
| 150 | + "plugin:import/warnings", |
| 151 | + "plugin:import/typescript", |
| 152 | + "prettier", |
| 153 | + ), |
| 154 | + ), |
| 155 | + plugins: { |
| 156 | + promise, |
| 157 | + "@typescript-eslint": fixupPluginRules(typescriptEslint), |
| 158 | + import: fixupPluginRules(_import), |
| 159 | + react: fixupPluginRules(react), |
| 160 | + }, |
| 161 | + rules: { ...sharedRules, ...tsRules }, |
| 162 | + settings: sharedSettings, |
| 163 | + }, |
| 164 | + |
| 165 | + globalIgnores([ |
| 166 | + "**/node_modules/**", |
| 167 | + "**/dist/**", |
| 168 | + "**/build/**", |
| 169 | + "**/tests/**", |
| 170 | + "eslint.config.js", |
| 171 | + ".eslintrc.js", |
| 172 | + ]), |
| 173 | +]); |
0 commit comments