UNPKG

jscpd

Version:

Copy/paste detector for programming code, support JavaScript, CoffeeScript, PHP, Ruby, Python, Less, Go, Java, Yaml, C#, C++, C languages

84 lines (77 loc) 3.01 kB
// Generated by CoffeeScript 1.10.0 (function() { var TABLE_CONFIGURATION, Table, compareDates; require('colors'); Table = require('cli-table'); TABLE_CONFIGURATION = { chars: { 'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': '', 'top': '', 'top-mid': '', 'top-left': '', 'top-right': '', 'bottom': '', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': '', 'left': '', 'right': '' } }; compareDates = function(firstDate, secondDate) { firstDate = new Date(firstDate); secondDate = new Date(secondDate); switch (true) { case firstDate < secondDate: return "=>"; case firstDate > secondDate: return "<="; default: return "=="; } }; module.exports = function() { var clog, clone, fn, i, len, log, percent, ref, verbose; clog = ''; verbose = this.options.verbose || this.options.blame; ref = this.map.clones; fn = function(clone) { var firstFile, fragment, secondFile, table; table = new Table(TABLE_CONFIGURATION); firstFile = clone.firstFile; secondFile = clone.secondFile; if (verbose) { fragment = clone.getLines().split("\n").reduce(function(tbl, current, lineNumber) { var firstFileLine, secondFileLine; firstFileLine = clone.firstFileStart + lineNumber; secondFileLine = clone.secondFileStart + lineNumber; if (Object.keys(clone.firstFileAnnotatedCode).length > 0) { tbl.push([firstFileLine, clone.firstFileAnnotatedCode[firstFileLine].author, compareDates(clone.firstFileAnnotatedCode[firstFileLine].date, clone.secondFileAnnotatedCode[secondFileLine].date), secondFileLine, clone.secondFileAnnotatedCode[secondFileLine].author, current.dim]); } else { tbl.push([firstFileLine, secondFileLine, current.dim]); } return tbl; }, table); } clog = clog + "\n\t- " + firstFile.green.bold + ": " + clone.firstFileStart + "-" + (clone.firstFileStart + clone.linesCount) + "\n\t " + secondFile.green.bold + ": " + clone.secondFileStart + "-" + (clone.secondFileStart + clone.linesCount) + "\n"; if (verbose) { return clog = clog + "\n" + (fragment.toString()) + "\n"; } }; for (i = 0, len = ref.length; i < len; i++) { clone = ref[i]; fn(clone); } percent = this.map.getPercentage(); log = "Found " + this.map.clones.length + " exact clones with " + this.map.numberOfDuplication + " duplicated lines in " + this.map.numberOfFiles + " files\n " + clog + "\n\n " + percent + "% (" + this.map.numberOfDuplication + " lines) duplicated lines out of " + this.map.numberOfLines + " total lines of code.\n"; if (this.options.limit <= percent) { console.error(log); console.error("ERROR: jscpd found too many duplicates over threshold"); process.exit(1); } return log; }; }).call(this);