Loading...
Loading...
Dead Code Cleanup and Consolidation Expert. Used to remove unused code, duplicate code, and refactor. Execute analysis tools (knip, depcheck, ts-prune) to identify and safely remove dead code.
npx skill4agent add seikaikyo/dash-skills refactor-cleaner# knip - Find unused files, exports, dependencies
npx knip
# depcheck - Identify unused npm dependencies
npx depcheck
# ts-prune - Find unused TypeScript exports
npx ts-prune
# eslint - Check for unused variables
npx eslint . --report-unused-disable-directivesa) Run detection tools in parallel
b) Collect all findings
c) Classify by risk:
- Safe: Unused exports, dependencies
- Caution: May be used via dynamic imports
- High Risk: Public APIs, shared utilitiesa) Start with only "Safe" items
b) Remove one category at a time:
1. Unused npm dependencies
2. Unused internal exports
3. Unused files
4. Duplicate code
c) Run tests after each batch
d) Create a git commit for each batcha) Identify duplicate components/utilities
b) Select the best implementation:
- Most feature-complete
- Best tested
- Most recently used
c) Update all imports to use the selected version
d) Delete duplicates
e) Verify tests still passdocs/DELETION_LOG.md# Code Deletion Log
## [YYYY-MM-DD] Refactoring Operation
### Removed Dependencies
- package-name@version - Last used: Never, Size: XX KB
- another-package@version - Replaced by: better-package
### Deleted Files
- src/old-component.tsx - Replaced with: src/new-component.tsx
- lib/deprecated-util.ts - Functionality moved to: lib/utils.ts
### Consolidated Duplicate Code
- src/components/Button1.tsx + Button2.tsx -> Button.tsx
- Reason: Identical implementations
### Removed Exports
- src/utils/helpers.ts - Functions: foo(), bar()
- Reason: No references in codebase
### Impact
- Files deleted: 15
- Dependencies removed: 5
- Lines of code removed: 2,300
- Package size reduced: ~45 KB
### Testing
- All unit tests passed
- All integration tests passed
- Manual testing completed// Remove unused imports
import { useState, useEffect, useMemo } from 'react' // Only useState is used
// Keep only used imports
import { useState } from 'react'// Remove unreachable code
if (false) {
// Will never execute
doSomething()
}
// Remove unused functions
export function unusedHelper() {
// No references in codebase
}// Multiple similar components
components/Button.tsx
components/PrimaryButton.tsx
components/NewButton.tsx
// Consolidate into one
components/Button.tsx (using variant prop)// Installed but never imported packages
{
"dependencies": {
"lodash": "^4.17.21", // Never used
"moment": "^2.29.4" // Replaced by date-fns
}
}# 1. Roll back immediately
git revert HEAD
npm install
npm run build
npm test
# 2. Investigate the cause
# - What failed?
# - Was it a dynamic import?
# - Did the detection tool miss something?
# 3. Fix forward
# - Mark as "Do Not Remove"
# - Document why detection tool missed it
# - Add explicit type annotations## Refactoring: Code Cleanup
### Summary
Dead code cleanup, removing unused exports, dependencies, and duplicates.
### Changes
- Removed X unused files
- Removed Y unused dependencies
- Consolidated Z duplicate components
- See docs/DELETION_LOG.md for details
### Testing
- [x] Build passes
- [x] All tests pass
- [x] Manual testing completed
- [x] No console errors
### Impact
- Package size: -XX KB
- Lines of code: -XXXX
- Dependencies: -X packages
### Risk Level
Low - Only verified unused code was removed
See DELETION_LOG.md for details.