code-auditor-mcp 1.17.1 → 1.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -543
- package/dist/codeIndexDb.d.ts +28 -0
- package/dist/codeIndexDb.d.ts.map +1 -1
- package/dist/codeIndexDb.js +125 -0
- package/dist/codeIndexDb.js.map +1 -1
- package/dist/mcp-standalone.js +20 -6
- package/dist/mcp-standalone.js.map +1 -1
- package/dist/mcp-tools/workflowGuide.d.ts.map +1 -1
- package/dist/mcp-tools/workflowGuide.js +111 -15
- package/dist/mcp-tools/workflowGuide.js.map +1 -1
- package/dist/mcp.js +213 -6
- package/dist/mcp.js.map +1 -1
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/examples/.code-auditor.json +75 -0
- package/examples/tolerant-solid.auditrc.json +70 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,598 +1,156 @@
|
|
|
1
|
-
# Code Auditor
|
|
2
|
-
|
|
3
|
-
A comprehensive TypeScript/JavaScript code quality audit tool that analyzes your codebase for SOLID principles compliance, DRY violations, security patterns, and more.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **SOLID Principles Analysis** - Detect violations of Single Responsibility, Open/Closed, and other SOLID principles
|
|
8
|
-
- **DRY (Don't Repeat Yourself)** - Find code duplication and suggest refactoring opportunities
|
|
9
|
-
- **Unused Imports Detection** - Identify unused imports at function or file level with configurable options
|
|
10
|
-
- **Security Pattern Analysis** - Verify authentication, authorization, and rate limiting implementations
|
|
11
|
-
- **Component Architecture Review** - Analyze component structure, complexity, and best practices
|
|
12
|
-
- **Data Access Patterns** - Check for SQL injection risks, performance issues, and security patterns
|
|
13
|
-
- **Code Function Indexing** - Index and search functions across your codebase with intelligent tokenization
|
|
14
|
-
- **AI Tool Configuration** - Auto-generate configurations for 10+ AI coding assistants
|
|
15
|
-
- **Advanced Search** - Natural language search with content search, match context, and query parsing
|
|
16
|
-
- **Index Maintenance** - Bulk cleanup and deep synchronization tools for accurate indexing
|
|
17
|
-
- **Multiple Output Formats** - Generate HTML, JSON, or CSV reports
|
|
18
|
-
- **Highly Configurable** - Customize thresholds, patterns, and analysis rules
|
|
19
|
-
- **Framework Support** - Built-in support for React, Vue, Angular, Svelte, and Node.js
|
|
20
|
-
- **MCP Server Integration** - Use with AI assistants like Claude for interactive code analysis
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
### Global Installation
|
|
25
|
-
```bash
|
|
26
|
-
npm install -g code-auditor
|
|
27
|
-
```
|
|
1
|
+
# Code Auditor: AI-Powered Code Intelligence
|
|
28
2
|
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
npm install --save-dev code-auditor
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### From Source
|
|
35
|
-
```bash
|
|
36
|
-
git clone https://github.com/code-auditor/code-auditor.git
|
|
37
|
-
cd code-auditor
|
|
38
|
-
npm install
|
|
39
|
-
npm run build
|
|
40
|
-
npm link
|
|
41
|
-
```
|
|
3
|
+
**Your AI understands your code.** Code Auditor indexes your entire codebase and provides real-time analysis that AI assistants like Claude can actually use to help you write better code.
|
|
42
4
|
|
|
43
|
-
##
|
|
5
|
+
## The Problem It Solves
|
|
44
6
|
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
# Run with default settings
|
|
48
|
-
code-audit
|
|
7
|
+
AI coding assistants are powerful, but they're flying blind. They can't search your codebase, don't know your patterns, and miss critical context. Code Auditor changes that by creating a searchable index of every function, component, and pattern in your code.
|
|
49
8
|
|
|
50
|
-
|
|
51
|
-
code-audit --init
|
|
9
|
+
## How It Works
|
|
52
10
|
|
|
53
|
-
|
|
54
|
-
|
|
11
|
+
1. **Index** - Automatically catalogs functions, React components, and dependencies
|
|
12
|
+
2. **Analyze** - Detects SOLID violations, code duplication, and security issues
|
|
13
|
+
3. **Connect** - AI assistants access your code index via MCP (Model Context Protocol)
|
|
14
|
+
4. **Iterate** - Get intelligent suggestions based on your actual codebase
|
|
55
15
|
|
|
56
|
-
|
|
57
|
-
code-audit -p ./src
|
|
58
|
-
```
|
|
16
|
+
## Quick Start (2 minutes)
|
|
59
17
|
|
|
60
|
-
### Common Options
|
|
61
18
|
```bash
|
|
62
|
-
#
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
# Run specific analyzers only
|
|
66
|
-
code-audit -a solid -a dry
|
|
67
|
-
|
|
68
|
-
# Set minimum severity level
|
|
69
|
-
code-audit -s warning
|
|
70
|
-
|
|
71
|
-
# Show detailed progress
|
|
72
|
-
code-audit -v
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## Configuration
|
|
76
|
-
|
|
77
|
-
The auditor looks for configuration in these locations (in order):
|
|
78
|
-
1. Command line arguments
|
|
79
|
-
2. `.auditrc.json` in the current directory
|
|
80
|
-
3. `audit.config.json` in the current directory
|
|
81
|
-
4. `audit.config.js` in the current directory
|
|
82
|
-
5. Environment variables (with `AUDIT_` prefix)
|
|
83
|
-
|
|
84
|
-
### Basic Configuration Example
|
|
85
|
-
|
|
86
|
-
```json
|
|
87
|
-
{
|
|
88
|
-
"includePaths": [
|
|
89
|
-
"src/**/*.{ts,tsx,js,jsx}"
|
|
90
|
-
],
|
|
91
|
-
"excludePaths": [
|
|
92
|
-
"**/node_modules/**",
|
|
93
|
-
"**/*.test.ts"
|
|
94
|
-
],
|
|
95
|
-
"enabledAnalyzers": [
|
|
96
|
-
"solid",
|
|
97
|
-
"dry",
|
|
98
|
-
"security",
|
|
99
|
-
"component",
|
|
100
|
-
"data-access"
|
|
101
|
-
],
|
|
102
|
-
"outputFormats": ["html", "json"],
|
|
103
|
-
"outputDirectory": "./audit-reports",
|
|
104
|
-
"thresholds": {
|
|
105
|
-
"maxCritical": 0,
|
|
106
|
-
"maxWarnings": 50,
|
|
107
|
-
"minHealthScore": 80
|
|
108
|
-
},
|
|
109
|
-
"unusedImportsConfig": {
|
|
110
|
-
"checkLevel": "function",
|
|
111
|
-
"includeTypeOnlyImports": false,
|
|
112
|
-
"ignorePatterns": ["React", "^_"]
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
```
|
|
19
|
+
# Add to your project with Claude Code CLI
|
|
20
|
+
claude mcp add code-auditor -- npx code-auditor-mcp
|
|
116
21
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
```json
|
|
122
|
-
{
|
|
123
|
-
"unusedImportsConfig": {
|
|
124
|
-
"checkLevel": "function", // "function" | "file" - analyze at function or file level
|
|
125
|
-
"includeTypeOnlyImports": false, // whether to report type-only imports as unused
|
|
126
|
-
"ignorePatterns": [ // regex patterns for imports to ignore
|
|
127
|
-
"React", // ignore React (often used implicitly in JSX)
|
|
128
|
-
"^_", // ignore imports starting with underscore
|
|
129
|
-
"test.*" // ignore test-related imports
|
|
130
|
-
]
|
|
131
|
-
}
|
|
132
|
-
}
|
|
22
|
+
# That's it! Now ask Claude:
|
|
23
|
+
# "What authentication functions exist in my codebase?"
|
|
24
|
+
# "Find all API endpoints and check for rate limiting"
|
|
25
|
+
# "Show me components similar to UserTable"
|
|
133
26
|
```
|
|
134
27
|
|
|
135
|
-
|
|
136
|
-
- `function` (default): Analyzes each function in isolation, reporting imports unused within that specific function
|
|
137
|
-
- `file`: Analyzes the entire file, reporting imports not used anywhere in the file
|
|
138
|
-
|
|
139
|
-
### Project-Specific Configurations
|
|
140
|
-
|
|
141
|
-
See the `examples/` directory for pre-configured setups:
|
|
142
|
-
- `nextjs.auditrc.json` - Next.js projects
|
|
143
|
-
- `react.auditrc.json` - React applications
|
|
144
|
-
- `node-api.auditrc.json` - Node.js APIs
|
|
145
|
-
|
|
146
|
-
## Available Analyzers
|
|
147
|
-
|
|
148
|
-
### SOLID Analyzer
|
|
149
|
-
Checks for violations of SOLID principles:
|
|
150
|
-
- Single Responsibility Principle
|
|
151
|
-
- Open/Closed Principle
|
|
152
|
-
- Liskov Substitution Principle
|
|
153
|
-
- Interface Segregation Principle
|
|
154
|
-
- Dependency Inversion Principle
|
|
155
|
-
|
|
156
|
-
### DRY Analyzer
|
|
157
|
-
Detects code duplication:
|
|
158
|
-
- Duplicate code blocks
|
|
159
|
-
- Similar function implementations
|
|
160
|
-
- Repeated imports
|
|
161
|
-
- String literal duplication
|
|
162
|
-
- Unused imports (file-level detection)
|
|
163
|
-
|
|
164
|
-
### Security Analyzer
|
|
165
|
-
Verifies security patterns:
|
|
166
|
-
- Authentication wrapper usage
|
|
167
|
-
- Authorization checks
|
|
168
|
-
- Rate limiting implementation
|
|
169
|
-
- Public endpoint identification
|
|
170
|
-
|
|
171
|
-
### Component Analyzer
|
|
172
|
-
Analyzes UI components:
|
|
173
|
-
- Component complexity
|
|
174
|
-
- Error boundary usage
|
|
175
|
-
- Prop validation
|
|
176
|
-
- Nesting depth
|
|
177
|
-
|
|
178
|
-
### Data Access Analyzer
|
|
179
|
-
Reviews database interactions:
|
|
180
|
-
- SQL injection vulnerabilities
|
|
181
|
-
- Query performance issues
|
|
182
|
-
- Missing security filters
|
|
183
|
-
- Connection patterns
|
|
184
|
-
|
|
185
|
-
## CLI Options
|
|
28
|
+
## Core Features That Matter
|
|
186
29
|
|
|
30
|
+
### 🔍 Natural Language Code Search
|
|
187
31
|
```
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
-i, --include <pattern> Include files matching pattern
|
|
192
|
-
-e, --exclude <pattern> Exclude files matching pattern
|
|
193
|
-
-a, --analyzers <name> Enable specific analyzers
|
|
194
|
-
-f, --format <format> Output format: html, json, csv
|
|
195
|
-
-o, --output <dir> Output directory for reports
|
|
196
|
-
-s, --severity <level> Minimum severity: critical, warning, suggestion
|
|
197
|
-
--fail-on-critical Exit with error code if critical issues found
|
|
198
|
-
--no-progress Disable progress bar
|
|
199
|
-
-v, --verbose Show detailed progress
|
|
200
|
-
--init Create a sample configuration file
|
|
201
|
-
-h, --help Show help
|
|
32
|
+
"Find all functions that validate user input"
|
|
33
|
+
"Show me where we're calling the payment API"
|
|
34
|
+
"What components use the useState hook?"
|
|
202
35
|
```
|
|
203
36
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
37
|
+
### 🎯 Smart Code Analysis
|
|
38
|
+
- **SOLID Principles** - Catch architecture issues before they spread
|
|
39
|
+
- **DRY Violations** - Find duplicate code that should be refactored
|
|
40
|
+
- **Security Patterns** - Verify auth, rate limiting, SQL injection protection
|
|
41
|
+
- **Dead Code** - Identify unused imports and functions
|
|
209
42
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
43
|
+
### 🤖 AI Tool Integration
|
|
44
|
+
Auto-generates configurations for:
|
|
45
|
+
- Claude (via MCP)
|
|
46
|
+
- Cursor
|
|
47
|
+
- Continue
|
|
48
|
+
- GitHub Copilot
|
|
49
|
+
- 10+ other AI assistants
|
|
214
50
|
|
|
215
|
-
|
|
216
|
-
|
|
51
|
+
### ⚙️ Persistent Configuration
|
|
52
|
+
Set your analyzer preferences once:
|
|
217
53
|
```
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
import { runAudit } from 'code-auditor';
|
|
222
|
-
|
|
223
|
-
const result = await runAudit({
|
|
224
|
-
projectRoot: './my-project',
|
|
225
|
-
outputFormats: ['html', 'json']
|
|
226
|
-
});
|
|
54
|
+
You: "Set SOLID analyzer to allow 3 responsibilities for components"
|
|
55
|
+
Claude: Configuration saved! All future audits will use this setting.
|
|
227
56
|
```
|
|
228
57
|
|
|
229
|
-
|
|
230
|
-
```typescript
|
|
231
|
-
import { createAuditRunner } from 'code-auditor';
|
|
232
|
-
|
|
233
|
-
// Pre-configured for Next.js projects
|
|
234
|
-
const runner = createAuditRunner('nextjs', {
|
|
235
|
-
thresholds: {
|
|
236
|
-
maxCritical: 0
|
|
237
|
-
}
|
|
238
|
-
});
|
|
58
|
+
## Real Examples
|
|
239
59
|
|
|
240
|
-
|
|
60
|
+
### Example 1: Finding Authentication Patterns
|
|
241
61
|
```
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
async analyzeFile(filePath: string, content: string) {
|
|
249
|
-
// Your analysis logic here
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const runner = new AuditRunner();
|
|
254
|
-
runner.registerAnalyzer('custom', {
|
|
255
|
-
name: 'My Custom Analyzer',
|
|
256
|
-
instance: new MyCustomAnalyzer()
|
|
257
|
-
});
|
|
62
|
+
You: "Show me all authentication-related functions"
|
|
63
|
+
Claude: Found 23 functions across 8 files:
|
|
64
|
+
- `validateToken()` in auth/tokens.ts:45
|
|
65
|
+
- `requireAuth()` in middleware/auth.ts:12
|
|
66
|
+
- `checkPermissions()` in auth/permissions.ts:78
|
|
67
|
+
...
|
|
258
68
|
```
|
|
259
69
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
### Health Score
|
|
263
|
-
The health score (0-100) is calculated based on:
|
|
264
|
-
- Number of violations per file
|
|
265
|
-
- Severity of violations (critical issues have more impact)
|
|
266
|
-
- Overall code coverage analyzed
|
|
267
|
-
|
|
268
|
-
### Severity Levels
|
|
269
|
-
- **Critical** 🔴 - Must be fixed immediately (security vulnerabilities, major bugs)
|
|
270
|
-
- **Warning** 🟡 - Should be addressed soon (poor patterns, minor security issues)
|
|
271
|
-
- **Suggestion** 🔵 - Nice to have improvements (optimizations, best practices)
|
|
272
|
-
|
|
273
|
-
### Report Formats
|
|
274
|
-
|
|
275
|
-
#### HTML Report
|
|
276
|
-
Interactive web report with:
|
|
277
|
-
- Summary dashboard
|
|
278
|
-
- Sortable violation lists
|
|
279
|
-
- Code snippets with line numbers
|
|
280
|
-
- Recommendations with examples
|
|
281
|
-
- Trend charts (when historical data available)
|
|
282
|
-
|
|
283
|
-
#### JSON Report
|
|
284
|
-
Machine-readable format containing:
|
|
285
|
-
- Complete violation details
|
|
286
|
-
- Metrics and statistics
|
|
287
|
-
- Recommendations
|
|
288
|
-
- MCP-compatible format option
|
|
289
|
-
|
|
290
|
-
#### CSV Report
|
|
291
|
-
Spreadsheet-friendly format with:
|
|
292
|
-
- Summary metrics
|
|
293
|
-
- Violation counts by category
|
|
294
|
-
- Trend data for tracking
|
|
295
|
-
|
|
296
|
-
## CI/CD Integration
|
|
297
|
-
|
|
298
|
-
### GitHub Actions
|
|
299
|
-
```yaml
|
|
300
|
-
- name: Run Code Audit
|
|
301
|
-
run: |
|
|
302
|
-
npm install -g code-auditor
|
|
303
|
-
code-audit -c .auditrc.json --fail-on-critical
|
|
70
|
+
### Example 2: Analyzing Code Quality
|
|
304
71
|
```
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
- npm install -g code-auditor
|
|
311
|
-
- code-audit -f json -o reports/
|
|
312
|
-
artifacts:
|
|
313
|
-
reports:
|
|
314
|
-
paths:
|
|
315
|
-
- reports/
|
|
72
|
+
You: "Audit the user service for issues"
|
|
73
|
+
Claude: Found 3 critical issues:
|
|
74
|
+
- Single Responsibility violation: UserService handles both auth and profile updates
|
|
75
|
+
- SQL injection risk: Raw query in getUserByEmail() at line 234
|
|
76
|
+
- Missing rate limiting on password reset endpoint
|
|
316
77
|
```
|
|
317
78
|
|
|
318
|
-
###
|
|
319
|
-
```groovy
|
|
320
|
-
stage('Code Audit') {
|
|
321
|
-
steps {
|
|
322
|
-
sh 'npm install -g code-auditor'
|
|
323
|
-
sh 'code-audit --fail-on-critical'
|
|
324
|
-
}
|
|
325
|
-
}
|
|
79
|
+
### Example 3: Discovering Patterns
|
|
326
80
|
```
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
- `
|
|
331
|
-
- `
|
|
332
|
-
- `AUDIT_MIN_SEVERITY` - Set minimum severity level
|
|
333
|
-
- `AUDIT_FAIL_ON_CRITICAL` - Exit with error on critical issues
|
|
334
|
-
- `AUDIT_ENABLED_ANALYZERS` - Comma-separated list of analyzers
|
|
335
|
-
|
|
336
|
-
## MCP Server Integration
|
|
337
|
-
|
|
338
|
-
Code Auditor includes a built-in MCP (Model Context Protocol) server that enables AI assistants like Claude to analyze your code interactively.
|
|
339
|
-
|
|
340
|
-
### Using with Claude Code CLI
|
|
341
|
-
|
|
342
|
-
The easiest way to use Code Auditor with Claude is through the Claude Code CLI:
|
|
343
|
-
|
|
344
|
-
```bash
|
|
345
|
-
# Add the Code Auditor MCP server to your project
|
|
346
|
-
claude mcp add code-auditor -- npx code-auditor-mcp
|
|
347
|
-
|
|
348
|
-
# The MCP server is now available in your Claude Code session
|
|
349
|
-
# Just ask Claude to analyze your code!
|
|
81
|
+
You: "Find React components similar to DataTable"
|
|
82
|
+
Claude: Found 4 similar components:
|
|
83
|
+
- `UserTable` - extends DataTable with user-specific columns
|
|
84
|
+
- `OrderGrid` - implements similar pagination pattern
|
|
85
|
+
- `ProductList` - uses same filtering approach
|
|
350
86
|
```
|
|
351
87
|
|
|
352
|
-
|
|
88
|
+
## Installation Options
|
|
353
89
|
|
|
90
|
+
### Global Install
|
|
354
91
|
```bash
|
|
355
|
-
# Using npm start (if installed locally)
|
|
356
|
-
claude mcp add code-auditor -- npm start
|
|
357
|
-
|
|
358
|
-
# Using global installation
|
|
359
92
|
npm install -g code-auditor-mcp
|
|
360
|
-
|
|
93
|
+
code-audit # Run analysis
|
|
361
94
|
```
|
|
362
95
|
|
|
363
|
-
###
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
1. Install code-auditor globally:
|
|
368
|
-
```bash
|
|
369
|
-
npm install -g code-auditor-mcp
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
2. Add to your Claude Desktop configuration:
|
|
373
|
-
```json
|
|
374
|
-
{
|
|
375
|
-
"mcpServers": {
|
|
376
|
-
"code-auditor": {
|
|
377
|
-
"command": "npx",
|
|
378
|
-
"args": ["code-auditor-mcp"]
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
Configuration file locations:
|
|
385
|
-
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
386
|
-
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
387
|
-
- Linux: `~/.config/Claude/claude_desktop_config.json`
|
|
388
|
-
|
|
389
|
-
3. Restart Claude Desktop
|
|
390
|
-
|
|
391
|
-
### Available MCP Tools
|
|
392
|
-
|
|
393
|
-
#### Code Analysis Tools
|
|
394
|
-
- **audit_run** - Run a comprehensive code audit
|
|
395
|
-
- **audit_analyze_file** - Analyze a specific file for issues
|
|
396
|
-
- **audit_check_health** - Get a quick health score for your codebase
|
|
397
|
-
- **audit_list_analyzers** - List all available analyzers and their capabilities
|
|
398
|
-
|
|
399
|
-
#### Code Index Tools
|
|
400
|
-
- **index_functions** - Index functions from TypeScript/JavaScript files
|
|
401
|
-
- **search_functions** - Search indexed functions with natural language queries
|
|
402
|
-
- **find_definition** - Find the exact definition of a specific function
|
|
403
|
-
- **register_functions** - Manually register functions with metadata
|
|
404
|
-
- **get_index_stats** - Get statistics about the code index
|
|
405
|
-
- **clear_index** - Clear all indexed functions
|
|
406
|
-
|
|
407
|
-
#### AI Configuration Tools
|
|
408
|
-
- **generate_ai_configs** - Generate configs for AI coding assistants (Cursor, Continue, Copilot, etc.)
|
|
409
|
-
- **list_ai_tools** - List all supported AI tools
|
|
410
|
-
- **get_ai_tool_info** - Get detailed info about a specific AI tool
|
|
411
|
-
- **validate_ai_config** - Validate an AI tool configuration
|
|
412
|
-
|
|
413
|
-
#### Maintenance Tools
|
|
414
|
-
- **bulk_cleanup** - Remove index entries for deleted files
|
|
415
|
-
- **deep_sync** - Deep synchronize all indexed files
|
|
416
|
-
|
|
417
|
-
#### Analyzer Configuration Tools
|
|
418
|
-
- **whitelist_get** - View current whitelist entries (platform APIs, dependencies, etc.)
|
|
419
|
-
- **whitelist_add** - Add exceptions for legitimate patterns (framework classes, etc.)
|
|
420
|
-
- **whitelist_update_status** - Enable/disable whitelist entries
|
|
421
|
-
- **whitelist_detect** - Auto-detect and suggest whitelist entries from package.json
|
|
422
|
-
|
|
423
|
-
### Advanced Search Functionality
|
|
424
|
-
|
|
425
|
-
The `search_functions` tool (and `search_code` in MCP) supports powerful search operators that enable precise code discovery. You can use natural language queries combined with special operators to find exactly what you need.
|
|
426
|
-
|
|
427
|
-
#### Search Modes
|
|
428
|
-
|
|
429
|
-
The search tool now supports three distinct search modes:
|
|
430
|
-
|
|
431
|
-
- **metadata** (default) - Searches in function names, signatures, and metadata
|
|
432
|
-
- **content** - Searches within function bodies and implementations
|
|
433
|
-
- **both** - Searches in both metadata and content
|
|
434
|
-
|
|
435
|
-
Set the search mode in the MCP tool by adding it to filters:
|
|
436
|
-
```json
|
|
437
|
-
{
|
|
438
|
-
"query": "validateUser",
|
|
439
|
-
"filters": {
|
|
440
|
-
"searchMode": "content"
|
|
441
|
-
}
|
|
442
|
-
}
|
|
96
|
+
### Project Install
|
|
97
|
+
```bash
|
|
98
|
+
npm install --save-dev code-auditor
|
|
99
|
+
npx code-audit
|
|
443
100
|
```
|
|
444
101
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
```typescript
|
|
451
|
-
{
|
|
452
|
-
"contentMatches": [
|
|
453
|
-
{
|
|
454
|
-
"line": 45,
|
|
455
|
-
"column": 8,
|
|
456
|
-
"match": "validateUser(email)"
|
|
457
|
-
}
|
|
458
|
-
],
|
|
459
|
-
"matchContexts": [
|
|
460
|
-
{
|
|
461
|
-
"matchIndex": 0,
|
|
462
|
-
"context": [
|
|
463
|
-
" // Check if user exists",
|
|
464
|
-
" const user = await getUserByEmail(email);",
|
|
465
|
-
" if (!validateUser(email)) {",
|
|
466
|
-
" throw new Error('Invalid user');",
|
|
467
|
-
" }"
|
|
468
|
-
]
|
|
469
|
-
}
|
|
470
|
-
]
|
|
471
|
-
}
|
|
102
|
+
### CI/CD Integration
|
|
103
|
+
```yaml
|
|
104
|
+
# GitHub Actions
|
|
105
|
+
- name: Code Audit
|
|
106
|
+
run: npx code-audit --fail-on-critical
|
|
472
107
|
```
|
|
473
108
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
| Operator | Description | Example |
|
|
477
|
-
|----------|-------------|---------|
|
|
478
|
-
| `file:` | Filter by file path | `file:utils` `file:src/components` |
|
|
479
|
-
| `type:` | Filter by file type | `type:ts` `type:tsx` |
|
|
480
|
-
| `lang:` `language:` | Filter by language | `lang:typescript` |
|
|
481
|
-
| `entity:` | Filter by entity type | `entity:function` `entity:component` |
|
|
482
|
-
| `async:` | Filter async functions | `async:true` `async:false` |
|
|
483
|
-
| `exported:` | Filter by export status | `exported:true` |
|
|
484
|
-
| `kind:` | Filter by function kind | `kind:arrow` `kind:method` |
|
|
485
|
-
| `complexity:` | Filter by complexity | `complexity:>10` `complexity:5-10` |
|
|
486
|
-
| `jsdoc:` `doc:` | Filter by documentation | `jsdoc:true` `doc:false` |
|
|
487
|
-
| **Dependency Operators** | | |
|
|
488
|
-
| `dep:` `dependency:` `uses:` | Find dependency usage | `dep:lodash` `uses:react` |
|
|
489
|
-
| `calls:` | Functions calling a function | `calls:validateUser` |
|
|
490
|
-
| `calledby:` `dependents-of:` | Functions called by | `calledby:handleRequest` |
|
|
491
|
-
| `unused-imports` | Find unused imports | `unused-imports` |
|
|
492
|
-
| **React Operators** | | |
|
|
493
|
-
| `component:` | Filter component type | `component:functional` |
|
|
494
|
-
| `hook:` `hooks:` | Find hook usage | `hook:useState` |
|
|
495
|
-
| `prop:` `props:` | Find prop usage | `prop:onClick` |
|
|
496
|
-
| **Search Modifiers** | | |
|
|
497
|
-
| `-` | Exclude terms | `validate -test` |
|
|
498
|
-
| `"..."` | Exact phrase | `"user authentication"` |
|
|
499
|
-
| `~` `fuzzy` | Enable fuzzy search | `~ authenticaton` |
|
|
500
|
-
| `stem` `stemming` | Enable stemming | `stem render` |
|
|
501
|
-
|
|
502
|
-
#### Example Searches
|
|
109
|
+
## Key Commands
|
|
503
110
|
|
|
504
111
|
```bash
|
|
505
|
-
#
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
#
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
# Find undocumented exported functions
|
|
512
|
-
search_code "exported:true jsdoc:false"
|
|
513
|
-
|
|
514
|
-
# Find React components using hooks
|
|
515
|
-
search_code "component:functional hook:useState"
|
|
516
|
-
|
|
517
|
-
# Find functions with unused imports
|
|
518
|
-
search_code "unused-imports file:src"
|
|
112
|
+
code-audit # Full analysis with HTML report
|
|
113
|
+
code-audit -f json # JSON output for CI/CD
|
|
114
|
+
code-audit -a solid,dry # Run specific analyzers
|
|
115
|
+
code-audit --health # Quick health score (0-100)
|
|
116
|
+
```
|
|
519
117
|
|
|
520
|
-
|
|
521
|
-
search_code "dependents-of:authenticate"
|
|
118
|
+
## The Feedback Loop
|
|
522
119
|
|
|
523
|
-
|
|
524
|
-
|
|
120
|
+
1. **Write Code** → Code Auditor indexes it automatically
|
|
121
|
+
2. **Ask AI** → "Is there a function to validate emails?"
|
|
122
|
+
3. **Get Context** → AI finds `validateEmail()` and similar patterns
|
|
123
|
+
4. **Improve** → AI suggests using existing validation instead of duplicating
|
|
124
|
+
5. **Repeat** → Your AI gets smarter about YOUR codebase
|
|
525
125
|
|
|
526
|
-
|
|
527
|
-
search_code '"Invalid user"' --filters '{"searchMode": "content"}'
|
|
126
|
+
## Advanced Search Operators
|
|
528
127
|
|
|
529
|
-
|
|
530
|
-
|
|
128
|
+
| What You Want | Search Query |
|
|
129
|
+
|--------------|--------------|
|
|
130
|
+
| Complex functions | `complexity:>10` |
|
|
131
|
+
| Undocumented exports | `exported:true jsdoc:false` |
|
|
132
|
+
| React hooks usage | `component:functional hook:useState` |
|
|
133
|
+
| Find dependencies | `calls:validateUser` |
|
|
134
|
+
| Unused imports | `unused-imports file:src` |
|
|
531
135
|
|
|
532
|
-
|
|
533
|
-
search_code "Button component:functional prop:onClick file:components"
|
|
136
|
+
## Performance
|
|
534
137
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
### Usage Examples with Claude
|
|
540
|
-
|
|
541
|
-
```
|
|
542
|
-
# Code Analysis
|
|
543
|
-
"Run a code audit on my project and show me the critical issues"
|
|
544
|
-
"Check the health score of the src directory"
|
|
545
|
-
"Analyze my code for SOLID principle violations"
|
|
546
|
-
"Find security vulnerabilities in my authentication code"
|
|
547
|
-
"Show me all code duplication in the components folder"
|
|
548
|
-
|
|
549
|
-
# Code Search & Discovery (Metadata Search)
|
|
550
|
-
"Search for functions that validate email addresses"
|
|
551
|
-
"Find all user authentication functions"
|
|
552
|
-
"Show me any existing data table components"
|
|
553
|
-
"Search for functions that send notifications"
|
|
554
|
-
"Find all React components that use useState hook"
|
|
555
|
-
|
|
556
|
-
# Content Search (Search within function bodies)
|
|
557
|
-
"Search for where we're calling the validateUser function in the code"
|
|
558
|
-
"Find all SQL queries that select from the users table"
|
|
559
|
-
"Show me where we're throwing 'Invalid user' errors"
|
|
560
|
-
"Find all console.log statements in production code"
|
|
561
|
-
"Search for TODO comments in function implementations"
|
|
562
|
-
"Find where we're using the column 'country' in our queries"
|
|
563
|
-
|
|
564
|
-
# Combined Search
|
|
565
|
-
"Find authentication functions and show where they're called from"
|
|
566
|
-
"Search for Button components and their onClick handlers"
|
|
567
|
-
"Find all API endpoints and their rate limiting implementations"
|
|
568
|
-
|
|
569
|
-
# AI Tool Configuration
|
|
570
|
-
"Generate AI configurations for Cursor and Claude"
|
|
571
|
-
"List all supported AI coding tools"
|
|
572
|
-
"Set up my AI tools to use the code index"
|
|
573
|
-
|
|
574
|
-
# Maintenance
|
|
575
|
-
"Clean up stale entries in the code index"
|
|
576
|
-
"Sync all indexed files to update function signatures"
|
|
577
|
-
"Re-index the src directory to pick up recent changes"
|
|
578
|
-
```
|
|
579
|
-
|
|
580
|
-
See [TOOLS-DOCUMENTATION.md](TOOLS-DOCUMENTATION.md) for comprehensive documentation on all MCP tools.
|
|
138
|
+
- Indexes 10,000+ functions in seconds
|
|
139
|
+
- Incremental updates on file changes
|
|
140
|
+
- LokiJS for fast in-memory search
|
|
141
|
+
- FlexSearch for intelligent queries
|
|
581
142
|
|
|
582
143
|
## Contributing
|
|
583
144
|
|
|
584
|
-
|
|
145
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
585
146
|
|
|
586
147
|
## License
|
|
587
148
|
|
|
588
|
-
MIT
|
|
589
|
-
|
|
590
|
-
## Support
|
|
149
|
+
MIT - Use it anywhere, anytime.
|
|
591
150
|
|
|
592
|
-
|
|
593
|
-
- **Discussions**: [GitHub Discussions](https://github.com/yourusername/code-auditor/discussions)
|
|
594
|
-
- **Documentation**: [Full Documentation](https://yourusername.github.io/code-auditor)
|
|
151
|
+
---
|
|
595
152
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
153
|
+
**Ready to give your AI x-ray vision into your code?**
|
|
154
|
+
```bash
|
|
155
|
+
claude mcp add code-auditor -- npx code-auditor-mcp
|
|
156
|
+
```
|