Comments (18)
Do you have any documentation on the expected XML format? And are tokens mandatory? Because jsinspect specifically avoids considering tokens as part of its parsing.
from jsinspect.
I don't know of any documentation. The best I can give you is the original pmd-cpd source code (http://sourceforge.net/p/pmd/code/ci/master/tree/pmd-core/src/main/java/net/sourceforge/pmd/cpd/XMLRenderer.java) and the jenkins reader (https://github.com/jenkinsci/dry-plugin/blob/master/src/main/java/hudson/plugins/dry/parser/DuplicateCode.java).
Looking at my existing cpd jenkins reports (generated from phpcpd), it doesn't look like the jenkins parser cares about the value of the tokens field. It uses the lines to determine the severity of the violation.
from jsinspect.
Great, thanks! Will look into it next week.
from jsinspect.
@trichins Do you have any example output you could provide? Just curious how it usually displays "codefragments" - assuming they're not identical, would a diff be displayed?
from jsinspect.
All the output that I've seen just shows a code snippet. I think it is based around the idea that the code will be identical between the two sections, otherwise it wouldn't be a copy/paste violation. But I don't think it actually cares what is put in there. I use it to help me track down where the violation is so a diff would work just as well.
from jsinspect.
Hi @trichins, I've committed something that could work at: 0ab568b
Could you confirm whether or not this output is compatible with your setup?
<?xml version="1.0" encoding="utf-8"?>
<pmd-cpd>
<duplication>
<file path="spec/fixtures/intersection.js" line="1"/>
<file path="spec/fixtures/intersection.js" line="7"/>
<file path="spec/fixtures/indentation.js" line="1"/>
<file path="spec/fixtures/indentation.js" line="7"/>
<codefragment>
- spec/fixtures/intersection.js:1,5
+ spec/fixtures/intersection.js:7,11
+ function intersectionB(arrayA, arrayB) {
+ arrayA.filter(function(n) {
+ return arrayB.indexOf(n) != -1;
- function intersectionA(array1, array2) {
- array1.filter(function(n) {
- return array2.indexOf(n) != -1;
});
}
- spec/fixtures/intersection.js:1,5
+ spec/fixtures/indentation.js:1,5
function intersectionA(array1, array2) {
array1.filter(function(n) {
return array2.indexOf(n) != -1;
});
}
- spec/fixtures/intersection.js:1,5
+ spec/fixtures/indentation.js:7,11
function intersectionA(array1, array2) {
array1.filter(function(n) {
+ return array2.indexOf(n) == -1;
- return array2.indexOf(n) != -1;
});
}
</codefragment>
</duplication>
</pmd-cpd>
Of note, the <duplication>
element is missing the tokens attribute, since we don't count them, as well as lines, as it may vary between files.
from jsinspect.
Also, you can generate the test output above by running the following from master:
./bin/jsinspect -r pmd spec/fixtures/intersection.js spec/fixtures/indentation.js
from jsinspect.
Closing for now. Let me know if you run into any issues with this format!
Thanks.
from jsinspect.
Sorry it's taken me such a long time to get back to you. I just tested it and it works pretty well. Two issues that it has is:
1 - the <duplication> node needs at least a "lines" attribute. It is used by jenkins to determine the severity of the duplication. The value is the number of duplicate lines.
2 - The path attribute in the <file> node should be an absolute path. I'm seeing two diffferent paths being written, one that starts with "./" and one that doesn't. Both are relative. I've worked around this by running sed on the output.
from jsinspect.
Hi @trichins thanks for the reply. Lines doesn't make much sense in this case, but I suppose I could report the max number of lines between the different instances. As for the paths, what are they used for? Just linking to the files?
from jsinspect.
max number of lines will work.
jenkins tries to find the file and display it with the lines highlighted when you click on the report. Unfortunately, the finding part happens during the initial parsing of the xml output and if can't find the file, it fails the entire job.
from jsinspect.
:( That's unfortunate. Expect fixes for both tonight or tomorrow. Thanks again!
from jsinspect.
@trichins Mind taking a look at the latest release when you get the chance? I decided to have lines be the total num of lines spanned by each parent node in a "duplication". And while I added absolute paths for the file elements, I kept relative paths in the diffs, as they're generally cleaner to read.
./bin/jsinspect -r pmd spec/fixtures/intersection.js spec/fixtures/indentation.js
<?xml version="1.0" encoding="utf-8"?>
<pmd-cpd>
<duplication lines="20">
<file path="/Users/danielstjules/GitHub/jsinspect/spec/fixtures/intersection.js" line="1"/>
<file path="/Users/danielstjules/GitHub/jsinspect/spec/fixtures/intersection.js" line="7"/>
<file path="/Users/danielstjules/GitHub/jsinspect/spec/fixtures/indentation.js" line="1"/>
<file path="/Users/danielstjules/GitHub/jsinspect/spec/fixtures/indentation.js" line="7"/>
<codefragment>
- spec/fixtures/intersection.js:1,5
+ spec/fixtures/intersection.js:7,11
+ function intersectionB(arrayA, arrayB) {
+ arrayA.filter(function(n) {
+ return arrayB.indexOf(n) != -1;
- function intersectionA(array1, array2) {
- array1.filter(function(n) {
- return array2.indexOf(n) != -1;
});
}
- spec/fixtures/intersection.js:1,5
+ spec/fixtures/indentation.js:1,5
function intersectionA(array1, array2) {
array1.filter(function(n) {
return array2.indexOf(n) != -1;
});
}
- spec/fixtures/intersection.js:1,5
+ spec/fixtures/indentation.js:7,11
function intersectionA(array1, array2) {
array1.filter(function(n) {
+ return array2.indexOf(n) == -1;
- return array2.indexOf(n) != -1;
});
}
</codefragment>
</duplication>
</pmd-cpd>
from jsinspect.
The paths are working.
As for the lines count, I'd prefer if it was the max line count of each parent node. But since this is just a hint to jenkins on which one is the worst offender, a sum kind of works as well.
from jsinspect.
Agreed. 10 lines of code copy-pasted 100 times should be ranked more negatively than a single 30-line copy-paste. Glad things are working. :)
from jsinspect.
@danielstjules It seems that the <file ...
path is coming out as absolute, while the paths shown inside the <codefragment>
are relative.
The examples above are using relative for both.
Would it be possible to use only relative paths in both cases?
stefanjudis/grunt-jsinspect#21
from jsinspect.
jenkins tries to find the file and display it with the lines highlighted when you click on the report.
Absolute paths are required in <file ...>
for linking to the respective from the Jenkins report. And I opted to use relative paths within the code fragments as I find them a bit more legible :)
from jsinspect.
Ok, thank you for the clarification
from jsinspect.
Related Issues (20)
- Possibility to specify custom reporter via CLI and by .jsinspectrc HOT 3
- Blowing up on large react projects HOT 7
- How to save a file๏ผ HOT 1
- Feature request: parsing script tags in HTML
- can't set boolean flags from config file HOT 1
- detect-copy-paste fork HOT 1
- instances > X OR threshold > Y HOT 1
- Usage in Javascript-like languages? HOT 4
- Ability to define files to report
- npx example for package.json scripts
- Cannot parse files using the babel proposal optional chaining
- Typo in documentation example
- Feature Request: Ignore Existing Duplication HOT 1
- Has any plan to support TypeScript? HOT 3
- Unexpected token <> HOT 1
- Consider different font colour for showing matching code blocks HOT 1
- FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
- [feature request] support suffix other than .js or .jsx HOT 2
- Single line match reported when there is no match
- Is this project still maintained? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsinspect.