import js from "@eslint/js";
import globals from "globals";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import reactCompiler from "eslint-plugin-react-compiler";
import tseslint from "typescript-eslint";
export default tseslint.config(
{ ignores: ["dist", "node_modules", "*.config.js", "*.config.ts"] },
{
extends: [
js.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked
],
files: ["**/*.{ts,tsx}"],
languageOptions: {
ecmaVersion: 2020,
globals: {
...globals.browser,
...globals.node, // For worker code
},
parserOptions: {
project: ["./tsconfig.app.json", "./tsconfig.worker.json", "./tsconfig.node.json"],
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
"react-hooks": reactHooks,
"react-refresh": reactRefresh,
"react-compiler": reactCompiler,
},
rules: {
...reactHooks.configs.recommended.rules,
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
"react-compiler/react-compiler": "error",
// TypeScript-specific improvements
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_"
}
],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-misused-promises": "error",
// Security and best practices
"no-console": ["warn", { allow: ["warn", "error"] }],
"prefer-const": "error",
"no-var": "error",
"eqeqeq": ["error", "always"],
"curly": ["error", "all"],
// Import organization
"sort-imports": ["error", {
ignoreCase: true,
ignoreDeclarationSort: true
}],
// Code style consistency
"@typescript-eslint/consistent-type-imports": [
"error",
{ prefer: "type-imports" }
],
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
// Error prevention
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/strict-boolean-expressions": "error",
},
},
// Worker-specific configuration
{
files: ["src/worker/**/*.ts"],
languageOptions: {
globals: {
...globals.worker,
...globals.node,
},
},
rules: {
// Allow console in worker code for debugging
"no-console": "off",
},
},
// Test-specific configuration
{
files: ["src/test/**/*.{ts,tsx}", "**/*.test.{ts,tsx}"],
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.jest,
},
},
rules: {
// More relaxed rules for tests
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"no-console": "off",
},
}
);