feat(logging): enable ESLint no-console rule with client exemptions
全局启用 no-console: error 规则,强制服务端 .ts 文件使用 createModuleLogger。豁免场景: scripts/(脚本)、tests/(测试)、src/**/*.tsx(客户端组件,留待 Task 12-14 处理)、src/**/hooks/**/*.ts(客户端 hooks)、src/**/components/**/*.ts(客户端 utils)、src/shared/lib/query-client.ts(被客户端导入)。将 deletes/ 归档目录加入 globalIgnores。
This commit is contained in:
@@ -30,6 +30,9 @@ const eslintConfig = defineConfig([
|
|||||||
"禁止硬编码 hex 颜色,使用设计令牌 hsl(var(--*)) 或 Tailwind 类 bg-*",
|
"禁止硬编码 hex 颜色,使用设计令牌 hsl(var(--*)) 或 Tailwind 类 bg-*",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
// 禁止 console.* 调用,统一使用 createModuleLogger("module-name")
|
||||||
|
// 豁免场景:scripts/、tests/、客户端 .tsx(留待客户端错误上报机制处理)、被客户端导入的 .ts
|
||||||
|
"no-console": "error",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -89,6 +92,43 @@ const eslintConfig = defineConfig([
|
|||||||
"no-restricted-syntax": "off",
|
"no-restricted-syntax": "off",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// 豁免:scripts/ 和 tests/ 允许 console(脚本/测试场景不接入 logger)
|
||||||
|
{
|
||||||
|
files: ["scripts/**/*.{js,mjs,ts}", "tests/**/*.{ts,tsx,js}"],
|
||||||
|
rules: {
|
||||||
|
"no-console": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 暂时豁免:客户端 .tsx 文件中的 console 调用,留待客户端错误上报机制(Task 12-14)处理
|
||||||
|
// 客户端组件不能导入服务端 pino logger,需通过 useErrorReport Hook 上报
|
||||||
|
{
|
||||||
|
files: ["src/**/*.tsx"],
|
||||||
|
rules: {
|
||||||
|
"no-console": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 豁免:客户端 hooks(.ts)被客户端组件导入,不能使用服务端 logger
|
||||||
|
// 留待 Task 12-14 客户端错误上报机制处理
|
||||||
|
{
|
||||||
|
files: ["src/**/hooks/**/*.ts"],
|
||||||
|
rules: {
|
||||||
|
"no-console": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 豁免:components 目录中的 .ts utils(如 exam-preview-utils.ts)被客户端 hooks 导入
|
||||||
|
{
|
||||||
|
files: ["src/**/components/**/*.ts"],
|
||||||
|
rules: {
|
||||||
|
"no-console": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 豁免:被客户端组件导入的 .ts 文件不能使用服务端 logger(如 query-client.ts 被 providers.tsx 导入)
|
||||||
|
{
|
||||||
|
files: ["src/shared/lib/query-client.ts"],
|
||||||
|
rules: {
|
||||||
|
"no-console": "off",
|
||||||
|
},
|
||||||
|
},
|
||||||
// Override default ignores of eslint-config-next.
|
// Override default ignores of eslint-config-next.
|
||||||
globalIgnores([
|
globalIgnores([
|
||||||
// Default ignores of eslint-config-next:
|
// Default ignores of eslint-config-next:
|
||||||
@@ -103,6 +143,8 @@ const eslintConfig = defineConfig([
|
|||||||
"tests/webapp/debug_drizzle.js",
|
"tests/webapp/debug_drizzle.js",
|
||||||
// Migration/maintenance scripts using CommonJS require()
|
// Migration/maintenance scripts using CommonJS require()
|
||||||
"scripts/**/*.js",
|
"scripts/**/*.js",
|
||||||
|
// 已删除文件的归档目录,不参与 lint
|
||||||
|
"deletes/**",
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user