knip

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Knip

Knip

Finds unused files, dependencies, and exports in TypeScript/JavaScript projects.
查找TypeScript/JavaScript项目中未使用的文件、依赖项和导出内容。

Usage

使用方法

bash
bunx knip                     # Analyze project
bunx knip --production        # Production only (no tests, devDeps)
bunx knip --strict            # Direct dependencies only
bunx knip --fix               # Auto-remove unused (use cautiously)
bunx knip --include files     # Only unused files
bunx knip --include exports   # Only unused exports
bunx knip --include dependencies  # Only unused deps
bash
bunx knip                     # 分析项目
bunx knip --production        # 仅分析生产环境(不包含测试代码、开发依赖)
bunx knip --strict            # 仅检查直接依赖
bunx knip --fix               # 自动移除未使用内容(谨慎使用)
bunx knip --include files     # 仅检查未使用文件
bunx knip --include exports   # 仅检查未使用导出内容
bunx knip --include dependencies  # 仅检查未使用依赖项

Output Formats

输出格式

bash
bunx knip --reporter compact  # Compact output
bunx knip --reporter json     # JSON for tooling
bunx knip --reporter github-actions  # CI annotations
bash
bunx knip --reporter compact  # 紧凑格式输出
bunx knip --reporter json     # 输出JSON格式(供工具调用)
bunx knip --reporter github-actions  # GitHub Actions CI注解格式

Filtering

过滤设置

bash
bunx knip --workspace packages/client  # Specific workspace
bunx knip --exclude "test/**/*"        # Exclude patterns
bash
bunx knip --workspace packages/client  # 指定工作区(packages/client)
bunx knip --exclude "test/**/*"        # 排除指定模式的文件

Debugging

调试

bash
bunx knip --debug                      # Debug output
bunx knip --trace-file src/utils.ts    # Trace file
bunx knip --trace-export myFunction    # Trace export
bash
bunx knip --debug                      # 输出调试信息
bunx knip --trace-file src/utils.ts    # 追踪指定文件(src/utils.ts)
bunx knip --trace-export myFunction    # 追踪指定导出内容(myFunction)

Configuration

配置

Configure via
.knip.json
or
knip.config.js
for custom entry points and exclusions.
可通过
.knip.json
knip.config.js
自定义入口文件和排除规则。

Related Skills

相关技能

  • maintenance: Refactoring and technical debt management
  • jscpd: Find duplicate code blocks
  • bun: Package management for JS/TS projects
  • maintenance: 重构与技术债务管理
  • jscpd: 查找重复代码块
  • bun: JS/TS项目的包管理工具