refakts
Version:
TypeScript refactoring tool built for AI coding agents to perform precise refactoring operations via command line instead of requiring complete code regeneration.
42 lines • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.gitDiffCheck = void 0;
const child_process_1 = require("child_process");
const util_1 = require("util");
const execAsync = (0, util_1.promisify)(child_process_1.exec);
exports.gitDiffCheck = {
name: 'diffSize',
check: async (sourceDir) => {
const diffResult = await checkGitDiffSize();
return diffResult.message ? [createDiffIssue(diffResult.message)] : [];
},
getGroupDefinition: (groupKey) => groupKey === 'diffSize' ? {
title: 'LARGE CHANGES',
description: 'Large diffs are harder to review and more likely to introduce bugs.',
actionGuidance: 'Commit smaller incremental changes with passing tests to maintain code quality.'
} : undefined
};
const checkGitDiffSize = async () => {
try {
const { stdout } = await execAsync('git diff --stat');
const lines = stdout.split('\n');
const summaryLine = lines[lines.length - 2];
if (!summaryLine)
return {};
const match = summaryLine.match(/(\d+) insertions?\(\+\), (\d+) deletions?\(-\)/);
if (!match)
return {};
const totalChanges = parseInt(match[1]) + parseInt(match[2]);
return totalChanges > 200 ? {
message: 'STOP! Your diff is over 200 lines. This is too much change at once. Revert to last commit and break this into smaller steps with passing tests between each step.'
} : {};
}
catch (error) {
return {};
}
};
const createDiffIssue = (message) => ({
type: 'diffSize',
message: message
});
//# sourceMappingURL=git-diff-check.js.map