refakts
Version:
TypeScript refactoring tool built for AI coding agents to perform precise refactoring operations via command line instead of requiring complete code regeneration.
35 lines • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.duplicationCheck = 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.duplicationCheck = {
name: 'duplication',
check: async () => {
try {
await execAsync('npx jscpd src --threshold 10 --reporters console --silent');
return [];
}
catch (error) {
return hasDuplication(error) ? createDuplicationIssue() : [];
}
},
getGroupDefinition: (groupKey) => groupKey === 'duplication' ? {
title: 'CODE DUPLICATION',
description: 'Duplicated code increases maintenance burden and error risk.',
actionGuidance: 'Extract common functionality into shared functions or classes.'
} : undefined
};
const hasDuplication = (error) => {
if (error && typeof error === 'object' && 'stdout' in error) {
const execError = error;
return execError.stdout?.includes('duplications found') ?? false;
}
return false;
};
const createDuplicationIssue = () => [{
type: 'duplication',
message: 'Code duplication detected. Look for missing abstractions - similar code patterns indicate shared concepts that should be extracted into reusable functions or classes.'
}];
//# sourceMappingURL=duplication-check.js.map