ds-sfcoe-ailabs
Version:
AI-powered code review tool with static analysis integration for comprehensive code quality assessment.
53 lines (52 loc) • 2.02 kB
JavaScript
import { SCATProviderType, SFCodeAnalyzer, PMDCodeAnalyzer, } from './index.js';
/**
* Factory class for creating Static Code Analysis Tool (SCAT) provider instances
*
* Provides a centralized way to create appropriate SCAT provider implementations
* based on the specified provider type. Supports SFCodeAnalyzer and PMDCodeAnalyzer.
*
* @example
* ```typescript
* const provider = SCATProviderFactory.getInstance(
* SCATProviderType.SFCodeAnalyzer,
* '/path/to/scan',
* '/path/to/config'
* );
* const results = await provider.run();
* ```
*/
export default class SCATProviderFactory {
/**
* Gets a SCAT provider instance
*
* @param type - The type of SCAT provider to create
* @param scanDirectory - The directory to scan for code analysis
* @param configFile - Optional configuration file path for the analyzer
* @param fileList - Optional array of specific files to analyze (for PMD)
* @returns An instance of the specified SCAT provider
* @throws Error when the provider type is unsupported or required parameters are missing
* @example
* ```typescript
* const provider = SCATProviderFactory.getInstance(
* SCATProviderType.PMDCodeAnalyzer,
* '/src',
* 'pmd-ruleset.xml',
* ['Class1.cls', 'Class2.cls']
* );
* const results = await provider.run();
* ```
*/
static getInstance(type, scanDirectory, configFile, fileList) {
switch (type) {
case SCATProviderType.SFCodeAnalyzer:
return new SFCodeAnalyzer(scanDirectory, configFile);
case SCATProviderType.PMDCodeAnalyzer:
if (!configFile || !fileList) {
throw new Error('PMDCodeAnalyzer requires both configFile and fileList parameters');
}
return new PMDCodeAnalyzer(scanDirectory, configFile, fileList);
default:
throw new Error(`Unsupported SCAT provider type: ${type}`);
}
}
}