UNPKG

ccguard

Version:

Automated enforcement of net-negative LOC, complexity constraints, and quality standards for Claude code

80 lines 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LocCounter = void 0; class LocCounter { ignoreEmptyLines; constructor(options = {}) { this.ignoreEmptyLines = options.ignoreEmptyLines ?? true; } /** * Count lines of code in a string */ countLines(content) { if (!content) return 0; const lines = content.split('\n'); if (this.ignoreEmptyLines) { return lines.filter(line => line.trim().length > 0).length; } return lines.length; } /** * Calculate LOC change for an Edit operation */ calculateEditChange(input) { const linesRemoved = this.countLines(input.old_string); const linesAdded = this.countLines(input.new_string); return { linesAdded, linesRemoved, netChange: linesAdded - linesRemoved }; } /** * Calculate LOC change for a MultiEdit operation */ calculateMultiEditChange(input) { let totalAdded = 0; let totalRemoved = 0; // Process each edit in sequence for (const edit of input.edits) { const linesRemoved = this.countLines(edit.old_string); const linesAdded = this.countLines(edit.new_string); totalRemoved += linesRemoved; totalAdded += linesAdded; } return { linesAdded: totalAdded, linesRemoved: totalRemoved, netChange: totalAdded - totalRemoved }; } /** * Calculate LOC change for a Write operation (new file) */ calculateWriteChange(input) { const linesAdded = this.countLines(input.content); return { linesAdded, linesRemoved: 0, netChange: linesAdded }; } /** * Calculate LOC change for any operation type */ calculateChange(toolName, input) { switch (toolName) { case 'Edit': return this.calculateEditChange(input); case 'MultiEdit': return this.calculateMultiEditChange(input); case 'Write': return this.calculateWriteChange(input); default: throw new Error(`Unknown tool: ${toolName}`); } } } exports.LocCounter = LocCounter; //# sourceMappingURL=locCounter.js.map