@aiready/core 0.7.14 → 0.8.1
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/dist/index.d.mts +292 -4
- package/dist/index.d.ts +292 -4
- package/dist/index.js +531 -2
- package/dist/index.mjs +522 -2
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -102,13 +102,173 @@ interface Report {
|
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Language-agnostic AST and parser interfaces for multi-language support
|
|
107
|
+
*
|
|
108
|
+
* This module provides abstractions for parsing different programming languages
|
|
109
|
+
* while maintaining a consistent interface for analysis tools.
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* Supported programming languages
|
|
113
|
+
*/
|
|
114
|
+
declare enum Language {
|
|
115
|
+
TypeScript = "typescript",
|
|
116
|
+
JavaScript = "javascript",
|
|
117
|
+
Python = "python",
|
|
118
|
+
Java = "java",
|
|
119
|
+
Go = "go",
|
|
120
|
+
Rust = "rust",
|
|
121
|
+
CSharp = "csharp"
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* File extensions mapped to languages
|
|
125
|
+
*/
|
|
126
|
+
declare const LANGUAGE_EXTENSIONS: Record<string, Language>;
|
|
127
|
+
/**
|
|
128
|
+
* Location information in source code
|
|
129
|
+
*/
|
|
130
|
+
interface SourceLocation {
|
|
131
|
+
line: number;
|
|
132
|
+
column: number;
|
|
133
|
+
}
|
|
134
|
+
interface SourceRange {
|
|
135
|
+
start: SourceLocation;
|
|
136
|
+
end: SourceLocation;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Common AST node type (language-agnostic)
|
|
140
|
+
*/
|
|
141
|
+
interface CommonASTNode {
|
|
142
|
+
type: string;
|
|
143
|
+
loc?: SourceRange;
|
|
144
|
+
raw?: any;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Export information (function, class, variable, etc.)
|
|
148
|
+
*/
|
|
149
|
+
interface ExportInfo {
|
|
150
|
+
name: string;
|
|
151
|
+
type: 'function' | 'class' | 'const' | 'type' | 'interface' | 'default' | 'variable';
|
|
152
|
+
loc?: SourceRange;
|
|
153
|
+
/** Imports used within this export */
|
|
154
|
+
imports?: string[];
|
|
155
|
+
/** Dependencies on other exports in same file */
|
|
156
|
+
dependencies?: string[];
|
|
157
|
+
/** TypeScript types referenced */
|
|
158
|
+
typeReferences?: string[];
|
|
159
|
+
/** For methods: parent class name */
|
|
160
|
+
parentClass?: string;
|
|
161
|
+
/** For functions/methods: parameters */
|
|
162
|
+
parameters?: string[];
|
|
163
|
+
/** Visibility (public, private, protected) */
|
|
164
|
+
visibility?: 'public' | 'private' | 'protected';
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Import information
|
|
168
|
+
*/
|
|
169
|
+
interface ImportInfo {
|
|
170
|
+
/** Module being imported from */
|
|
171
|
+
source: string;
|
|
172
|
+
/** What's being imported */
|
|
173
|
+
specifiers: string[];
|
|
174
|
+
/** Is this a type-only import (TypeScript) */
|
|
175
|
+
isTypeOnly?: boolean;
|
|
176
|
+
/** Location in source */
|
|
177
|
+
loc?: SourceRange;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Parse result containing exports and imports
|
|
181
|
+
*/
|
|
182
|
+
interface ParseResult {
|
|
183
|
+
exports: ExportInfo[];
|
|
184
|
+
imports: ImportInfo[];
|
|
185
|
+
/** Language of the parsed file */
|
|
186
|
+
language: Language;
|
|
187
|
+
/** Any parse warnings (non-fatal) */
|
|
188
|
+
warnings?: string[];
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Naming convention rules per language
|
|
192
|
+
*/
|
|
193
|
+
interface NamingConvention {
|
|
194
|
+
/** Allowed variable naming patterns */
|
|
195
|
+
variablePattern: RegExp;
|
|
196
|
+
/** Allowed function naming patterns */
|
|
197
|
+
functionPattern: RegExp;
|
|
198
|
+
/** Allowed class naming patterns */
|
|
199
|
+
classPattern: RegExp;
|
|
200
|
+
/** Allowed constant naming patterns */
|
|
201
|
+
constantPattern: RegExp;
|
|
202
|
+
/** Language-specific exceptions (e.g., __init__ in Python) */
|
|
203
|
+
exceptions?: string[];
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Language-specific configuration
|
|
207
|
+
*/
|
|
208
|
+
interface LanguageConfig {
|
|
209
|
+
language: Language;
|
|
210
|
+
/** File extensions for this language */
|
|
211
|
+
extensions: string[];
|
|
212
|
+
/** Naming conventions */
|
|
213
|
+
namingConventions: NamingConvention;
|
|
214
|
+
/** Common abbreviations allowed */
|
|
215
|
+
allowedAbbreviations?: string[];
|
|
216
|
+
/** Language-specific keywords to ignore */
|
|
217
|
+
keywords?: string[];
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Abstract interface for language parsers
|
|
221
|
+
* Each language implementation should implement this interface
|
|
222
|
+
*/
|
|
223
|
+
interface LanguageParser {
|
|
224
|
+
/** Language this parser handles */
|
|
225
|
+
readonly language: Language;
|
|
226
|
+
/** File extensions this parser supports */
|
|
227
|
+
readonly extensions: string[];
|
|
228
|
+
/**
|
|
229
|
+
* Parse source code and extract structure
|
|
230
|
+
* @param code - Source code to parse
|
|
231
|
+
* @param filePath - Path to the file (for context)
|
|
232
|
+
* @returns Parse result with exports and imports
|
|
233
|
+
* @throws ParseError if code has syntax errors
|
|
234
|
+
*/
|
|
235
|
+
parse(code: string, filePath: string): ParseResult;
|
|
236
|
+
/**
|
|
237
|
+
* Get naming conventions for this language
|
|
238
|
+
*/
|
|
239
|
+
getNamingConventions(): NamingConvention;
|
|
240
|
+
/**
|
|
241
|
+
* Check if this parser can handle a file
|
|
242
|
+
* @param filePath - File path to check
|
|
243
|
+
*/
|
|
244
|
+
canHandle(filePath: string): boolean;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Parser error with location information
|
|
248
|
+
*/
|
|
249
|
+
declare class ParseError extends Error {
|
|
250
|
+
readonly filePath: string;
|
|
251
|
+
readonly loc?: SourceLocation | undefined;
|
|
252
|
+
constructor(message: string, filePath: string, loc?: SourceLocation | undefined);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Statistics about parsed code
|
|
256
|
+
*/
|
|
257
|
+
interface ParseStatistics {
|
|
258
|
+
language: Language;
|
|
259
|
+
filesAnalyzed: number;
|
|
260
|
+
totalExports: number;
|
|
261
|
+
totalImports: number;
|
|
262
|
+
parseErrors: number;
|
|
263
|
+
warnings: number;
|
|
264
|
+
}
|
|
265
|
+
|
|
105
266
|
declare const DEFAULT_EXCLUDE: string[];
|
|
106
267
|
/**
|
|
107
268
|
* Scan files in a directory using glob patterns
|
|
108
269
|
*
|
|
109
|
-
* Note: This scanner
|
|
110
|
-
*
|
|
111
|
-
* should filter to their supported languages before processing.
|
|
270
|
+
* Note: This scanner supports multiple languages (.ts, .tsx, .js, .jsx, .py, .java, etc.)
|
|
271
|
+
* Individual tools can filter to their supported languages if needed.
|
|
112
272
|
*
|
|
113
273
|
* @param options - Scan configuration
|
|
114
274
|
* @returns Array of absolute file paths matching the patterns
|
|
@@ -324,4 +484,132 @@ declare function formatScore(result: ScoringResult): string;
|
|
|
324
484
|
*/
|
|
325
485
|
declare function formatToolScore(output: ToolScoringOutput): string;
|
|
326
486
|
|
|
327
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Parser Factory - Manages language-specific parsers
|
|
489
|
+
*
|
|
490
|
+
* This factory provides a centralized way to access the appropriate parser
|
|
491
|
+
* for a given file based on its extension.
|
|
492
|
+
*/
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Factory for creating and managing language parsers
|
|
496
|
+
*/
|
|
497
|
+
declare class ParserFactory {
|
|
498
|
+
private static instance;
|
|
499
|
+
private parsers;
|
|
500
|
+
private extensionMap;
|
|
501
|
+
private constructor();
|
|
502
|
+
/**
|
|
503
|
+
* Get singleton instance
|
|
504
|
+
*/
|
|
505
|
+
static getInstance(): ParserFactory;
|
|
506
|
+
/**
|
|
507
|
+
* Register a language parser
|
|
508
|
+
*/
|
|
509
|
+
registerParser(parser: LanguageParser): void;
|
|
510
|
+
/**
|
|
511
|
+
* Get parser for a specific language
|
|
512
|
+
*/
|
|
513
|
+
getParserForLanguage(language: Language): LanguageParser | null;
|
|
514
|
+
/**
|
|
515
|
+
* Get parser for a file based on its extension
|
|
516
|
+
*/
|
|
517
|
+
getParserForFile(filePath: string): LanguageParser | null;
|
|
518
|
+
/**
|
|
519
|
+
* Check if a file is supported
|
|
520
|
+
*/
|
|
521
|
+
isSupported(filePath: string): boolean;
|
|
522
|
+
/**
|
|
523
|
+
* Get all registered languages
|
|
524
|
+
*/
|
|
525
|
+
getSupportedLanguages(): Language[];
|
|
526
|
+
/**
|
|
527
|
+
* Get all supported file extensions
|
|
528
|
+
*/
|
|
529
|
+
getSupportedExtensions(): string[];
|
|
530
|
+
/**
|
|
531
|
+
* Get language for a file
|
|
532
|
+
*/
|
|
533
|
+
getLanguageForFile(filePath: string): Language | null;
|
|
534
|
+
/**
|
|
535
|
+
* Extract file extension (with dot)
|
|
536
|
+
*/
|
|
537
|
+
private getFileExtension;
|
|
538
|
+
/**
|
|
539
|
+
* Reset factory (useful for testing)
|
|
540
|
+
*/
|
|
541
|
+
static reset(): void;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Convenience function to get parser for a file
|
|
545
|
+
*/
|
|
546
|
+
declare function getParser(filePath: string): LanguageParser | null;
|
|
547
|
+
/**
|
|
548
|
+
* Convenience function to check if file is supported
|
|
549
|
+
*/
|
|
550
|
+
declare function isFileSupported(filePath: string): boolean;
|
|
551
|
+
/**
|
|
552
|
+
* Get all supported languages
|
|
553
|
+
*/
|
|
554
|
+
declare function getSupportedLanguages(): Language[];
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* TypeScript/JavaScript Parser
|
|
558
|
+
*
|
|
559
|
+
* Parses TypeScript and JavaScript files using @typescript-eslint/typescript-estree
|
|
560
|
+
*/
|
|
561
|
+
|
|
562
|
+
declare class TypeScriptParser implements LanguageParser {
|
|
563
|
+
readonly language = Language.TypeScript;
|
|
564
|
+
readonly extensions: string[];
|
|
565
|
+
parse(code: string, filePath: string): ParseResult;
|
|
566
|
+
getNamingConventions(): NamingConvention;
|
|
567
|
+
canHandle(filePath: string): boolean;
|
|
568
|
+
private extractImports;
|
|
569
|
+
private extractExports;
|
|
570
|
+
private extractFromDeclaration;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Python Parser using tree-sitter
|
|
575
|
+
*
|
|
576
|
+
* Parses Python files using tree-sitter-python for accurate AST parsing
|
|
577
|
+
*/
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Python Parser implementation
|
|
581
|
+
*
|
|
582
|
+
* Note: This implementation will use tree-sitter-python for parsing.
|
|
583
|
+
* For now, it provides a skeleton that can be filled in once web-tree-sitter
|
|
584
|
+
* is properly configured.
|
|
585
|
+
*/
|
|
586
|
+
declare class PythonParser implements LanguageParser {
|
|
587
|
+
readonly language = Language.Python;
|
|
588
|
+
readonly extensions: string[];
|
|
589
|
+
private parser;
|
|
590
|
+
private initialized;
|
|
591
|
+
/**
|
|
592
|
+
* Initialize the tree-sitter parser
|
|
593
|
+
* This is async because tree-sitter WASM needs to be loaded
|
|
594
|
+
*/
|
|
595
|
+
initialize(): Promise<void>;
|
|
596
|
+
parse(code: string, filePath: string): ParseResult;
|
|
597
|
+
getNamingConventions(): NamingConvention;
|
|
598
|
+
canHandle(filePath: string): boolean;
|
|
599
|
+
/**
|
|
600
|
+
* Regex-based import extraction (temporary implementation)
|
|
601
|
+
*/
|
|
602
|
+
private extractImportsRegex;
|
|
603
|
+
/**
|
|
604
|
+
* Regex-based export extraction (temporary implementation)
|
|
605
|
+
*
|
|
606
|
+
* Python doesn't have explicit exports like JavaScript.
|
|
607
|
+
* We extract:
|
|
608
|
+
* - Functions defined at module level (def)
|
|
609
|
+
* - Classes defined at module level (class)
|
|
610
|
+
* - Variables in __all__ list
|
|
611
|
+
*/
|
|
612
|
+
private extractExportsRegex;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export { type AIReadyConfig, type ASTNode, type AnalysisResult, type CLIOptions, type CommonASTNode, DEFAULT_EXCLUDE, DEFAULT_TOOL_WEIGHTS, type ExportInfo, type ExportWithImports, type FileImport, type ImportInfo, type Issue, type IssueType, LANGUAGE_EXTENSIONS, Language, type LanguageConfig, type LanguageParser, type Location, type Metrics, type NamingConvention, ParseError, type ParseResult, type ParseStatistics, ParserFactory, PythonParser, type Report, type ScanOptions, type ScoringConfig, type ScoringResult, type SourceLocation, type SourceRange, TOOL_NAME_MAP, type ToolScoringOutput, TypeScriptParser, calculateImportSimilarity, calculateOverallScore, estimateTokens, extractFunctions, extractImports, formatScore, formatToolScore, getElapsedTime, getFileExtension, getParser, getRating, getRatingDisplay, getSupportedLanguages, getToolWeight, handleCLIError, handleJSONOutput, isFileSupported, isSourceFile, loadConfig, loadMergedConfig, mergeConfigWithDefaults, normalizeToolName, parseCode, parseFileExports, parseWeightString, readFileContent, resolveOutputPath, scanFiles };
|
package/dist/index.d.ts
CHANGED
|
@@ -102,13 +102,173 @@ interface Report {
|
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Language-agnostic AST and parser interfaces for multi-language support
|
|
107
|
+
*
|
|
108
|
+
* This module provides abstractions for parsing different programming languages
|
|
109
|
+
* while maintaining a consistent interface for analysis tools.
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* Supported programming languages
|
|
113
|
+
*/
|
|
114
|
+
declare enum Language {
|
|
115
|
+
TypeScript = "typescript",
|
|
116
|
+
JavaScript = "javascript",
|
|
117
|
+
Python = "python",
|
|
118
|
+
Java = "java",
|
|
119
|
+
Go = "go",
|
|
120
|
+
Rust = "rust",
|
|
121
|
+
CSharp = "csharp"
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* File extensions mapped to languages
|
|
125
|
+
*/
|
|
126
|
+
declare const LANGUAGE_EXTENSIONS: Record<string, Language>;
|
|
127
|
+
/**
|
|
128
|
+
* Location information in source code
|
|
129
|
+
*/
|
|
130
|
+
interface SourceLocation {
|
|
131
|
+
line: number;
|
|
132
|
+
column: number;
|
|
133
|
+
}
|
|
134
|
+
interface SourceRange {
|
|
135
|
+
start: SourceLocation;
|
|
136
|
+
end: SourceLocation;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Common AST node type (language-agnostic)
|
|
140
|
+
*/
|
|
141
|
+
interface CommonASTNode {
|
|
142
|
+
type: string;
|
|
143
|
+
loc?: SourceRange;
|
|
144
|
+
raw?: any;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Export information (function, class, variable, etc.)
|
|
148
|
+
*/
|
|
149
|
+
interface ExportInfo {
|
|
150
|
+
name: string;
|
|
151
|
+
type: 'function' | 'class' | 'const' | 'type' | 'interface' | 'default' | 'variable';
|
|
152
|
+
loc?: SourceRange;
|
|
153
|
+
/** Imports used within this export */
|
|
154
|
+
imports?: string[];
|
|
155
|
+
/** Dependencies on other exports in same file */
|
|
156
|
+
dependencies?: string[];
|
|
157
|
+
/** TypeScript types referenced */
|
|
158
|
+
typeReferences?: string[];
|
|
159
|
+
/** For methods: parent class name */
|
|
160
|
+
parentClass?: string;
|
|
161
|
+
/** For functions/methods: parameters */
|
|
162
|
+
parameters?: string[];
|
|
163
|
+
/** Visibility (public, private, protected) */
|
|
164
|
+
visibility?: 'public' | 'private' | 'protected';
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Import information
|
|
168
|
+
*/
|
|
169
|
+
interface ImportInfo {
|
|
170
|
+
/** Module being imported from */
|
|
171
|
+
source: string;
|
|
172
|
+
/** What's being imported */
|
|
173
|
+
specifiers: string[];
|
|
174
|
+
/** Is this a type-only import (TypeScript) */
|
|
175
|
+
isTypeOnly?: boolean;
|
|
176
|
+
/** Location in source */
|
|
177
|
+
loc?: SourceRange;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Parse result containing exports and imports
|
|
181
|
+
*/
|
|
182
|
+
interface ParseResult {
|
|
183
|
+
exports: ExportInfo[];
|
|
184
|
+
imports: ImportInfo[];
|
|
185
|
+
/** Language of the parsed file */
|
|
186
|
+
language: Language;
|
|
187
|
+
/** Any parse warnings (non-fatal) */
|
|
188
|
+
warnings?: string[];
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Naming convention rules per language
|
|
192
|
+
*/
|
|
193
|
+
interface NamingConvention {
|
|
194
|
+
/** Allowed variable naming patterns */
|
|
195
|
+
variablePattern: RegExp;
|
|
196
|
+
/** Allowed function naming patterns */
|
|
197
|
+
functionPattern: RegExp;
|
|
198
|
+
/** Allowed class naming patterns */
|
|
199
|
+
classPattern: RegExp;
|
|
200
|
+
/** Allowed constant naming patterns */
|
|
201
|
+
constantPattern: RegExp;
|
|
202
|
+
/** Language-specific exceptions (e.g., __init__ in Python) */
|
|
203
|
+
exceptions?: string[];
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Language-specific configuration
|
|
207
|
+
*/
|
|
208
|
+
interface LanguageConfig {
|
|
209
|
+
language: Language;
|
|
210
|
+
/** File extensions for this language */
|
|
211
|
+
extensions: string[];
|
|
212
|
+
/** Naming conventions */
|
|
213
|
+
namingConventions: NamingConvention;
|
|
214
|
+
/** Common abbreviations allowed */
|
|
215
|
+
allowedAbbreviations?: string[];
|
|
216
|
+
/** Language-specific keywords to ignore */
|
|
217
|
+
keywords?: string[];
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Abstract interface for language parsers
|
|
221
|
+
* Each language implementation should implement this interface
|
|
222
|
+
*/
|
|
223
|
+
interface LanguageParser {
|
|
224
|
+
/** Language this parser handles */
|
|
225
|
+
readonly language: Language;
|
|
226
|
+
/** File extensions this parser supports */
|
|
227
|
+
readonly extensions: string[];
|
|
228
|
+
/**
|
|
229
|
+
* Parse source code and extract structure
|
|
230
|
+
* @param code - Source code to parse
|
|
231
|
+
* @param filePath - Path to the file (for context)
|
|
232
|
+
* @returns Parse result with exports and imports
|
|
233
|
+
* @throws ParseError if code has syntax errors
|
|
234
|
+
*/
|
|
235
|
+
parse(code: string, filePath: string): ParseResult;
|
|
236
|
+
/**
|
|
237
|
+
* Get naming conventions for this language
|
|
238
|
+
*/
|
|
239
|
+
getNamingConventions(): NamingConvention;
|
|
240
|
+
/**
|
|
241
|
+
* Check if this parser can handle a file
|
|
242
|
+
* @param filePath - File path to check
|
|
243
|
+
*/
|
|
244
|
+
canHandle(filePath: string): boolean;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Parser error with location information
|
|
248
|
+
*/
|
|
249
|
+
declare class ParseError extends Error {
|
|
250
|
+
readonly filePath: string;
|
|
251
|
+
readonly loc?: SourceLocation | undefined;
|
|
252
|
+
constructor(message: string, filePath: string, loc?: SourceLocation | undefined);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Statistics about parsed code
|
|
256
|
+
*/
|
|
257
|
+
interface ParseStatistics {
|
|
258
|
+
language: Language;
|
|
259
|
+
filesAnalyzed: number;
|
|
260
|
+
totalExports: number;
|
|
261
|
+
totalImports: number;
|
|
262
|
+
parseErrors: number;
|
|
263
|
+
warnings: number;
|
|
264
|
+
}
|
|
265
|
+
|
|
105
266
|
declare const DEFAULT_EXCLUDE: string[];
|
|
106
267
|
/**
|
|
107
268
|
* Scan files in a directory using glob patterns
|
|
108
269
|
*
|
|
109
|
-
* Note: This scanner
|
|
110
|
-
*
|
|
111
|
-
* should filter to their supported languages before processing.
|
|
270
|
+
* Note: This scanner supports multiple languages (.ts, .tsx, .js, .jsx, .py, .java, etc.)
|
|
271
|
+
* Individual tools can filter to their supported languages if needed.
|
|
112
272
|
*
|
|
113
273
|
* @param options - Scan configuration
|
|
114
274
|
* @returns Array of absolute file paths matching the patterns
|
|
@@ -324,4 +484,132 @@ declare function formatScore(result: ScoringResult): string;
|
|
|
324
484
|
*/
|
|
325
485
|
declare function formatToolScore(output: ToolScoringOutput): string;
|
|
326
486
|
|
|
327
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Parser Factory - Manages language-specific parsers
|
|
489
|
+
*
|
|
490
|
+
* This factory provides a centralized way to access the appropriate parser
|
|
491
|
+
* for a given file based on its extension.
|
|
492
|
+
*/
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Factory for creating and managing language parsers
|
|
496
|
+
*/
|
|
497
|
+
declare class ParserFactory {
|
|
498
|
+
private static instance;
|
|
499
|
+
private parsers;
|
|
500
|
+
private extensionMap;
|
|
501
|
+
private constructor();
|
|
502
|
+
/**
|
|
503
|
+
* Get singleton instance
|
|
504
|
+
*/
|
|
505
|
+
static getInstance(): ParserFactory;
|
|
506
|
+
/**
|
|
507
|
+
* Register a language parser
|
|
508
|
+
*/
|
|
509
|
+
registerParser(parser: LanguageParser): void;
|
|
510
|
+
/**
|
|
511
|
+
* Get parser for a specific language
|
|
512
|
+
*/
|
|
513
|
+
getParserForLanguage(language: Language): LanguageParser | null;
|
|
514
|
+
/**
|
|
515
|
+
* Get parser for a file based on its extension
|
|
516
|
+
*/
|
|
517
|
+
getParserForFile(filePath: string): LanguageParser | null;
|
|
518
|
+
/**
|
|
519
|
+
* Check if a file is supported
|
|
520
|
+
*/
|
|
521
|
+
isSupported(filePath: string): boolean;
|
|
522
|
+
/**
|
|
523
|
+
* Get all registered languages
|
|
524
|
+
*/
|
|
525
|
+
getSupportedLanguages(): Language[];
|
|
526
|
+
/**
|
|
527
|
+
* Get all supported file extensions
|
|
528
|
+
*/
|
|
529
|
+
getSupportedExtensions(): string[];
|
|
530
|
+
/**
|
|
531
|
+
* Get language for a file
|
|
532
|
+
*/
|
|
533
|
+
getLanguageForFile(filePath: string): Language | null;
|
|
534
|
+
/**
|
|
535
|
+
* Extract file extension (with dot)
|
|
536
|
+
*/
|
|
537
|
+
private getFileExtension;
|
|
538
|
+
/**
|
|
539
|
+
* Reset factory (useful for testing)
|
|
540
|
+
*/
|
|
541
|
+
static reset(): void;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Convenience function to get parser for a file
|
|
545
|
+
*/
|
|
546
|
+
declare function getParser(filePath: string): LanguageParser | null;
|
|
547
|
+
/**
|
|
548
|
+
* Convenience function to check if file is supported
|
|
549
|
+
*/
|
|
550
|
+
declare function isFileSupported(filePath: string): boolean;
|
|
551
|
+
/**
|
|
552
|
+
* Get all supported languages
|
|
553
|
+
*/
|
|
554
|
+
declare function getSupportedLanguages(): Language[];
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* TypeScript/JavaScript Parser
|
|
558
|
+
*
|
|
559
|
+
* Parses TypeScript and JavaScript files using @typescript-eslint/typescript-estree
|
|
560
|
+
*/
|
|
561
|
+
|
|
562
|
+
declare class TypeScriptParser implements LanguageParser {
|
|
563
|
+
readonly language = Language.TypeScript;
|
|
564
|
+
readonly extensions: string[];
|
|
565
|
+
parse(code: string, filePath: string): ParseResult;
|
|
566
|
+
getNamingConventions(): NamingConvention;
|
|
567
|
+
canHandle(filePath: string): boolean;
|
|
568
|
+
private extractImports;
|
|
569
|
+
private extractExports;
|
|
570
|
+
private extractFromDeclaration;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Python Parser using tree-sitter
|
|
575
|
+
*
|
|
576
|
+
* Parses Python files using tree-sitter-python for accurate AST parsing
|
|
577
|
+
*/
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Python Parser implementation
|
|
581
|
+
*
|
|
582
|
+
* Note: This implementation will use tree-sitter-python for parsing.
|
|
583
|
+
* For now, it provides a skeleton that can be filled in once web-tree-sitter
|
|
584
|
+
* is properly configured.
|
|
585
|
+
*/
|
|
586
|
+
declare class PythonParser implements LanguageParser {
|
|
587
|
+
readonly language = Language.Python;
|
|
588
|
+
readonly extensions: string[];
|
|
589
|
+
private parser;
|
|
590
|
+
private initialized;
|
|
591
|
+
/**
|
|
592
|
+
* Initialize the tree-sitter parser
|
|
593
|
+
* This is async because tree-sitter WASM needs to be loaded
|
|
594
|
+
*/
|
|
595
|
+
initialize(): Promise<void>;
|
|
596
|
+
parse(code: string, filePath: string): ParseResult;
|
|
597
|
+
getNamingConventions(): NamingConvention;
|
|
598
|
+
canHandle(filePath: string): boolean;
|
|
599
|
+
/**
|
|
600
|
+
* Regex-based import extraction (temporary implementation)
|
|
601
|
+
*/
|
|
602
|
+
private extractImportsRegex;
|
|
603
|
+
/**
|
|
604
|
+
* Regex-based export extraction (temporary implementation)
|
|
605
|
+
*
|
|
606
|
+
* Python doesn't have explicit exports like JavaScript.
|
|
607
|
+
* We extract:
|
|
608
|
+
* - Functions defined at module level (def)
|
|
609
|
+
* - Classes defined at module level (class)
|
|
610
|
+
* - Variables in __all__ list
|
|
611
|
+
*/
|
|
612
|
+
private extractExportsRegex;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export { type AIReadyConfig, type ASTNode, type AnalysisResult, type CLIOptions, type CommonASTNode, DEFAULT_EXCLUDE, DEFAULT_TOOL_WEIGHTS, type ExportInfo, type ExportWithImports, type FileImport, type ImportInfo, type Issue, type IssueType, LANGUAGE_EXTENSIONS, Language, type LanguageConfig, type LanguageParser, type Location, type Metrics, type NamingConvention, ParseError, type ParseResult, type ParseStatistics, ParserFactory, PythonParser, type Report, type ScanOptions, type ScoringConfig, type ScoringResult, type SourceLocation, type SourceRange, TOOL_NAME_MAP, type ToolScoringOutput, TypeScriptParser, calculateImportSimilarity, calculateOverallScore, estimateTokens, extractFunctions, extractImports, formatScore, formatToolScore, getElapsedTime, getFileExtension, getParser, getRating, getRatingDisplay, getSupportedLanguages, getToolWeight, handleCLIError, handleJSONOutput, isFileSupported, isSourceFile, loadConfig, loadMergedConfig, mergeConfigWithDefaults, normalizeToolName, parseCode, parseFileExports, parseWeightString, readFileContent, resolveOutputPath, scanFiles };
|