- 新增 pino/pino-pretty/pino-roll 依赖,实现结构化日志(console pretty + file JSONL rolling) - 新增 Logger 接口及 PinoLoggerWrapper/ConsoleFallbackLogger/NoopLogger/MemoryLogger 实现 - 新增 src/pino-roll.d.ts 类型声明 - 新增 server.storage.dataDir 配置(默认 ./data,相对路径基于配置文件目录) - 新增 server.logging 配置(level/console/file/rotation,支持变量引用) - 配置文件从可选改为必填,parseRuntimeArgs 无参数时抛错 - bootstrap 创建 logger、确保 dataDir、shutdown flush、失败路径 fallback - startServer 接收 logger 并输出结构化监听日志 - ESLint 新增 no-restricted-syntax 禁止 src/server 直接 console.*(排除 logger.ts) - 更新 config.example.yaml、README.md、DEVELOPMENT.md 同步配置和日志文档 - 完善测试覆盖:logger、config、schema、bootstrap 共 150 个测试通过
111 lines
3.2 KiB
JavaScript
111 lines
3.2 KiB
JavaScript
import js from "@eslint/js";
|
|
import importPlugin from "eslint-plugin-import";
|
|
import perfectionist from "eslint-plugin-perfectionist";
|
|
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
|
|
import reactHooks from "eslint-plugin-react-hooks";
|
|
import reactRefresh from "eslint-plugin-react-refresh";
|
|
import tseslint from "typescript-eslint";
|
|
|
|
const noDirectConsoleMessage =
|
|
"后端运行时代码禁止直接使用 console.*;请通过注入的 Logger 实例输出日志,配置加载失败前使用 createConsoleFallback()。";
|
|
|
|
export default tseslint.config(
|
|
{
|
|
ignores: [
|
|
"node_modules/**",
|
|
"dist/**",
|
|
".build/**",
|
|
"*.bun-build",
|
|
"openspec/**",
|
|
".opencode/**",
|
|
".claude/**",
|
|
".codex/**",
|
|
".agents/**",
|
|
"bun.lock",
|
|
"data/**",
|
|
],
|
|
},
|
|
js.configs.recommended,
|
|
...tseslint.configs.recommendedTypeChecked,
|
|
...tseslint.configs.stylisticTypeChecked,
|
|
importPlugin.flatConfigs.recommended,
|
|
importPlugin.flatConfigs.typescript,
|
|
perfectionist.configs["recommended-natural"],
|
|
{
|
|
languageOptions: {
|
|
parserOptions: {
|
|
projectService: true,
|
|
tsconfigRootDir: import.meta.dirname,
|
|
},
|
|
},
|
|
settings: {
|
|
"import/resolver": { node: true, typescript: true },
|
|
},
|
|
},
|
|
{
|
|
rules: {
|
|
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
|
|
"@typescript-eslint/consistent-type-assertions": ["error", { assertionStyle: "as" }],
|
|
"@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports" }],
|
|
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
|
|
"@typescript-eslint/only-throw-error": "error",
|
|
"@typescript-eslint/prefer-nullish-coalescing": "error",
|
|
"@typescript-eslint/prefer-optional-chain": "error",
|
|
"import/no-unresolved": ["error", { ignore: ["^bun:"] }],
|
|
"no-undef": "off",
|
|
},
|
|
},
|
|
{
|
|
files: ["eslint.config.js"],
|
|
rules: {
|
|
"import/no-named-as-default": "off",
|
|
"import/no-named-as-default-member": "off",
|
|
},
|
|
},
|
|
{
|
|
files: ["src/server/**/*.ts"],
|
|
ignores: ["src/server/logger.ts"],
|
|
rules: {
|
|
"no-restricted-syntax": [
|
|
"error",
|
|
{
|
|
message: noDirectConsoleMessage,
|
|
selector: "MemberExpression[object.name='console']",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
{
|
|
files: ["src/web/**/*.{ts,tsx}"],
|
|
plugins: {
|
|
"react-hooks": reactHooks,
|
|
"react-refresh": reactRefresh,
|
|
},
|
|
rules: {
|
|
...reactHooks.configs.recommended.rules,
|
|
"no-restricted-imports": [
|
|
"error",
|
|
{
|
|
patterns: [
|
|
{
|
|
group: [
|
|
"../server/*",
|
|
"../server/**",
|
|
"../**/server/*",
|
|
"../**/server/**",
|
|
"../../server/*",
|
|
"../../server/**",
|
|
"src/server/*",
|
|
"src/server/**",
|
|
],
|
|
message: "前端不得导入 src/server 后端运行时实现;请改用 src/shared 类型或 HTTP API。",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
|
|
},
|
|
},
|
|
eslintPluginPrettierRecommended,
|
|
);
|