import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import tseslint from "typescript-eslint";

const tsconfigRootDir = dirname(fileURLToPath(import.meta.url));

export default tseslint.config(
  {
    ignores: [
      "node_modules/**",
      "dist/**",
      "**/dist/**",
      ".publish/**",
      "**/.wrnexus/**",
      "**/.wrnexus-*/**",
      "coverage/**",
      "bun.lock",
      "bun.lockb",
      "**/*.gen.ts",
      "editors/vscode/src/compiler.cjs",
      "editors/vscode/src/language-server.cjs",
      "editors/vscode/src/extension.bundle.cjs",
      "focus-shims.d.ts",
      "**/focus-shims.d.ts",
      "tsconfig.focus.json",
      "**/tsconfig.focus.json",
    ],
  },
  {
    languageOptions: {
      parserOptions: {
        tsconfigRootDir,
      },
    },
  },
  js.configs.recommended,
  ...tseslint.configs.recommended,
  {
    // The VS Code extension is plain CommonJS/ESM running on Node, not framework TS.
    files: ["editors/vscode/**/*.{js,mjs}"],
    rules: {
      "no-undef": "off",
      "no-console": "off",
      "@typescript-eslint/no-require-imports": "off",
      "@typescript-eslint/no-unused-expressions": "off",
    },
  },
  {
    files: ["**/*.{ts,tsx}"],
    rules: {
      "no-undef": "off",
      "no-console": "off",
      "@typescript-eslint/no-explicit-any": "off",
      "@typescript-eslint/no-unused-vars": [
        "warn",
        {
          argsIgnorePattern: "^_",
          varsIgnorePattern: "^_",
          caughtErrorsIgnorePattern: "^_",
        },
      ],
    },
  },
);
