// @ts-check // 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', }, }, 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', // 强制四空格缩进 indent: ['error', 4], // 强制分号 semi: ['error', 'always'], // 强制单引号 quotes: ['error', 'single'], // 末尾逗号(多行对象/数组) 'comma-dangle': ['error', 'always-multiline'], // 对象key统一加引号 'quote-props': ['error', 'as-needed'], // 关键字前后空格 'keyword-spacing': ['error', { before: true, after: true }], // 大括号风格 'brace-style': ['error', '1tbs'], // 禁止多余空行 'no-multiple-empty-lines': ['error', { max: 1 }], }, }, { // 忽略目录和文件 ignores: ['node_modules/', 'dist/', 'bun.lockb', '*.config.js', '*.config.ts'], }, ];