Code Monkey home page Code Monkey logo

Comments (18)

danielstjules avatar danielstjules commented on July 26, 2024

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.

trichins avatar trichins commented on July 26, 2024

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.

danielstjules avatar danielstjules commented on July 26, 2024

Great, thanks! Will look into it next week.

from jsinspect.

danielstjules avatar danielstjules commented on July 26, 2024

@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.

trichins avatar trichins commented on July 26, 2024

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.

danielstjules avatar danielstjules commented on July 26, 2024

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.

danielstjules avatar danielstjules commented on July 26, 2024

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.

danielstjules avatar danielstjules commented on July 26, 2024

Closing for now. Let me know if you run into any issues with this format!
Thanks.

from jsinspect.

trichins avatar trichins commented on July 26, 2024

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.

danielstjules avatar danielstjules commented on July 26, 2024

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.

trichins avatar trichins commented on July 26, 2024

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.

danielstjules avatar danielstjules commented on July 26, 2024

:( That's unfortunate. Expect fixes for both tonight or tomorrow. Thanks again!

from jsinspect.

danielstjules avatar danielstjules commented on July 26, 2024

@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.

trichins avatar trichins commented on July 26, 2024

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.

danielstjules avatar danielstjules commented on July 26, 2024

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.

paazmaya avatar paazmaya commented on July 26, 2024

@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.

danielstjules avatar danielstjules commented on July 26, 2024

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.

paazmaya avatar paazmaya commented on July 26, 2024

Ok, thank you for the clarification

from jsinspect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.