forked from kucherenko/jscpd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca40bf2
commit e231a64
Showing
5 changed files
with
57 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
shjs = require "shelljs" | ||
|
||
class Clone | ||
constructor: (@firstFile, @secondFile, @firstFileStart, @secondFileStart, @linesCount, @tokensCount)-> | ||
|
||
getLines: -> | ||
console.log "getLines" | ||
code = shjs.cat(@firstFile) | ||
lines = code.split '\n' | ||
start = @firstFileStart | ||
end = start + @linesCount | ||
lines[start..end].join("\n") | ||
|
||
exports.Clone = Clone | ||
exports.Clone = Clone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
|
||
jade = require('jade').runtime | ||
fs = require 'fs' | ||
class Report | ||
|
||
constructor: (@options) -> | ||
|
||
generate: (@map) -> | ||
result = "" | ||
xmlDoc = false | ||
if @options.output | ||
xmlDoc = "<?xml version=\"1.1\" encoding=\"UTF-8\" ?><pmd-cpd>" | ||
verbose = @options.verbose | ||
for clone in @map.clones | ||
do (clone) -> | ||
result = result + "\n\t- #{clone.firstFile}:#{clone.firstFileStart}-#{clone.firstFileStart + clone.linesCount}\n\t" + | ||
" #{clone.secondFile}:#{clone.secondFileStart}-#{clone.secondFileStart + clone.linesCount}\n\t" | ||
result = "#{result}\n#{clone.getLines()}" if verbose | ||
|
||
if xmlDoc | ||
xmlDoc = xmlDoc + | ||
"<duplication lines='" + clone.linesCount + "' tokens='" + clone.tokensCount + "'>" + | ||
"<file path='" + clone.firstFile + "' line='" + clone.firstFileStart + "'/>" + | ||
"<file path='" + clone.secondFile + "' line='" + clone.secondFileStart + "'/>" + | ||
"<codefragment>" + jade.escape(clone.getLines()) + "</codefragment></duplication>" | ||
|
||
if xmlDoc | ||
xmlDoc = xmlDoc + "</pmd-cpd>"; | ||
fs.writeFileSync(@options.output, xmlDoc) | ||
|
||
result = "Found #{@map.clones.length} exact clones with #{@map.numberOfDuplication} duplicated lines in #{@map.numberOfFiles} files\n #{result}" | ||
console.log result | ||
|
||
exports.Report = Report | ||
console.log "#{result}\n\n #{@map.getPercentage()}% (#{@map.numberOfDuplication} lines) duplicated lines out of #{@map.numberOfLines} total lines of code.\n" | ||
|
||
|
||
exports.Report = Report |