code-auditor-mcp 1.0.0

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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +362 -0
  3. package/configs/hhra-compat.json +168 -0
  4. package/dist/analyzers/analyzerUtils.d.ts +69 -0
  5. package/dist/analyzers/analyzerUtils.d.ts.map +1 -0
  6. package/dist/analyzers/analyzerUtils.js +188 -0
  7. package/dist/analyzers/analyzerUtils.js.map +1 -0
  8. package/dist/analyzers/dataAccessAnalyzer.d.ts +46 -0
  9. package/dist/analyzers/dataAccessAnalyzer.d.ts.map +1 -0
  10. package/dist/analyzers/dataAccessAnalyzer.js +448 -0
  11. package/dist/analyzers/dataAccessAnalyzer.js.map +1 -0
  12. package/dist/analyzers/dryAnalyzer.d.ts +30 -0
  13. package/dist/analyzers/dryAnalyzer.d.ts.map +1 -0
  14. package/dist/analyzers/dryAnalyzer.js +537 -0
  15. package/dist/analyzers/dryAnalyzer.js.map +1 -0
  16. package/dist/analyzers/solidAnalyzer.d.ts +23 -0
  17. package/dist/analyzers/solidAnalyzer.d.ts.map +1 -0
  18. package/dist/analyzers/solidAnalyzer.js +355 -0
  19. package/dist/analyzers/solidAnalyzer.js.map +1 -0
  20. package/dist/auditRunner.d.ts +20 -0
  21. package/dist/auditRunner.d.ts.map +1 -0
  22. package/dist/auditRunner.js +214 -0
  23. package/dist/auditRunner.js.map +1 -0
  24. package/dist/cli.d.ts +6 -0
  25. package/dist/cli.d.ts.map +1 -0
  26. package/dist/cli.js +38 -0
  27. package/dist/cli.js.map +1 -0
  28. package/dist/config/configLoader.d.ts +19 -0
  29. package/dist/config/configLoader.d.ts.map +1 -0
  30. package/dist/config/configLoader.js +124 -0
  31. package/dist/config/configLoader.js.map +1 -0
  32. package/dist/config/defaults.d.ts +69 -0
  33. package/dist/config/defaults.d.ts.map +1 -0
  34. package/dist/config/defaults.js +142 -0
  35. package/dist/config/defaults.js.map +1 -0
  36. package/dist/index.d.ts +44 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +66 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/mcp-standalone.d.ts +3 -0
  41. package/dist/mcp-standalone.d.ts.map +1 -0
  42. package/dist/mcp-standalone.js +171 -0
  43. package/dist/mcp-standalone.js.map +1 -0
  44. package/dist/mcp.d.ts +3 -0
  45. package/dist/mcp.d.ts.map +1 -0
  46. package/dist/mcp.js +340 -0
  47. package/dist/mcp.js.map +1 -0
  48. package/dist/reporting/csvReportGenerator.d.ts +29 -0
  49. package/dist/reporting/csvReportGenerator.d.ts.map +1 -0
  50. package/dist/reporting/csvReportGenerator.js +182 -0
  51. package/dist/reporting/csvReportGenerator.js.map +1 -0
  52. package/dist/reporting/htmlReportGenerator.d.ts +18 -0
  53. package/dist/reporting/htmlReportGenerator.d.ts.map +1 -0
  54. package/dist/reporting/htmlReportGenerator.js +352 -0
  55. package/dist/reporting/htmlReportGenerator.js.map +1 -0
  56. package/dist/reporting/jsonReportGenerator.d.ts +23 -0
  57. package/dist/reporting/jsonReportGenerator.d.ts.map +1 -0
  58. package/dist/reporting/jsonReportGenerator.js +103 -0
  59. package/dist/reporting/jsonReportGenerator.js.map +1 -0
  60. package/dist/reporting/reportGenerator.d.ts +21 -0
  61. package/dist/reporting/reportGenerator.d.ts.map +1 -0
  62. package/dist/reporting/reportGenerator.js +53 -0
  63. package/dist/reporting/reportGenerator.js.map +1 -0
  64. package/dist/types.d.ts +246 -0
  65. package/dist/types.d.ts.map +1 -0
  66. package/dist/types.js +6 -0
  67. package/dist/types.js.map +1 -0
  68. package/dist/utils/astParser.d.ts +71 -0
  69. package/dist/utils/astParser.d.ts.map +1 -0
  70. package/dist/utils/astParser.js +244 -0
  71. package/dist/utils/astParser.js.map +1 -0
  72. package/dist/utils/astUtils.d.ts +89 -0
  73. package/dist/utils/astUtils.d.ts.map +1 -0
  74. package/dist/utils/astUtils.js +289 -0
  75. package/dist/utils/astUtils.js.map +1 -0
  76. package/dist/utils/fileDiscovery.d.ts +58 -0
  77. package/dist/utils/fileDiscovery.d.ts.map +1 -0
  78. package/dist/utils/fileDiscovery.js +203 -0
  79. package/dist/utils/fileDiscovery.js.map +1 -0
  80. package/examples/.auditrc.example.json +61 -0
  81. package/examples/.auditrc.json +201 -0
  82. package/examples/nextjs.auditrc.json +65 -0
  83. package/examples/node-api.auditrc.json +82 -0
  84. package/examples/react.auditrc.json +59 -0
  85. package/package.json +62 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Code Auditor Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,362 @@
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
+ - **Security Pattern Analysis** - Verify authentication, authorization, and rate limiting implementations
10
+ - **Component Architecture Review** - Analyze component structure, complexity, and best practices
11
+ - **Data Access Patterns** - Check for SQL injection risks, performance issues, and security patterns
12
+ - **Multiple Output Formats** - Generate HTML, JSON, or CSV reports
13
+ - **Highly Configurable** - Customize thresholds, patterns, and analysis rules
14
+ - **Framework Support** - Built-in support for React, Vue, Angular, Svelte, and Node.js
15
+ - **MCP Server Integration** - Use with AI assistants like Claude for interactive code analysis
16
+
17
+ ## Installation
18
+
19
+ ### Global Installation
20
+ ```bash
21
+ npm install -g code-auditor
22
+ ```
23
+
24
+ ### Local Installation
25
+ ```bash
26
+ npm install --save-dev code-auditor
27
+ ```
28
+
29
+ ### From Source
30
+ ```bash
31
+ git clone https://github.com/code-auditor/code-auditor.git
32
+ cd code-auditor
33
+ npm install
34
+ npm run build
35
+ npm link
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ### Basic Usage
41
+ ```bash
42
+ # Run with default settings
43
+ code-audit
44
+
45
+ # Generate a sample configuration
46
+ code-audit --init
47
+
48
+ # Use a specific configuration
49
+ code-audit -c .auditrc.json
50
+
51
+ # Analyze a specific directory
52
+ code-audit -p ./src
53
+ ```
54
+
55
+ ### Common Options
56
+ ```bash
57
+ # Generate multiple report formats
58
+ code-audit -f html -f json -f csv
59
+
60
+ # Run specific analyzers only
61
+ code-audit -a solid -a dry
62
+
63
+ # Set minimum severity level
64
+ code-audit -s warning
65
+
66
+ # Show detailed progress
67
+ code-audit -v
68
+ ```
69
+
70
+ ## Configuration
71
+
72
+ The auditor looks for configuration in these locations (in order):
73
+ 1. Command line arguments
74
+ 2. `.auditrc.json` in the current directory
75
+ 3. `audit.config.json` in the current directory
76
+ 4. `audit.config.js` in the current directory
77
+ 5. Environment variables (with `AUDIT_` prefix)
78
+
79
+ ### Basic Configuration Example
80
+
81
+ ```json
82
+ {
83
+ "includePaths": [
84
+ "src/**/*.{ts,tsx,js,jsx}"
85
+ ],
86
+ "excludePaths": [
87
+ "**/node_modules/**",
88
+ "**/*.test.ts"
89
+ ],
90
+ "enabledAnalyzers": [
91
+ "solid",
92
+ "dry",
93
+ "security",
94
+ "component",
95
+ "data-access"
96
+ ],
97
+ "outputFormats": ["html", "json"],
98
+ "outputDirectory": "./audit-reports",
99
+ "thresholds": {
100
+ "maxCritical": 0,
101
+ "maxWarnings": 50,
102
+ "minHealthScore": 80
103
+ }
104
+ }
105
+ ```
106
+
107
+ ### Project-Specific Configurations
108
+
109
+ See the `examples/` directory for pre-configured setups:
110
+ - `nextjs.auditrc.json` - Next.js projects
111
+ - `react.auditrc.json` - React applications
112
+ - `node-api.auditrc.json` - Node.js APIs
113
+
114
+ ## Available Analyzers
115
+
116
+ ### SOLID Analyzer
117
+ Checks for violations of SOLID principles:
118
+ - Single Responsibility Principle
119
+ - Open/Closed Principle
120
+ - Liskov Substitution Principle
121
+ - Interface Segregation Principle
122
+ - Dependency Inversion Principle
123
+
124
+ ### DRY Analyzer
125
+ Detects code duplication:
126
+ - Duplicate code blocks
127
+ - Similar function implementations
128
+ - Repeated imports
129
+ - String literal duplication
130
+
131
+ ### Security Analyzer
132
+ Verifies security patterns:
133
+ - Authentication wrapper usage
134
+ - Authorization checks
135
+ - Rate limiting implementation
136
+ - Public endpoint identification
137
+
138
+ ### Component Analyzer
139
+ Analyzes UI components:
140
+ - Component complexity
141
+ - Error boundary usage
142
+ - Prop validation
143
+ - Nesting depth
144
+
145
+ ### Data Access Analyzer
146
+ Reviews database interactions:
147
+ - SQL injection vulnerabilities
148
+ - Query performance issues
149
+ - Missing security filters
150
+ - Connection patterns
151
+
152
+ ## CLI Options
153
+
154
+ ```
155
+ Options:
156
+ -c, --config <file> Load configuration from file
157
+ -p, --project <dir> Project root directory
158
+ -i, --include <pattern> Include files matching pattern
159
+ -e, --exclude <pattern> Exclude files matching pattern
160
+ -a, --analyzers <name> Enable specific analyzers
161
+ -f, --format <format> Output format: html, json, csv
162
+ -o, --output <dir> Output directory for reports
163
+ -s, --severity <level> Minimum severity: critical, warning, suggestion
164
+ --fail-on-critical Exit with error code if critical issues found
165
+ --no-progress Disable progress bar
166
+ -v, --verbose Show detailed progress
167
+ --init Create a sample configuration file
168
+ -h, --help Show help
169
+ ```
170
+
171
+ ## Programmatic API
172
+
173
+ ### Basic Usage
174
+ ```typescript
175
+ import { AuditRunner } from 'code-auditor';
176
+
177
+ const runner = new AuditRunner({
178
+ includePaths: ['src/**/*.ts'],
179
+ enabledAnalyzers: ['solid', 'dry']
180
+ });
181
+
182
+ const result = await runner.run();
183
+ console.log(`Found ${result.summary.totalViolations} issues`);
184
+ ```
185
+
186
+ ### Quick Audit Function
187
+ ```typescript
188
+ import { runAudit } from 'code-auditor';
189
+
190
+ const result = await runAudit({
191
+ projectRoot: './my-project',
192
+ outputFormats: ['html', 'json']
193
+ });
194
+ ```
195
+
196
+ ### Project-Specific Runner
197
+ ```typescript
198
+ import { createAuditRunner } from 'code-auditor';
199
+
200
+ // Pre-configured for Next.js projects
201
+ const runner = createAuditRunner('nextjs', {
202
+ thresholds: {
203
+ maxCritical: 0
204
+ }
205
+ });
206
+
207
+ const result = await runner.run();
208
+ ```
209
+
210
+ ### Custom Analyzer
211
+ ```typescript
212
+ import { BaseAnalyzer, AuditRunner } from 'code-auditor';
213
+
214
+ class MyCustomAnalyzer extends BaseAnalyzer {
215
+ async analyzeFile(filePath: string, content: string) {
216
+ // Your analysis logic here
217
+ }
218
+ }
219
+
220
+ const runner = new AuditRunner();
221
+ runner.registerAnalyzer('custom', {
222
+ name: 'My Custom Analyzer',
223
+ instance: new MyCustomAnalyzer()
224
+ });
225
+ ```
226
+
227
+ ## Understanding Reports
228
+
229
+ ### Health Score
230
+ The health score (0-100) is calculated based on:
231
+ - Number of violations per file
232
+ - Severity of violations (critical issues have more impact)
233
+ - Overall code coverage analyzed
234
+
235
+ ### Severity Levels
236
+ - **Critical** 🔴 - Must be fixed immediately (security vulnerabilities, major bugs)
237
+ - **Warning** 🟡 - Should be addressed soon (poor patterns, minor security issues)
238
+ - **Suggestion** 🔵 - Nice to have improvements (optimizations, best practices)
239
+
240
+ ### Report Formats
241
+
242
+ #### HTML Report
243
+ Interactive web report with:
244
+ - Summary dashboard
245
+ - Sortable violation lists
246
+ - Code snippets with line numbers
247
+ - Recommendations with examples
248
+ - Trend charts (when historical data available)
249
+
250
+ #### JSON Report
251
+ Machine-readable format containing:
252
+ - Complete violation details
253
+ - Metrics and statistics
254
+ - Recommendations
255
+ - MCP-compatible format option
256
+
257
+ #### CSV Report
258
+ Spreadsheet-friendly format with:
259
+ - Summary metrics
260
+ - Violation counts by category
261
+ - Trend data for tracking
262
+
263
+ ## CI/CD Integration
264
+
265
+ ### GitHub Actions
266
+ ```yaml
267
+ - name: Run Code Audit
268
+ run: |
269
+ npm install -g code-auditor
270
+ code-audit -c .auditrc.json --fail-on-critical
271
+ ```
272
+
273
+ ### GitLab CI
274
+ ```yaml
275
+ code-audit:
276
+ script:
277
+ - npm install -g code-auditor
278
+ - code-audit -f json -o reports/
279
+ artifacts:
280
+ reports:
281
+ paths:
282
+ - reports/
283
+ ```
284
+
285
+ ### Jenkins
286
+ ```groovy
287
+ stage('Code Audit') {
288
+ steps {
289
+ sh 'npm install -g code-auditor'
290
+ sh 'code-audit --fail-on-critical'
291
+ }
292
+ }
293
+ ```
294
+
295
+ ## Environment Variables
296
+
297
+ - `AUDIT_OUTPUT_DIR` - Override output directory
298
+ - `AUDIT_VERBOSE` - Enable verbose output
299
+ - `AUDIT_MIN_SEVERITY` - Set minimum severity level
300
+ - `AUDIT_FAIL_ON_CRITICAL` - Exit with error on critical issues
301
+ - `AUDIT_ENABLED_ANALYZERS` - Comma-separated list of analyzers
302
+
303
+ ## MCP Server Integration
304
+
305
+ Code Auditor includes a built-in MCP (Model Context Protocol) server that enables AI assistants like Claude to analyze your code interactively.
306
+
307
+ ### Setting up with Claude Desktop
308
+
309
+ 1. Install code-auditor globally:
310
+ ```bash
311
+ npm install -g code-auditor
312
+ ```
313
+
314
+ 2. Add to your Claude Desktop configuration:
315
+ ```json
316
+ {
317
+ "mcpServers": {
318
+ "code-auditor": {
319
+ "command": "npx",
320
+ "args": ["code-auditor-mcp"]
321
+ }
322
+ }
323
+ }
324
+ ```
325
+
326
+ Configuration file locations:
327
+ - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
328
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
329
+ - Linux: `~/.config/Claude/claude_desktop_config.json`
330
+
331
+ 3. Restart Claude Desktop
332
+
333
+ ### Available MCP Tools
334
+
335
+ - **audit_run** - Run a comprehensive code audit
336
+ - **audit_check_health** - Get a quick health score for your codebase
337
+
338
+ ### Usage Examples with Claude
339
+
340
+ ```
341
+ "Run a code audit on my project and show me the critical issues"
342
+ "Check the health score of the src directory"
343
+ "Analyze my code for SOLID principle violations"
344
+ ```
345
+
346
+ ## Contributing
347
+
348
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
349
+
350
+ ## License
351
+
352
+ MIT License - see [LICENSE](LICENSE) file for details.
353
+
354
+ ## Support
355
+
356
+ - **Issues**: [GitHub Issues](https://github.com/yourusername/code-auditor/issues)
357
+ - **Discussions**: [GitHub Discussions](https://github.com/yourusername/code-auditor/discussions)
358
+ - **Documentation**: [Full Documentation](https://yourusername.github.io/code-auditor)
359
+
360
+ ## Acknowledgments
361
+
362
+ Originally extracted from the HHRA ORG-Tracker project, this tool has been generalized for use with any TypeScript/JavaScript codebase.
@@ -0,0 +1,168 @@
1
+ {
2
+ "projectRoot": "../..",
3
+ "reportTitle": "HHRA Architecture & Code Quality Audit",
4
+
5
+ "includePaths": [
6
+ "app/**/*.{ts,tsx}",
7
+ "src/**/*.{ts,tsx}",
8
+ "scripts/**/*.ts"
9
+ ],
10
+
11
+ "excludePaths": [
12
+ "**/node_modules/**",
13
+ "**/.next/**",
14
+ "**/dist/**",
15
+ "**/build/**",
16
+ "**/coverage/**",
17
+ "**/*.test.{ts,tsx}",
18
+ "**/*.spec.{ts,tsx}",
19
+ "**/tests/**",
20
+ "**/e2e/**",
21
+ "**/.vercel/**",
22
+ "**/public/**",
23
+ "code-auditor/**"
24
+ ],
25
+
26
+ "enabledAnalyzers": [
27
+ "component",
28
+ "security",
29
+ "solid",
30
+ "dry",
31
+ "data-access"
32
+ ],
33
+
34
+ "analyzerConfig": {
35
+ "security": {
36
+ "authPatterns": [
37
+ "withAuth",
38
+ "withAdminAuth",
39
+ "requireAuth",
40
+ "SessionAuth",
41
+ "useSession"
42
+ ],
43
+ "adminPatterns": [
44
+ "withAdminAuth",
45
+ "requireAdmin",
46
+ "adminOnly"
47
+ ],
48
+ "rateLimitPatterns": [
49
+ "rateLimit",
50
+ "withRateLimit",
51
+ "rateLimitGuard"
52
+ ],
53
+ "publicPatterns": [
54
+ "public",
55
+ "noAuth",
56
+ "skipAuth"
57
+ ]
58
+ },
59
+
60
+ "component": {
61
+ "frameworkPatterns": {
62
+ "react": {
63
+ "components": ["*.tsx", "*.jsx"],
64
+ "hooks": ["use*"],
65
+ "context": ["*Context", "*Provider"]
66
+ }
67
+ },
68
+ "checkErrorBoundaries": true,
69
+ "checkPropTypes": false,
70
+ "maxComplexity": 15,
71
+ "maxNesting": 4
72
+ },
73
+
74
+ "data-access": {
75
+ "databasePatterns": {
76
+ "postgres": ["app-db", "org-tracker-db", "@neondatabase", "neon"],
77
+ "drizzle": ["drizzle-orm", "db.query", "db.select", "db.insert", "db.update", "db.delete"]
78
+ },
79
+ "ormPatterns": {
80
+ "drizzle": ["drizzle-orm", "drizzle", "schema"]
81
+ },
82
+ "securityPatterns": {
83
+ "parameterized": ["?", "$1", ":param", "prepared"],
84
+ "sanitized": ["sanitize", "escape", "clean", "safe"]
85
+ },
86
+ "performanceThresholds": {
87
+ "maxJoins": 5,
88
+ "warnOnSelectStar": true
89
+ }
90
+ },
91
+
92
+ "solid": {
93
+ "maxMethodsPerClass": 10,
94
+ "maxLinesPerMethod": 50,
95
+ "maxParametersPerMethod": 4,
96
+ "maxImportsPerFile": 20,
97
+ "maxComplexity": 10
98
+ },
99
+
100
+ "dry": {
101
+ "minLineThreshold": 5,
102
+ "similarityThreshold": 0.85,
103
+ "excludePatterns": [
104
+ "**/*.test.ts",
105
+ "**/*.spec.ts",
106
+ "**/tests/**",
107
+ "**/migrations/**"
108
+ ],
109
+ "checkImports": true,
110
+ "checkStrings": true
111
+ }
112
+ },
113
+
114
+ "customPatterns": {
115
+ "components": [
116
+ "**/app/**/page.{ts,tsx}",
117
+ "**/app/**/layout.{ts,tsx}",
118
+ "**/app/**/error.{ts,tsx}",
119
+ "**/app/**/loading.{ts,tsx}",
120
+ "**/app/**/not-found.{ts,tsx}",
121
+ "**/components/**/*.{ts,tsx}",
122
+ "**/app/components/**/*.{ts,tsx}"
123
+ ],
124
+ "endpoints": [
125
+ "**/app/api/**/route.{ts,tsx}",
126
+ "**/pages/api/**/*.{ts,tsx}",
127
+ "**/api/**/*.{ts,tsx}"
128
+ ],
129
+ "tests": [
130
+ "**/*.test.{ts,tsx}",
131
+ "**/*.spec.{ts,tsx}",
132
+ "**/tests/**",
133
+ "**/e2e/**",
134
+ "**/__tests__/**"
135
+ ]
136
+ },
137
+
138
+ "outputFormats": ["html", "json"],
139
+ "outputDirectory": "./audit-reports",
140
+
141
+ "minSeverity": "suggestion",
142
+ "failOnCritical": false,
143
+ "verbose": false,
144
+ "showProgress": true,
145
+
146
+ "thresholds": {
147
+ "maxCritical": 0,
148
+ "maxWarnings": 100,
149
+ "minHealthScore": 75,
150
+ "maxComplexity": 10,
151
+ "maxDuplication": 10
152
+ },
153
+
154
+ "reportTheme": {
155
+ "primaryColor": "#0070f3",
156
+ "criticalColor": "#e00",
157
+ "warningColor": "#f5a623",
158
+ "suggestionColor": "#0070f3"
159
+ },
160
+
161
+ "integrations": {
162
+ "ci": {
163
+ "provider": "github",
164
+ "failOnThreshold": true,
165
+ "commentOnPR": false
166
+ }
167
+ }
168
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Functional utilities for analyzer development
3
+ * These replace the BaseAnalyzer class with composable functions
4
+ */
5
+ import * as ts from 'typescript';
6
+ import { Violation, AnalyzerResult, SeverityLevel } from '../types.js';
7
+ export { parseTypeScriptFile } from '../utils/astParser.js';
8
+ export { getLineAndColumn, getNodeText, getImports, findNodesByKind } from '../utils/astUtils.js';
9
+ /**
10
+ * File analyzer function - processes a single file
11
+ */
12
+ export type FileAnalyzerFunction = (filePath: string, sourceFile: ts.SourceFile, config: any) => Promise<Violation[]> | Violation[];
13
+ /**
14
+ * Progress reporter function
15
+ */
16
+ export type ProgressReporter = (current: number, total: number, file: string) => void;
17
+ /**
18
+ * Standard file processing function
19
+ * Handles file reading, parsing, error handling, and progress reporting
20
+ */
21
+ export declare function processFiles(files: string[], analyzeFile: FileAnalyzerFunction, analyzerName: string, config?: any, progressReporter?: ProgressReporter): Promise<AnalyzerResult>;
22
+ /**
23
+ * Create a violation object with defaults
24
+ */
25
+ export declare function createViolation(data: Violation): Violation;
26
+ /**
27
+ * Get line and column from a TypeScript node
28
+ */
29
+ export declare function getNodePosition(sourceFile: ts.SourceFile, node: ts.Node): {
30
+ line: number;
31
+ column: number;
32
+ };
33
+ /**
34
+ * Check if a node is exported
35
+ */
36
+ export declare function isNodeExported(node: ts.Node): boolean;
37
+ /**
38
+ * Get the name of a node if it has one
39
+ */
40
+ export declare function getNodeName(node: ts.Node): string | undefined;
41
+ /**
42
+ * Count specific node types in a subtree
43
+ */
44
+ export declare function countNodesOfType<T extends ts.Node>(node: ts.Node, predicate: (node: ts.Node) => node is T): number;
45
+ /**
46
+ * Find all nodes of a specific type
47
+ */
48
+ export declare function findNodesOfType<T extends ts.Node>(node: ts.Node, predicate: (node: ts.Node) => node is T): T[];
49
+ /**
50
+ * Traverse AST with a visitor function
51
+ */
52
+ export declare function traverseAST(node: ts.Node, visitor: (node: ts.Node) => void): void;
53
+ /**
54
+ * Filter violations by severity
55
+ */
56
+ export declare function filterViolationsBySeverity(violations: Violation[], minSeverity?: SeverityLevel): Violation[];
57
+ /**
58
+ * Sort violations by severity, file, and line
59
+ */
60
+ export declare function sortViolations(violations: Violation[]): Violation[];
61
+ /**
62
+ * Calculate cyclomatic complexity of a function
63
+ */
64
+ export declare function calculateComplexity(node: ts.FunctionLikeDeclaration): number;
65
+ /**
66
+ * Create a standard analyzer function
67
+ */
68
+ export declare function createAnalyzer(name: string, fileAnalyzer: FileAnalyzerFunction, defaultConfig?: any): (files: any, config: any, options: any) => Promise<AnalyzerResult>;
69
+ //# sourceMappingURL=analyzerUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzerUtils.d.ts","sourceRoot":"","sources":["../../src/analyzers/analyzerUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;AAErF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CACjC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,MAAM,EAAE,GAAG,KACR,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;AAEtF;;;GAGG;AACH,wBAAsB,YAAY,CAChC,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,EAAE,oBAAoB,EACjC,YAAY,EAAE,MAAM,EACpB,MAAM,GAAE,GAAQ,EAChB,gBAAgB,CAAC,EAAE,gBAAgB,GAClC,OAAO,CAAC,cAAc,CAAC,CA6CzB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,SAAS,GACd,SAAS,CAEX;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,IAAI,EAAE,EAAE,CAAC,IAAI,GACZ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAGlC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAMrD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,GAAG,SAAS,CAQ7D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,EAAE,CAAC,IAAI,EAChD,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,GACtC,MAAM,CAYR;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,EAAE,CAAC,IAAI,EAC/C,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,GACtC,CAAC,EAAE,CAYL;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,GAC/B,IAAI,CAGN;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,SAAS,EAAE,EACvB,WAAW,CAAC,EAAE,aAAa,GAC1B,SAAS,EAAE,CAWb;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAcnE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,uBAAuB,GAAG,MAAM,CA4B5E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,oBAAoB,EAClC,aAAa,GAAE,GAAQ,IAET,UAAK,EAAE,WAAM,EAAE,YAAO,6BAWrC"}