Git workflow, code quality, context management and testing commands: - commit, push, pr, issue - git operations - simplify, refactor, verify, check - code quality - catchup, onboard, save, cleanup - context management - test, format, sync - development utilities Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
135 lines
2.8 KiB
Markdown
135 lines
2.8 KiB
Markdown
---
|
|
description: Remove unused code, imports, and dead code
|
|
argument-hint: [path] - Optional path to cleanup (defaults to recent changes)
|
|
---
|
|
|
|
# Code Cleanup
|
|
|
|
## Pre-computed Context
|
|
|
|
**Recently Modified Files:**
|
|
!`git diff --name-only HEAD~5 2>/dev/null | grep -E '\.(ts|tsx|js|jsx|py)$' | head -15`
|
|
|
|
**TypeScript Config:**
|
|
!`cat tsconfig.json 2>/dev/null | grep -E '"(noUnused|strict)"' | head -5 || echo "No tsconfig.json"`
|
|
|
|
**ESLint Unused Rules:**
|
|
!`cat .eslintrc* eslint.config.* 2>/dev/null | grep -i unused | head -3 || echo "No ESLint config"`
|
|
|
|
---
|
|
|
|
## Instructions
|
|
|
|
You are cleaning up unused code from the codebase.
|
|
|
|
### What to Remove
|
|
|
|
#### 1. Unused Imports
|
|
```typescript
|
|
// Remove these
|
|
import { unusedFunction } from './utils'; // never used
|
|
import * as _ from 'lodash'; // never used
|
|
```
|
|
|
|
**Detection:**
|
|
```bash
|
|
# TypeScript/ESLint
|
|
npx eslint --rule 'no-unused-vars: error' --rule '@typescript-eslint/no-unused-vars: error' .
|
|
|
|
# Or use ts-prune for exports
|
|
npx ts-prune 2>/dev/null
|
|
```
|
|
|
|
#### 2. Unused Variables
|
|
```typescript
|
|
// Remove
|
|
const unusedConfig = { ... }; // declared but never read
|
|
function helper(used, unused) { return used; } // unused parameter
|
|
```
|
|
|
|
#### 3. Dead Code
|
|
```typescript
|
|
// Remove unreachable code
|
|
function process() {
|
|
return result;
|
|
console.log('never runs'); // dead code
|
|
}
|
|
|
|
// Remove commented-out code
|
|
// function oldImplementation() { ... } // delete, use git history
|
|
```
|
|
|
|
#### 4. Unused Exports
|
|
```typescript
|
|
// If not imported anywhere, consider removing
|
|
export function neverImported() { ... }
|
|
```
|
|
|
|
Use `ts-prune` to find unused exports:
|
|
```bash
|
|
npx ts-prune 2>/dev/null | head -20
|
|
```
|
|
|
|
### Automated Tools
|
|
|
|
#### ESLint Auto-fix
|
|
```bash
|
|
npx eslint --fix --rule 'no-unused-vars: error' .
|
|
```
|
|
|
|
#### TypeScript Strict Mode
|
|
Enable in tsconfig.json:
|
|
```json
|
|
{
|
|
"compilerOptions": {
|
|
"noUnusedLocals": true,
|
|
"noUnusedParameters": true
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Python
|
|
```bash
|
|
# Find unused imports
|
|
autoflake --remove-all-unused-imports --in-place -r . 2>/dev/null
|
|
|
|
# Or with ruff
|
|
ruff check --select F401 --fix . 2>/dev/null
|
|
```
|
|
|
|
### Manual Review
|
|
|
|
For each file in the target path:
|
|
|
|
1. Read the file
|
|
2. Identify unused:
|
|
- Imports at the top
|
|
- Variables declared but not used
|
|
- Functions defined but not called
|
|
- Commented-out code blocks
|
|
3. Remove with Edit tool
|
|
4. Verify no errors introduced
|
|
|
|
### Safety Rules
|
|
|
|
1. **Don't remove exports** that might be used externally (public APIs)
|
|
2. **Check for side effects** - some imports run code on load
|
|
3. **Preserve intentional unused** - parameters with `_` prefix
|
|
4. **Run tests after cleanup** to verify nothing broke
|
|
|
|
### Report
|
|
|
|
```
|
|
## Cleanup Report
|
|
|
|
### Removed
|
|
- 15 unused imports
|
|
- 3 unused variables
|
|
- 2 dead code blocks
|
|
- 45 lines of commented code
|
|
|
|
### Files Cleaned
|
|
- src/utils.ts: -12 lines
|
|
- src/api/client.ts: -8 lines
|
|
```
|