// ESLint flat config for JavaScript/TypeScript/Vue
// Rules: https://eslint.org/docs/latest/rules
// Languages: JavaScript & TypeScript & Vue
//
// 前置条件:npm install
// 运行命令:npm run lint
//
// 不使用任何 recommended 预设,只启用显式定义的规则。

import tseslint from "typescript-eslint";
import pluginVue from "eslint-plugin-vue";

export default [
  // 全局忽略配置:不检查构建产物、依赖、配置文件等
  {
    ignores: [
      "**/dist/**", // 所有 dist 目录
      "**/build/**", // 所有 build 目录
      "**/target/**", // 所有 target 目录
      "**/node_modules/**", // 所有 node_modules 目录
      "**/*.min.js", // 所有压缩文件
      "**/*.lock", // 所有锁文件
      "package-lock.json", // 根目录锁文件
      ".git/**", // Git 目录
      "threat-model-*/**", // 威胁模型报告
    ],
  },
  // JS 规则:只启用显式声明的规则(不使用 js.configs.recommended)
  {
    rules: {
      "no-eval": "warn", // no-eval
      "no-implied-eval": "warn", // no-implied-eval
      "no-alert": "warn", // no-alert
      "no-debugger": "warn", // no-debugger
      "default-case": "warn", // default-case
      "no-fallthrough": "warn", // no-fallthrough
      "no-case-declarations": "warn", // no-case-declarations
      "no-cond-assign": "warn", // no-cond-assign
      "no-var": "warn", // no-var
      "no-multi-assign": "warn", // no-multi-assign
      "no-undef-init": "warn", // no-undef-init
      "no-array-constructor": "warn", // no-array-constructor
      "no-unsafe-finally": "warn", // no-unsafe-finally
      eqeqeq: "warn", // eqeqeq
      "no-nested-ternary": "warn", // no-nested-ternary
      "no-new-func": "warn", // no-new-func
      "prefer-rest-params": "warn", // prefer-rest-params
      "prefer-arrow-callback": "warn", // prefer-arrow-callback
      "no-prototype-builtins": "warn", // no-prototype-builtins
      "guard-for-in": "warn", // guard-for-in
      "no-extend-native": "warn", // no-extend-native
      "use-isnan": "warn", // use-isnan
      "no-implicit-coercion": "warn", // no-implicit-coercion
      "no-with": "warn", // no-with
    },
  },
  // TS 规则:配置 TypeScript 解析器和插件,只启用显式声明的 TS 规则
  {
    files: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
    languageOptions: {
      parser: tseslint.parser,
      parserOptions: {
        projectService: {
          allowDefaultProject: ["*.ts", "*.tsx", "*.mts", "*.cts", "*.vue"],
        },
      },
    },
    plugins: {
      "@typescript-eslint": tseslint.plugin,
    },
    rules: {
      "@typescript-eslint/no-implied-eval": "warn", // no-implied-eval
      "@typescript-eslint/prefer-return-this-type": "warn", // prefer-return-this-type
      "@typescript-eslint/ban-ts-comment": "warn", // ban-ts-comment
      "@typescript-eslint/no-array-constructor": "warn", // no-array-constructor
      "@typescript-eslint/prefer-enum-initializers": "warn", // prefer-enum-initializers
      "@typescript-eslint/prefer-literal-enum-member": "warn", // prefer-literal-enum-member
    },
  },
  // Vue 文件:只配置解析器(使用 flat/base,不启用 Vue 推荐规则)
  ...pluginVue.configs["flat/base"],
  {
    // Vue 文件中使用 TypeScript 解析器解析 <script lang="ts"> 块
    files: ["**/*.vue"],
    languageOptions: {
      parserOptions: {
        parser: tseslint.parser,
      },
    },
  },
];