// @ts-nocheck // ESLint 9.x Flat Config for Elysia + TypeScript 项目 // 详细注释,含风格规范(四空格缩进、分号、单引号等) import js from '@eslint/js'; import tseslint from '@typescript-eslint/eslint-plugin'; import tsparser from '@typescript-eslint/parser'; /** * @type {import("eslint").Linter.FlatConfig[]} * FlatConfig 方式配置,兼容ESLint 9.x及TypeScript */ export default [ // 基础JS推荐规则 js.configs.recommended, { // 仅检查src和tests目录下的ts文件 files: ['src/**/*.ts', 'tests/**/*.ts', '*.ts'], languageOptions: { // TypeScript解析器 parser: tsparser, parserOptions: { sourceType: 'module', // ES模块 ecmaVersion: 'latest', // 最新ECMAScript }, // 全局变量声明,避免no-undef globals: { Request: 'readonly', console: 'readonly', process: 'readonly', Bun: 'readonly', Response: 'readonly', Blob: 'readonly', File: 'readonly', TextEncoder: 'readonly', }, }, plugins: { // TypeScript插件 '@typescript-eslint': tseslint, }, rules: { // 关闭原生no-unused-vars,使用TS版本 'no-unused-vars': 'off', '@typescript-eslint/no-unused-vars': 'warn', // 关闭强制函数返回类型 '@typescript-eslint/explicit-function-return-type': 'off', // 允许any '@typescript-eslint/no-explicit-any': 'off', // 允许ts-ignore等注释 '@typescript-eslint/ban-ts-comment': 'off', // ===== 禁用与Prettier冲突的格式化规则 ===== indent: 'off', // 让Prettier处理缩进 'max-len': 'off', // 让Prettier处理行长度 'comma-spacing': 'off', // 让Prettier处理逗号空格 'object-curly-spacing': 'off', // 让Prettier处理对象空格 'array-bracket-spacing': 'off', // 让Prettier处理数组空格 // ===== 与Prettier兼容的规则 ===== // 强制分号(与Prettier一致) semi: ['error', 'always'], // 强制单引号(与Prettier一致) quotes: ['error', 'single'], // 末尾逗号(与Prettier一致) 'comma-dangle': ['error', 'always-multiline'], // 对象key统一加引号(与Prettier一致) 'quote-props': ['error', 'as-needed'], // ===== 其他代码质量规则 ===== // 关键字前后空格 'keyword-spacing': ['error', { before: true, after: true }], // 禁止多余空行 'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }], }, }, { // 忽略目录和文件 ignores: ['node_modules/', 'dist/', 'bun.lockb', '*.config.js', '*.config.ts'], }, ];