Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function reporterOrigin(options) {
// Calling the origin reporter
const jsonReporterResult = jsonReporter.call(this, options);
const percentage = this.map.getPercentage();
const limit = options.limit;
// The log is the third args of the return array, which will output to the stdout
const log = getPercentageLog({
percentage,
limit
});
if (percentage > limit) {
// If the percentage is greater than limit, then we just output the log and exit the process. Keep the logic same with _std-log.coffee
console.error(log);
process.exit(1);
}
// The first one is the output json
function jscpdReporter(options) {
// Pass filterFiles option will enhance the result with an extro property: filterDuplicates
const filterFiles = options.filterFiles;
// If no filterFiles is passed, then we just return the origin report with our custom logger
if (typeof filterFiles === 'undefined' || filterFiles.length === 0) {
return reporterOrigin.call(this, options);
}
// Calling the origin reporter and add an extro property filterDuplicates
const jsonReporterResult = jsonReporter.call(this, options);
// Get the filterClones
const filterClones = this.map.clones.filter(({ firstFile, secendFile }) => {
for (let i = 0; i < filterFiles.length; i++) {
// If the filepath is same, then return true
if (filterFiles[i] === firstFile || filterFiles[i] === secendFile) {
return true;
}
}
return false;
});
const filterDuplicates = filterClones.map((clone) => {
// Keep the structure same with duplicates property
return {
lines: clone.linesCount,