瀏覽代碼

feat: 添加 knip 冗余代码检查工具

配置 knip.json 检测未使用的文件、exports、依赖等。
新增 check:unused script,运行 knip-bun 扫描死代码。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
claude-code-best 3 周之前
父節點
當前提交
c587a64320
共有 3 個文件被更改,包括 26 次插入2 次删除
  1. 1 1
      TODO.md
  2. 22 0
      knip.json
  3. 3 1
      package.json

+ 1 - 1
TODO.md

@@ -18,7 +18,7 @@
 ## 工程化能力
 
 - [x] 代码格式化与校验
-- [ ] 冗余代码检查
+- [x] 冗余代码检查
 - [x] git hook 的配置
 - [ ] 代码健康度检查
 - [x] 单元测试基础设施搭建 (test runner 配置)

+ 22 - 0
knip.json

@@ -0,0 +1,22 @@
+{
+	"$schema": "https://unpkg.com/knip@6/schema.json",
+	"entry": ["src/entrypoints/cli.tsx"],
+	"project": ["src/**/*.{ts,tsx}"],
+	"ignore": ["src/types/**", "src/**/*.d.ts"],
+	"ignoreDependencies": [
+		"@ant/*",
+		"react-compiler-runtime",
+		"@anthropic-ai/mcpb",
+		"@anthropic-ai/sandbox-runtime"
+	],
+	"ignoreBinaries": ["bun"],
+	"workspaces": {
+		"packages/*": {
+			"entry": ["src/index.ts"],
+			"project": ["src/**/*.ts"]
+		},
+		"packages/@ant/*": {
+			"ignore": ["**"]
+		}
+	}
+}

+ 3 - 1
package.json

@@ -17,7 +17,8 @@
         "lint:fix": "biome check --fix src/",
         "format": "biome format --write src/",
         "prepare": "git config core.hooksPath .githooks",
-        "test": "bun test"
+        "test": "bun test",
+        "check:unused": "knip-bun"
     },
     "dependencies": {
         "@alcalzone/ansi-tokenize": "^0.3.0",
@@ -132,6 +133,7 @@
         "@types/react-reconciler": "^0.33.0",
         "@types/sharp": "^0.32.0",
         "@types/turndown": "^5.0.6",
+        "knip": "^6.1.1",
         "typescript": "^6.0.2"
     }
 }