UNPKG

sfcoe-ailabs

Version:

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

63 lines (62 loc) 1.91 kB
import * as path from 'node:path'; import { TEST_PATTERNS, LAST_EXTENSION_REGEX } from './constants.js'; /** * File utility functions for common operations */ export class FileUtils { /** * Extract filename from a file path */ static getFileName(filePath) { return filePath.split('/').pop() ?? filePath; } /** * Get file extension from a file path */ static getFileExtension(filePath) { return path.extname(filePath).toLowerCase(); } /** * Check if a file is a JavaScript/TypeScript file */ static isJavaScriptFile(filePath) { const extension = this.getFileExtension(filePath); return /\.(js|ts|mjs|cjs)$/i.test(extension); } /** * Check if a file is an Apex file */ static isApexFile(filePath) { const extension = this.getFileExtension(filePath); return extension === '.cls' || extension === '.trigger'; } /** * Check if a file is a test file based on filename or content */ static isTestFile(filePath, content) { const fileName = this.getFileName(filePath); const isTestFileName = fileName .toLowerCase() .includes(TEST_PATTERNS.TEST_FILE_PATTERN); const hasTestAnnotation = content?.includes(TEST_PATTERNS.APEX_TEST_ANNOTATION) ?? false; return isTestFileName || hasTestAnnotation; } /** * Normalize file path for consistent comparison */ static normalizePath(filePath) { return path.normalize(filePath); } /** * Create a unique entry key for deduplication */ static createEntryKey(fileName, ruleId, lineNumber) { return `${fileName}-${ruleId}-${lineNumber}`; } /** * Remove file extension from filename */ static removeExtension(fileName) { return fileName.replace(LAST_EXTENSION_REGEX, ''); } }