| 68 | } |
| 69 | |
| 70 | function validateAbstraction(lines: string[]): ValidationError[] { |
| 71 | const errors: ValidationError[] = []; |
| 72 | let nestingDepth = 0; |
| 73 | let maxNesting = 0; |
| 74 | |
| 75 | for (let i = 0; i < lines.length; i++) { |
| 76 | const line = lines[i]; |
| 77 | nestingDepth += (line.match(/{/g) || []).length; |
| 78 | nestingDepth -= (line.match(/}/g) || []).length; |
| 79 | maxNesting = Math.max(maxNesting, nestingDepth); |
| 80 | } |
| 81 | |
| 82 | if (maxNesting > 6) { |
| 83 | errors.push({ |
| 84 | rule: "nesting", |
| 85 | message: `Nesting depth of ${maxNesting} detected. Maximum recommended is 3-4 levels. Flatten the structure.`, |
| 86 | }); |
| 87 | } |
| 88 | |
| 89 | if (lines.length > 1000) { |
| 90 | errors.push({ |
| 91 | rule: "file-length", |
| 92 | message: `File is ${lines.length} lines. Maximum recommended is 500-1000. Consider splitting.`, |
| 93 | }); |
| 94 | } |
| 95 | |
| 96 | return errors; |
| 97 | } |
| 98 | |
| 99 | export async function proposeCommit(options: ProposeCommitOptions): Promise<string> { |
| 100 | const fullPath = resolve(options.rootDir, options.filePath); |