UNPKG

ds-sfcoe-ailabs

Version:

AI-powered code review tool with static analysis integration for comprehensive code quality assessment.

84 lines (83 loc) 2.43 kB
import path from 'node:path'; import fse from 'fs-extra'; import { COMMAND_DEFAULTS } from '../../utils/constants.js'; /** * Abstract base class for Static Code Analysis Tool (SCAT) providers * Provides common functionality for code analysis tools that generate SARIF output */ export default class SCATProvider { scanDirectory; configFile; sarifFileName; /** * Creates a new SCAT provider instance * * @param scanDirectory - The directory to scan for code analysis * @param configFile - The configuration file path for the analyzer * @param sarifFileName - Optional custom SARIF output file name * @throws Error if scanDirectory or configFile are invalid * @example * ```typescript * class CustomSCATProvider extends SCATProvider { * constructor() { * super('/scan/dir', 'config.xml', 'custom.sarif'); * } * } * ``` */ constructor(scanDirectory, configFile, sarifFileName) { this.scanDirectory = scanDirectory; this.configFile = configFile; this.sarifFileName = sarifFileName ?? path.join(scanDirectory, COMMAND_DEFAULTS.DEFAULT_SARIF_FILE_NAME); } /** * Reads and parses the SARIF results file * * @returns Promise that resolves to the parsed SARIF log * @throws Error if SARIF file cannot be read or parsed * @example * ```typescript * const sarifLog = await this.getSarifFile(); * console.log(sarifLog.runs); * ``` */ async getSarifFile() { return (await fse.readJson(this.sarifFileName, 'utf-8')); } /** * Gets the SARIF output file name * * @returns The SARIF file name */ getSarifFileName() { return this.sarifFileName; } /** * Gets the configuration file path * * @returns The configuration file path * @example * ```typescript * const configPath = this.getConfigFile(); * console.log(configPath); // '/path/to/config.xml' * ``` */ getConfigFile() { return this.configFile; } /** * Gets the scan directory path * * @returns The scan directory path * @example * ```typescript * const scanDir = this.getScanDirectory(); * console.log(scanDir); // '/path/to/scan' * ``` */ getScanDirectory() { return this.scanDirectory; } }