Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
prashanthr
@prashanthr84
Hello, Does the CPD suppression works in C#( // CPD-OFF and // CPD-ON). Has anybody used it before? I did try but it doesn't seem to work. I also see that there are no tests too check. Any idea?
Andreas Dangel
@adangel
I can confirm, that this feature unfortunately doesn't work (reason is, the c# antlr grammar puts the comments in a special channel, which is not considered by our tokenizer).
Juan Martín Sotuyo Dodero
@jsotuyod
if it's a channel issue, it should be really easy to fix
Andreas Dangel
@adangel
yes, I think that's all (+ a missing test)
prashanthr
@prashanthr84
Can you provide some hints/info? May be i will try to fix it. What actually is a Channel? Is it more of the Grammer file(C#) change?
Andreas Dangel
@adangel
@prashanthr84 see pmd/pmd#2551
August Boland
@augustboland
Hi, is there any possibility of getting an option to disable the code blocks in the XML report format
Juan Martín Sotuyo Dodero
@jsotuyod
@augustboland there is already an XSLT rendeder that renders the XML and applies an XSLT transofrmation. You can simply write an XSLT selecting the nodes you care about and pass it along under the xsltFilename property
August Boland
@augustboland
@jsotuyod I was asking because I'm having cases where the xml is bad and cant be parsed. I'm not sure XSLT is a valid solution in this case
Juan Martín Sotuyo Dodero
@jsotuyod
if the xmlrenderer is producing illegal xmls, it's a bug. Please, fill an issue in github
Linus Fernandes
@Fernal73
Wrt to the maven pom rules in PMD, do I need to add any additional pmd jars or will pmd-xml as a dependency suffice?
Andreas Dangel
@adangel
Yes, that should be enough. pmd-xml will transitively pull in pmd-core. Please be aware of this issue described here: pmd/pmd#1540
Linus Fernandes
@Fernal73
Ok. So I get this message in debug mode:
DoubleBraceInitialization (Best Practices) [DEBUG] Unable to use RuleChain for XPath: //dependencies/dependency [contains(version/text/@Image,'{project.version}')] [ (/document/project/parent/groupId and groupId/text/@Image != /document/project/parent/groupId/text/@Image) or (/document/project/groupId and groupId/text/@Image != /document/project/groupId/text/@Image) ]/version [DEBUG] Unable to use RuleChain for XPath: //dependencies/dependency [contains(version/text/@Image,'{project.version}')] [ (/document/project/parent/groupId and groupId/text/@Image != /document/project/parent/groupId/text/@Image) or (/document/project/groupId and groupId/text/@Image != /document/project/groupId/text/@Image) ]/version
Does this mean that it has covered my pom.xml or not?
Andreas Dangel
@adangel
With this message, you can just see, that the rule was active. There should be other debug messages which say something like "analyzing file xyz..." or so. If these are missing, then no files matched (probably due to the stupid extension we have....)
Linus Fernandes
@Fernal73
Frankly, I don't see any files processed message in Maven output for this rule , at least not in its vicinity. I'd expect the XML rules to work on all Maven files as well. But obviously the maven rules are not mapped to XML files (from the issue you pointed out). Very few users are going to rename their pom.xml to something.pom just so PMD can process it.
You could also do with a couple of new rules for Maven poms. One to order the dependencies alphabetically and/or by scope. Similarly for pluginManagement.
Andreas Dangel
@adangel
Will it work, if you temporarily rename your pom.xml file to pom.xml.pom? Then we are sure, that this is the issue.
Linus Fernandes
@Fernal73
The output is too verbose in debug mode. But I can't seem to find any evidence that the pom file is processed. The better way would be to have the rules fail. Then, we'd know for certain.
Linus Fernandes
@Fernal73
What does this rule actually do? ProjectVersionAsDependencyVersion
Should we be using properties to specify versions or not?
Linus Fernandes
@Fernal73
How useful are these two rules? From what I can see if you specify an invalid type in dependencyManagement, dependency in dependencies subsequently complain , making the pom itself invalid.
Linus Fernandes
@Fernal73
https://maven.apache.org/plugins/maven-pmd-plugin/pmd-mojo.html#language Could this be the problem? The goal doesn't complain when I set one of languages as XML though.
Andreas Dangel
@adangel
one of the problems, definitively: It clearly says, that it only supports java, javascript and jsp. Please also note, that you would need to tell maven-pmd-plugin to look actually at source files, which are not under the standard directory src/ - in that case, you would need to point the plugin to /pom.xml ... basically adding everything as a source, which is probably not useful. IMHO you need to run PMD as CLI
Linus Fernandes
@Fernal73
Yes, that's the conclusion I've arrived at as well. There's a parameter includeXMLInSite which processes the generated XML. The real showstopper is the language support missing. I'm guessing the Maven plugin developers focused on supporting the most used languages within pmd.
Using ${basedir}/pom. xml in includes might work as well.
I've had to do something similar for a Checkstyle feature utilising the scripting plugin using groovy. Have you used CodeNarc to statically analyse groovy scripts? I can't seem to find a Maven configuration that works for Java 11.
Linus Fernandes
@Fernal73
The most interesting part of CodeNarc is the format of the ruleset file.
About the maven ordering , a rule for pluginManagement might work.
Linus Fernandes
@Fernal73
I seem to be having a couple of errors with running pmd for XML from the command line. It doesn't like a comma separated list of XML file paths as input. Secondly, if the report file specified is in a directory that doesn't exist yet, pmd falls over. Shouldn't it be creating the directory for me?
Linus Fernandes
@Fernal73
Just the second part is a problem . It's confusing about the file list. It expects a file containing comma separated paths , not a comma separated list of paths on the command line. Why won't the latter work? How long can a command line be? The classpath can get pretty long when you're using that instead of specifying an uber jar.
Linus Fernandes
@Fernal73
@adangel Executing pmd from a groovy script pulls in pmd-core when I specify pmd-xml as the only dependency. However, the pmd maven plugin requires that I explicitly specify pmd-core with pmd-java as dependencies for it to work.
@adangel If I have an uber rules file with all the different language rules I intend to use, I have to specify all the language dependencies even when I specify only one language (say java) in the language parameter. Shouldn't pmd ignore other language rules instead of trying to load the mapped classes?
Andreas Dangel
@adangel

the pmd maven plugin requires that I explicitly specify pmd-core with pmd-java as dependencies for it to work.

That's because m-pmd-p by default supports java, so has in any case the dependency for pmd-java. If you now override the plugin-dependencies, you can only add additional dependencies (like pmd-xml), but never remove (or exclude). Therefore you need to make sure, to use the same pmd version or you need to override all pmd dependencies (that the m-pmd-p already has) with the same version. A mix between different versions of different pmd modules is not supported.

Andreas Dangel
@adangel

If I have an uber rules file with all the different language ... Shouldn't pmd ignore other language rules instead of trying to load the mapped classes?

That's an interesting question, which creates a lot of follow up question. E.g. we didn't really specify yet, how PMD should behave, if multiple languages are enabled at the same time. It might work, but not in all cases (especially if the rule names are the same in different languages...).
If you specify a ruleset, and we can't load all rules, should we then just ignore the problem or should we fail? At the moment, it seems, we fail (although probably not with helpful message). I would argue, if you specify a ruleset, you want to execute all rules in that ruleset, and not just a few... otherwise, why would you specify rules, you don't want to execute anyway?
Not sure, what the right decision here is in terms of "least surprise". There is of course a middle way: Warn the user, that not all rules are available, and run with the rules, that are available...

Linus Fernandes
@Fernal73
@adangel The middle way makes sense. Obviously, if you have rules in a ruleset, you'd want all to be executed. But breaking the build if some aren't available doesn't seem right or proper.
Linus Fernandes
@Fernal73
@adangel on the other hand, if users are just provided a warning, there's no incentive to add the needed dependencies or remove the unused rules altogether. I'm not certain what's the best practice here. I wouldn't consider it a bug if it's expected behaviour.
kenji21
@kenji21

Can't get a ANTLR4 for swift 5.0 string literals with '#" "#' syntax:

let rawString = #"Press "Continue" to close this dialog."#
extension URL {
    func html(withTitle title: String) -> String {
        return #"<a href="\#(absoluteString)">\#(title)</a>"#
    }
}

The Swift.g4 code for basic string literals is:

SingleStringLiteral : '"' QuotedText? '"' ;
fragment SingleDoubleQuote : '"' | ~["] ;
fragment QuotedText : QuotedTextItem+ ;
fragment QuotedTextItem : EscapedCharacter | InterpolatedString
// | '\\(' expression ')'
 | ~["\\\u000A\u000D]
 ;
fragment InterpolatedString: '\\(' (QuotedTextItem | SingleStringLiteral)* ')';

but adding DashedSingleStringLiteral : '#"' QuotedText? '"#' ; doesn't do the job

Clément Fournier
@oowekyala
QuotedText disallows double quotes. You'll need to make another fragment that allows them, and possibly other characters (eg \\\u000A is newline iirc)
kenji21
@kenji21
ok, merci Clément :-), got it: had to specific fragments:
DashedSingleStringLiteral : '#"' DashedMultiQuotedText? '"#' ;
fragment DashedMultiQuotedText : DashedMultiQuotedTextItem+ ;
fragment DashedMultiQuotedTextItem : EscapedCharacter | DashedMultiInterpolatedString
 | ~[\\\u000A\u000D]
 ;
fragment DashedMultiInterpolatedString: '\\#(' (DashedMultiQuotedTextItem | DashedSingleStringLiteral)* ')';
ZilinXiang
@ZilinXiang
Hi there, I wonder how to debug CPD in IDEA ? I followed the introduction and passed some augments in IDEA but it doesn't work...
I specified objectivec but CPD parsed the language is AnyLanguage
ZilinXiang
@ZilinXiang
It seems that ServiceLoader cannot load any Language implementation
ZilinXiang
@ZilinXiang
I resolved the problem. You should add your target language module as module dependency (runtime) for pmd-core.
Fiorella Zampetti
@fzampetti_gitlab
Hi there, we are conducting a survey about why refactoring-related contributions to software projects get rejected.
If you have any related experience, we highly appreciate your input!
Thanks in advance and the survey is available at https://usi.eu.qualtrics.com/jfe/form/SV_cO6Ayah0D6q4eSF
Jerome Marfleet
@jmarfleet_gitlab
Hi Guys. I was wondering if the software could be used to determine if an apex class was implementing another apex class. Say I got all the classes names and bodies via return [SELECT Id, Name, Body FROM ApexClass]. Could I then check the bodies to determine which class implements Schedulable?