find_pattern_usage – Pattern Usage Analysis
Search for specific patterns across multiple files with intelligent context analysis and security-focused detection
Use houtini-lm to search for code patterns, anti-patterns, or specific constructs across your entire project with contextual analysis.
Perfect For
Technical Debt Discovery
Systematically find TODO comments, FIXME markers, and temporary code that needs attention before production deployment.
Security Vulnerability Detection
Locate potentially dangerous patterns like eval() usage, innerHTML assignments, and unsafe API calls across your codebase.
Migration Planning
Identify deprecated API usage, legacy pattern usage, and code that needs updating for framework migrations.
Code Standards Enforcement
Find inconsistent coding patterns, style violations, and opportunities for standardisation across team projects.
Debugging and Investigation
Locate specific error patterns, logging statements, or debug code that may have been left in production builds.
Quick Start
houtini-lm:find_pattern_usage with:
- patterns: ["TODO", "FIXME", "HACK"]
- projectPath: "C:/my-project/src"
- includeContext: 3
Security pattern analysis:
houtini-lm:find_pattern_usage with:
- patterns: ["eval\\(", "innerHTML", "dangerouslySetInnerHTML"]
- projectPath: "C:/web-app/src"
- analysisType: "security"
Analysis Output
Pattern Matches
- File Locations: Exact file paths and line numbers for every pattern match
- Contextual Code: Surrounding code lines to understand usage context and intent
- Pattern Classification: Automatic categorisation by severity, type, and urgency
Usage Statistics
- Pattern Frequency: Total occurrences and distribution across files
- Hotspot Identification: Files with highest concentration of problematic patterns
- Trend Analysis: Pattern density and potential accumulation over time
Remediation Guidance
- Priority Ranking: Risk-based prioritisation for addressing each pattern type
- Specific Recommendations: Targeted advice for replacing or fixing problematic patterns
- Automation Opportunities: Patterns suitable for automated refactoring tools
Analysis Example
Security Pattern Search
// Pattern: eval() usage detection
houtini-lm:find_pattern_usage with:
- patterns: ["eval\\("]
- projectPath: "C:/web-app"
- includeContext: 5
Results Found
- File: src/utils/calculator.js:23
- Context:
function evaluateExpression(expr) {
// TODO: Replace with safer parser
return eval(expr); // SECURITY RISK
}
const result = evaluateExpression(userInput);
- Risk Level: Critical – Direct code execution vulnerability
- Recommendation: Replace with expression parser library (math.js, expr-eval)
Parameters
Parameter | Type | Description | Example |
---|---|---|---|
patterns | array | Search patterns (regex supported) | [“TODO”, “console\\.log”] |
projectPath | string | Root directory for search | “C:/project/src” |
includeContext | number | Context lines around matches (0-10) | 3 |
analysisType | enum | Analysis focus area | “patterns” | “security” | “comprehensive” |
maxDepth | number | Maximum directory depth (1-5) | 3 |
Pattern Syntax Guide
- Simple Text: “TODO” finds exact text matches
- Regex Patterns: “console\\.log” uses escaped regex for method calls
- Special Characters: Escape with double backslashes for literal matching
Advanced Configuration
Common Pattern Categories: Use these proven pattern sets for different analysis goals.
// Technical debt patterns
houtini-lm:find_pattern_usage with:
- patterns: ["TODO", "FIXME", "HACK", "TEMP", "XXX"]
- projectPath: "C:/project"
- analysisType: "comprehensive"
// Security vulnerability patterns
houtini-lm:find_pattern_usage with:
- patterns: ["eval\\(", "innerHTML", "document\\.write", "setTimeout\\(.+string"]
- analysisType: "security"
// React deprecated patterns
houtini-lm:find_pattern_usage with:
- patterns: ["componentWillMount", "componentWillReceiveProps", "findDOMNode"]
- projectPath: "C:/react-app/src"
Migration Analysis Workflow:
- Run find_pattern_usage to identify deprecated patterns
- Use suggest_refactoring for modern replacement recommendations
- Generate unit tests with generate_unit_tests before changes
- Verify cleanup with security_audit after modernisation
Pro Tips
Context Configuration: Use includeContext: 5-10 for complex patterns requiring more surrounding code for proper understanding.
Regex Patterns: Escape special regex characters with double backslashes when searching for literal function calls or operators.
Incremental Cleanup: Start with highest-risk security patterns, then address technical debt markers systematically.
Related Functions
- security_audit – Comprehensive security analysis with OWASP compliance
- suggest_refactoring – Code improvement recommendations for found patterns
- analyze_code_quality – Overall code quality assessment including pattern analysis
- find_unused_files – Dead code detection to complement pattern cleanup