import js from "@eslint/js";
import tseslint from "@typescript-eslint/eslint-plugin";
import tsparser from "@typescript-eslint/parser";
import prettierPlugin from "eslint-plugin-prettier";
export default [
js.configs.recommended,
{
files: ["**/*.ts"],
ignores: ["**/__tests__/**/*.ts", "**/*.test.ts", "**/*.spec.ts", "tests/**/*.ts"],
languageOptions: {
parser: tsparser,
parserOptions: {
project: "./tsconfig.json",
sourceType: "module",
},
globals: {
console: "readonly",
process: "readonly",
Buffer: "readonly",
NodeJS: "readonly",
URL: "readonly",
setTimeout: "readonly",
setInterval: "readonly",
clearInterval: "readonly",
clearTimeout: "readonly",
fetch: "readonly",
// Node.js CommonJS globals
__dirname: "readonly",
__filename: "readonly",
module: "readonly",
require: "readonly",
},
},
plugins: {
"@typescript-eslint": tseslint,
prettier: prettierPlugin,
},
rules: {
"prettier/prettier": "error",
"no-unused-vars": "off", // Disable base rule in favor of @typescript-eslint version
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-unsafe-assignment": "error",
"@typescript-eslint/no-unsafe-member-access": "error",
"@typescript-eslint/no-unsafe-call": "error",
"@typescript-eslint/no-unsafe-return": "error",
"@typescript-eslint/restrict-template-expressions": "error",
"@typescript-eslint/no-unsafe-argument": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"@typescript-eslint/unbound-method": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/prefer-as-const": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extraneous-class": "off",
},
},
{
files: ["**/__tests__/**/*.ts", "**/*.test.ts", "**/*.spec.ts", "tests/**/*.ts"],
languageOptions: {
parser: tsparser,
parserOptions: {
project: "./tsconfig.json",
sourceType: "module",
},
globals: {
console: "readonly",
process: "readonly",
Buffer: "readonly",
NodeJS: "readonly",
URL: "readonly",
setTimeout: "readonly",
setInterval: "readonly",
clearInterval: "readonly",
clearTimeout: "readonly",
fetch: "readonly",
// Jest globals
describe: "readonly",
it: "readonly",
test: "readonly",
expect: "readonly",
beforeEach: "readonly",
afterEach: "readonly",
beforeAll: "readonly",
afterAll: "readonly",
jest: "readonly",
// Node.js globals for test mocking
global: "writable",
require: "readonly",
__dirname: "readonly",
__filename: "readonly",
},
},
plugins: {
"@typescript-eslint": tseslint,
prettier: prettierPlugin,
},
rules: {
"prettier/prettier": "error",
"no-unused-vars": "off", // Disable base rule in favor of @typescript-eslint version
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_" },
],
// Async rules (relaxed for tests)
"@typescript-eslint/no-floating-promises": "off", // Test assertions often don't need to await
"@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/await-thenable": "error",
// Code quality rules (relaxed for tests)
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/prefer-nullish-coalescing": "off", // Semantic difference less critical in tests
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/prefer-as-const": "error",
"@typescript-eslint/unbound-method": "off", // Common in test mocks
// Relaxed rules for tests (mocks and dynamic data often require unsafe operations)
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/no-non-null-assertion": "off", // Tests often use ! for known values
"@typescript-eslint/no-extraneous-class": "off",
},
},
];