7.8 KiB
Anti-Pattern Czar Generalization Analysis
Generated: January 10, 2026
This report analyzes whether the /anti-pattern-czar command and its underlying detector script can be generalized for use in any TypeScript codebase or other programming languages.
Executive Summary
The anti-pattern detection system in claude-mem consists of two components:
/anti-pattern-czar- An interactive workflow command for detecting and fixing error handling anti-patternsdetect-error-handling-antipatterns.ts- The underlying static analysis script
Verdict: The core detection patterns are highly generalizable to any TypeScript/JavaScript codebase. However, the current implementation has claude-mem-specific hardcoding that would need to be extracted into configuration for broader use.
Current Implementation Analysis
Detection Methodology
The script uses purely regex-based detection (no AST parsing) with two phases:
-
Line-by-Line Pattern Matching - Scans for known anti-patterns:
ERROR_STRING_MATCHING- Fragileerror.message.includes('keyword')checksPARTIAL_ERROR_LOGGING- Loggingerror.messageinstead of full error objectERROR_MESSAGE_GUESSING- Multiple.includes()chains for error classificationPROMISE_EMPTY_CATCH-.catch(() => {})handlersPROMISE_CATCH_NO_LOGGING- Promise catches without logging
-
Try-Catch Block Analysis - Brace-depth tracking to identify:
EMPTY_CATCH- Catch blocks with no meaningful codeNO_LOGGING_IN_CATCH- Catch blocks without logging/throwingLARGE_TRY_BLOCK- More than 10 significant lines (uncertain error source)GENERIC_CATCH- Noinstanceofor error type discriminationCATCH_AND_CONTINUE_CRITICAL_PATH- Logging but not failing in critical code
Claude-Mem Specific Elements
| Element | Location | Generalization Required |
|---|---|---|
CRITICAL_PATHS array |
Lines 24-30 | Extract to config file |
| Script path in command | anti-pattern-czar.md | Make path configurable |
| Severity thresholds | Line 10 limit | Make configurable |
| Directory to scan | src/ hardcoded |
Accept as parameter |
| Exclusions | node_modules, dist |
Make configurable |
Comparison with Industry Tools
ESLint Rules Coverage
| Anti-Pattern | ESLint Equivalent | Coverage Gap |
|---|---|---|
| Empty catch blocks | no-empty |
Fully covered |
| Catch-and-rethrow | no-useless-catch |
Fully covered |
| Floating promises | @typescript-eslint/no-floating-promises |
Fully covered |
| Partial error logging | None | Gap |
| Error string matching | None | Gap |
| Error message guessing | None | Gap |
| Large try blocks | sonarjs/cognitive-complexity |
Partial |
| Critical path continuation | None | Gap |
Unique Value Proposition
The claude-mem detector catches patterns that no standard ESLint rule addresses:
- Partial Error Logging - Logging
error.messageloses stack traces - Error String Matching - Fragile
if (error.message.includes('timeout'))patterns - Error Message Guessing - Chained
.includes()for error classification - Critical Path Continuation - Logging but continuing in code that should fail
These patterns represent real debugging nightmares that caused hours of investigation in claude-mem's development.
Generalization Recommendations
Tier 1: Quick Generalization (Configuration)
Extract hardcoded values to a config file:
{
"sourceDir": "src/",
"criticalPaths": ["**/services/*.ts", "**/core/*.ts"],
"excludeDirs": ["node_modules", "dist", "test"],
"largeBlockThreshold": 10,
"overrideComment": "// [ANTI-PATTERN IGNORED]:"
}
Effort: 2-4 hours
Tier 2: ESLint Plugin (Broader Adoption)
Convert patterns to ESLint custom rules for standard toolchain integration:
// eslint-plugin-error-hygiene
module.exports = {
rules: {
'no-partial-error-logging': { /* ... */ },
'no-error-string-matching': { /* ... */ },
'no-error-message-guessing': { /* ... */ },
'critical-path-must-fail': { /* ... */ }
}
}
Advantages:
- Integrates with existing toolchains
- IDE integration via ESLint plugins
- Auto-fix support possible
- Community-standard distribution
Effort: 1-2 weeks
Tier 3: Multi-Language Support
The regex patterns could be adapted for:
- Go -
deferwith empty recover, error checking patterns - Python -
except:without logging, bareexcept Exception: - Rust -
.unwrap()in production paths,_pattern forResult
Effort: 1 week per language
Architecture for General Use
error-pattern-detector/
├── config/
│ ├── default.json # Sensible defaults
│ └── schema.json # Config validation
├── patterns/
│ ├── typescript/ # TS-specific patterns
│ │ ├── empty-catch.ts
│ │ ├── partial-logging.ts
│ │ └── critical-path.ts
│ └── shared/ # Cross-language patterns
│ ├── large-try-block.ts
│ └── swallowed-errors.ts
├── reporters/
│ ├── console.ts # CLI output
│ ├── json.ts # Machine-readable
│ ├── sarif.ts # GitHub/IDE integration
│ └── markdown.ts # Report generation
├── cli.ts # Entry point
└── index.ts # Programmatic API
PR #666 Review Context
The PR review raised a valid concern: the /anti-pattern-czar command references a script (scripts/anti-pattern-test/detect-error-handling-antipatterns.ts) that only exists in the claude-mem development repository.
Options:
- Keep as development tool - Don't distribute with plugin (recommended by reviewer)
- Bundle the detector - Include the script in the plugin distribution
- Extract to standalone package - Publish as
@claude-mem/error-pattern-detectorand depend on it
Option 3 enables both plugin distribution and community adoption.
Conclusions
What's Generalizable
| Component | Generalizability | Notes |
|---|---|---|
| Regex detection patterns | High | Universal to TS/JS |
| Brace-depth tracking | High | Works for any curly-brace language |
| Override comment syntax | High | Adoptable by any project |
| Report formatting | High | Standard markdown output |
| 4-step workflow | High | Applicable to any codebase |
What's Claude-Mem Specific
| Component | Specificity | Extraction Effort |
|---|---|---|
| Critical path file list | High | Configuration file |
| Script location | High | Path parameter |
| Severity philosophy | Medium | Documentation |
| Exit codes | Low | Already standard |
Recommendation
Invest in Tier 2 (ESLint Plugin) - The patterns detected are genuinely unique and valuable. Standard ESLint rules miss these debugging nightmares. An ESLint plugin would:
- Enable adoption in any TS/JS project
- Integrate with existing CI/CD pipelines
- Provide IDE feedback in real-time
- Allow community contributions to pattern library
- Create a marketable open-source project
The name eslint-plugin-error-hygiene captures the philosophy: maintaining clean error handling practices to prevent silent failures.
Next Steps
- Short-term: Extract configuration to enable use in other projects
- Medium-term: Create ESLint plugin with AST-based detection (more robust than regex)
- Long-term: Multi-language support, SARIF output for security tool integration
Report generated by analyzing PR #666 review comments, the anti-pattern-czar.md command, and detect-error-handling-antipatterns.ts implementation.