knip-deadcode
Original:🇺🇸 English
Translated
Knip dead code detection best practices for JavaScript and TypeScript projects. Use when configuring Knip, analyzing unused code, setting up CI integration, or cleaning up codebases. Triggers on knip.json, dead code, unused exports, unused dependencies, bundle optimization.
18installs
Sourcepproenca/dot-skills
Added on
NPX Install
npx skill4agent add pproenca/dot-skills knip-deadcodeTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Community Knip Dead Code Detection Best Practices
Comprehensive guide for detecting and removing dead code in JavaScript and TypeScript projects using Knip. Contains 43 rules across 8 categories, prioritized by impact to guide configuration, CI integration, and cleanup workflows.
When to Apply
Reference these guidelines when:
- Configuring Knip for a new project or monorepo
- Investigating false positives or false negatives
- Setting up CI pipelines to prevent dead code regressions
- Using auto-fix to clean up unused code
- Optimizing Knip performance for large codebases
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Configuration Foundations | CRITICAL | |
| 2 | Entry Point Strategy | CRITICAL | |
| 3 | Workspace & Monorepo | HIGH | |
| 4 | Dependency Analysis | HIGH | |
| 5 | Export Detection | MEDIUM-HIGH | |
| 6 | CI Integration | MEDIUM | |
| 7 | Auto-Fix Workflow | MEDIUM | |
| 8 | Performance Optimization | LOW-MEDIUM | |
Quick Reference
1. Configuration Foundations (CRITICAL)
- - Avoid broad ignore patterns
config-avoid-broad-ignore - - Configure path aliases in Knip
config-configure-path-aliases - - Enable framework plugins explicitly
config-enable-plugins-explicitly - - Run without config first for baseline
config-run-without-config - - Separate entry files from project files
config-separate-entry-project - - Use JSON schema for configuration validation
config-use-json-schema - - Use negation patterns for exclusions
config-use-negation-patterns - - Use production mode for shipping code analysis
config-use-production-mode
2. Entry Point Strategy (CRITICAL)
- - Add dynamic import targets as entry points
entry-add-dynamic-imports - - Exclude test files from production entries
entry-exclude-test-files - - Include all application entry points
entry-include-all-entry-points - - Include binary scripts as entry points
entry-include-bin-scripts - - Use compilers for non-standard file types
entry-use-compilers - - Use plugin entry points for frameworks
entry-use-plugin-entries - - Verify entry points with debug mode
entry-verify-with-debug
3. Workspace & Monorepo (HIGH)
- - Configure root workspace explicitly
workspace-configure-root-workspace - - Ignore specific workspaces when needed
workspace-ignore-specific - - Isolate workspaces for strict dependency checking
workspace-isolate-for-strict - - List cross-workspace dependencies explicitly
workspace-list-cross-deps - - Configure plugins per workspace
workspace-per-workspace-plugins - - Use workspace globs for consistent configuration
workspace-use-workspace-globs
4. Dependency Analysis (HIGH)
- - Add unlisted dependencies to package.json
deps-add-unlisted-deps - - Avoid relying on transitive dependencies
deps-avoid-transitive-reliance - - Configure plugins for tool-specific dependencies
deps-configure-plugin-deps - - Fix unused files before dependencies
deps-fix-files-first - - Ignore conditionally loaded dependencies
deps-ignore-conditional-deps - - Remove obsolete type definition packages
deps-remove-obsolete-types
5. Export Detection (MEDIUM-HIGH)
- - Check class members for unused code
exports-check-class-members - - Enable entry export checking for private packages
exports-enable-entry-exports - - Handle re-exports in barrel files
exports-handle-reexports - - Ignore exports used in same file
exports-ignore-same-file - - Tag public API exports with JSDoc
exports-tag-public-api - - Trace export usage before removal
exports-trace-usage - - Use include libs for type-based consumption
exports-use-include-libs
6. CI Integration (MEDIUM)
- - Add Knip to CI pipeline
ci-add-to-pipeline - - Separate production and default mode checks
ci-separate-production-check - - Enable cache for faster CI runs
ci-use-cache - - Use max issues for gradual adoption
ci-use-max-issues - - Use appropriate reporters for CI output
ci-use-reporters - - Use watch mode for local development
ci-watch-mode-local
7. Auto-Fix Workflow (MEDIUM)
- - Explicitly allow file removal
fix-allow-remove-files - - Format code after auto-fix
fix-format-after-fix - - Review auto-fix changes before commit
fix-review-before-commit - - Update package manager after dependency fix
fix-update-deps-after - - Use fix type for targeted cleanup
fix-use-fix-type
8. Performance Optimization (LOW-MEDIUM)
- - Filter issue types for focused analysis
perf-filter-issue-types - - Limit output for large codebases
perf-limit-output - - Profile performance for slow analysis
perf-profile-performance - - Use Bun runtime for faster analysis
perf-use-bun-runtime - - Enable cache for repeated analysis
perf-use-cache-flag - - Filter workspaces for faster monorepo analysis
perf-use-workspace-filter
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |