Dead Code Auditor (L3 Worker)
Specialized worker auditing unused and unreachable code.
Purpose & Scope
- Worker in ln-620 coordinator pipeline
- Audit dead code (Category 9: Low Priority)
- Find unused imports, variables, functions, commented-out code
- Calculate compliance score (X/10)
Inputs (from Coordinator)
Receives contextStore with tech stack, codebase root.
Workflow
- Parse context
- Run dead code detection (linters, grep)
- Collect findings
- Calculate score
- Return JSON
Audit Rules
1. Unreachable Code
Detection:
- Linter rules:
no-unreachable (ESLint)
- Check code after
return, throw, break
Severity: MEDIUM
2. Unused Imports/Variables/Functions
Detection:
- ESLint:
no-unused-vars
- TypeScript:
noUnusedLocals, noUnusedParameters
- Python:
flake8 with F401, F841
Severity:
- MEDIUM: Unused functions (dead weight)
- LOW: Unused imports (cleanup needed)
3. Commented-Out Code
Detection:
- Grep for
//.*{ or /*.*function patterns
- Large comment blocks (>10 lines) with code syntax
Severity: LOW
Recommendation: Delete (git preserves history)
4. Legacy Code & Backward Compatibility
What: Backward compatibility shims, deprecated patterns, old code that should be removed
Detection:
- Renamed variables/functions with old aliases:
- Pattern:
const oldName = newName or export { newModule as oldModule }
- Pattern:
function oldFunc() { return newFunc(); } (wrapper for backward compatibility)
- Deprecated exports/re-exports:
- Grep for
// DEPRECATED, @deprecated JSDoc tags
- Pattern:
export.*as.*old.* or export.*legacy.*
- Conditional code for old versions:
- Pattern:
if.*legacy.* or if.*old.*version.* or isOldVersion ? oldFunc() : newFunc()
- Migration shims and adapters:
- Pattern:
migrate.*, Legacy.*Adapter, .*Shim, .*Compat
- Comment markers:
- Grep for
// backward compatibility, // legacy support, // TODO: remove in v
- Grep for
// old implementation, // deprecated, // kept for backward
Severity:
- HIGH: Backward compatibility shims in critical paths (auth, payment, core features)
- MEDIUM: Deprecated exports still in use, migration code from >6 months ago
- LOW: Recent migration code (<3 months), planned deprecation with clear removal timeline
Recommendation:
- Remove backward compatibility shims - breaking changes are acceptable when properly versioned
- Delete old implementations - keep only the correct/new version
- Remove deprecated exports - update consumers to use new API
- Delete migration code after grace period (3-6 months)
- Clean legacy support comments - git history preserves old implementations
Effort:
- S: Remove simple aliases, delete deprecated exports
- M: Refactor code using old APIs to new APIs
- L: Remove complex backward compatibility layer affecting multiple modules
Scoring Algorithm
penalty = (high * 1.0) + (medium * 0.5) + (low * 0.2)
score = max(0, 10 - penalty)
Output Format
{
"category": "Dead Code",
"score": 6,
"total_issues": 12,
"high": 2,
"medium": 3,
"low": 7,
"findings": [
{
"severity": "MEDIUM",
"location": "src/utils/helpers.ts:45",
"issue": "Function 'formatDate' is never used",
"principle": "Code Maintainability / Clean Code",
"recommendation": "Remove unused function or export if needed elsewhere",
"effort": "S"
},
{
"severity": "HIGH",
"location": "src/api/v1/auth.ts:12-15",
"issue": "Backward compatibility shim for old password validation (6+ months old)",
"principle": "No Legacy Code / Clean Architecture",
"recommendation": "Remove old password validation, keep only new implementation. Update API version if breaking.",
"effort": "M"
}
]
}
Version: 3.0.0
Last Updated: 2025-12-23
1---2name: ln-626-dead-code-auditor3description: Dead code & legacy audit worker (L3). Checks unreachable code, unused imports/variables/functions, commented-out code, backward compatibility shims, deprecated patterns. Returns findings.4---5
6# Dead Code Auditor (L3 Worker)
7
8Specialized worker auditing unused and unreachable code.
9
10## Purpose & Scope
11
12- **Worker in ln-620 coordinator pipeline**
13- Audit **dead code** (Category 9: Low Priority)
14- Find unused imports, variables, functions, commented-out code
15- Calculate compliance score (X/10)
16
17## Inputs (from Coordinator)
18
19Receives `contextStore` with tech stack, codebase root.
20
21## Workflow
22
231) Parse context
242) Run dead code detection (linters, grep)
253) Collect findings
264) Calculate score
275) Return JSON
28
29## Audit Rules
30
31### 1. Unreachable Code
32**Detection:**
33- Linter rules: `no-unreachable` (ESLint)
34- Check code after `return`, `throw`, `break`
35
36**Severity:** MEDIUM
37
38### 2. Unused Imports/Variables/Functions
39**Detection:**
40- ESLint: `no-unused-vars`
41- TypeScript: `noUnusedLocals`, `noUnusedParameters`
42- Python: `flake8` with `F401`, `F841`
43
44**Severity:**
45- **MEDIUM:** Unused functions (dead weight)
46- **LOW:** Unused imports (cleanup needed)
47
48### 3. Commented-Out Code
49**Detection:**
50- Grep for `//.*{` or `/*.*function` patterns
51- Large comment blocks (>10 lines) with code syntax
52
53**Severity:** LOW
54
55**Recommendation:** Delete (git preserves history)
56
57### 4. Legacy Code & Backward Compatibility
58**What:** Backward compatibility shims, deprecated patterns, old code that should be removed
59
60**Detection:**
61- Renamed variables/functions with old aliases:
62 - Pattern: `const oldName = newName` or `export { newModule as oldModule }`
63 - Pattern: `function oldFunc() { return newFunc(); }` (wrapper for backward compatibility)
64- Deprecated exports/re-exports:
65 - Grep for `// DEPRECATED`, `@deprecated` JSDoc tags
66 - Pattern: `export.*as.*old.*` or `export.*legacy.*`
67- Conditional code for old versions:
68 - Pattern: `if.*legacy.*` or `if.*old.*version.*` or `isOldVersion ? oldFunc() : newFunc()`
69- Migration shims and adapters:
70 - Pattern: `migrate.*`, `Legacy.*Adapter`, `.*Shim`, `.*Compat`
71- Comment markers:
72 - Grep for `// backward compatibility`, `// legacy support`, `// TODO: remove in v`
73 - Grep for `// old implementation`, `// deprecated`, `// kept for backward`
74
75**Severity:**
76- **HIGH:** Backward compatibility shims in critical paths (auth, payment, core features)
77- **MEDIUM:** Deprecated exports still in use, migration code from >6 months ago
78- **LOW:** Recent migration code (<3 months), planned deprecation with clear removal timeline
79
80**Recommendation:**
81- Remove backward compatibility shims - breaking changes are acceptable when properly versioned
82- Delete old implementations - keep only the correct/new version
83- Remove deprecated exports - update consumers to use new API
84- Delete migration code after grace period (3-6 months)
85- Clean legacy support comments - git history preserves old implementations
86
87**Effort:**
88- **S:** Remove simple aliases, delete deprecated exports
89- **M:** Refactor code using old APIs to new APIs
90- **L:** Remove complex backward compatibility layer affecting multiple modules
91
92## Scoring Algorithm
93
94```
95penalty = (high * 1.0) + (medium * 0.5) + (low * 0.2)
96score = max(0, 10 - penalty)
97```
98
99## Output Format
100
101```json
102{
103 "category": "Dead Code",
104 "score": 6,
105 "total_issues": 12,
106 "high": 2,
107 "medium": 3,
108 "low": 7,
109 "findings": [
110 {
111 "severity": "MEDIUM",
112 "location": "src/utils/helpers.ts:45",
113 "issue": "Function 'formatDate' is never used",
114 "principle": "Code Maintainability / Clean Code",
115 "recommendation": "Remove unused function or export if needed elsewhere",
116 "effort": "S"
117 },
118 {
119 "severity": "HIGH",
120 "location": "src/api/v1/auth.ts:12-15",
121 "issue": "Backward compatibility shim for old password validation (6+ months old)",
122 "principle": "No Legacy Code / Clean Architecture",
123 "recommendation": "Remove old password validation, keep only new implementation. Update API version if breaking.",
124 "effort": "M"
125 }
126 ]
127}
128```
129
130---
131**Version:** 3.0.0
132**Last Updated:** 2025-12-23