| |
| |
| |
| |
| |
|
|
|
|
| |
| |
|
|
| export function normalizeReviewLanguage(text: string): string {
|
| if (!text) return ''
|
|
|
| let normalized = text
|
|
|
|
|
| const weakPhrases = [
|
| /\bmay cause (?:unexpected )?(?:issues?|problems?|behavior)\b/gi,
|
| /\bplease note,?\s*/gi,
|
| /\bit's recommended that\s*/gi,
|
| /\bit is recommended that\s*/gi
|
| ]
|
|
|
| for (const phrase of weakPhrases) {
|
| normalized = normalized.replace(phrase, '')
|
| }
|
|
|
|
|
| normalized = normalized.replace(
|
| /\binconsistent indentation\b/gi,
|
| 'incorrect indentation'
|
| )
|
|
|
|
|
| normalized = normalized.replace(/\s+/g, ' ').trim()
|
|
|
| return normalized
|
| }
|
|
|
| |
| |
|
|
| export function stripMarkdown(text: string): string {
|
| if (!text) return ''
|
|
|
| return text
|
| .replace(/```[\s\S]*?```/g, '')
|
| .replace(/\*\*/g, '')
|
| .replace(/\*/g, '')
|
| .replace(/`/g, '')
|
| .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
|
| .trim()
|
| }
|
|
|
| |
| |
|
|
| export function extractKeyTerms(text: string, limit: number = 5): string {
|
| if (!text) return ''
|
|
|
| const normalized = normalizeReviewLanguage(text)
|
| const words = normalized.split(' ').filter(w => w.length > 3)
|
|
|
| return words.slice(0, limit).join(' ')
|
| }
|
|
|
| |
| |
|
|
| export function cleanDescription(text: string): string {
|
| if (!text) return ''
|
|
|
| let cleaned = stripMarkdown(text)
|
| cleaned = normalizeReviewLanguage(cleaned)
|
|
|
|
|
| cleaned = cleaned.replace(/confidence\s*:\s*(high|medium|low)/gi, '')
|
|
|
| return cleaned.trim()
|
| }
|
|
|
| |
| |
|
|
| export function generateMinimalDescription(
|
| description: string,
|
| type: string,
|
| context?: {variableName?: string; functionName?: string}
|
| ): string {
|
| let minimal = cleanDescription(description)
|
|
|
|
|
| if (context?.functionName) {
|
| minimal = `In \`${context.functionName}\`, ${minimal.charAt(0).toLowerCase() + minimal.slice(1)}`
|
| }
|
|
|
|
|
| minimal = minimal.charAt(0).toUpperCase() + minimal.slice(1)
|
|
|
|
|
| minimal = minimal.replace(/\.$/, '')
|
|
|
| return minimal
|
| }
|
|
|