Files
Roo-Code/src/integrations/editor/detect-omission.ts
2024-12-08 10:51:40 -05:00

34 lines
1.1 KiB
TypeScript

/**
* Detects potential AI-generated code omissions in the given file content.
* @param originalFileContent The original content of the file.
* @param newFileContent The new content of the file to check.
* @returns True if a potential omission is detected, false otherwise.
*/
export function detectCodeOmission(originalFileContent: string, newFileContent: string): boolean {
const originalLines = originalFileContent.split("\n")
const newLines = newFileContent.split("\n")
const omissionKeywords = ["remain", "remains", "unchanged", "rest", "previous", "existing", "..."]
const commentPatterns = [
/^\s*\/\//, // Single-line comment for most languages
/^\s*#/, // Single-line comment for Python, Ruby, etc.
/^\s*\/\*/, // Multi-line comment opening
/^\s*{\s*\/\*/, // JSX comment opening
/^\s*<!--/, // HTML comment opening
]
for (const line of newLines) {
if (commentPatterns.some((pattern) => pattern.test(line))) {
const words = line.toLowerCase().split(/\s+/)
if (omissionKeywords.some((keyword) => words.includes(keyword))) {
if (!originalLines.includes(line)) {
return true
}
}
}
}
return false
}