pmd

PMD in eclipse does not accept exclude-pattern

隐身守侯 提交于 2019-12-06 03:35:57
问题 I am using PMD under eclipse 4.3.1 / Kepler and I cannot exclude files and folders from the violation check. My folder structure /any/path/to/the/workspace/myproject1 /any/path/to/the/workspace/myproject2 /any/path/to/the/workspace/myprojectWithPMDrulesFile/pmd-rules.xml Now following folders get generated by testng ...../myproject1/test-output ...../myproject2/test-output Now I have configured following rules file: <?xml version="1.0" encoding="UTF-8"?> <ruleset xmlns="http://pmd.sourceforge

In the Eclipe PMD plugin, can I reference the standard ruleset files?

≡放荡痞女 提交于 2019-12-05 12:53:04
I would like my eclipse PMD plugin configuration to access the same standard ruleset files as the maven-pmd-plugin . You can configure the maven pmd plugin to use a custom set of rule sets like this: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>2.5</version> <configuration> <rulesets> <!-- Two rule sets that come bundled with PMD --> <ruleset>/rulesets/braces.xml</ruleset> <ruleset>/rulesets/naming.xml</ruleset> <!-- Custom local file system rule set --> <ruleset>d:\rulesets\strings.xml</ruleset> <!-- Custom remote rule set accessed

Is there any Checkstyle/PMD/Findbugs rule to force “else if” to be on the same line?

为君一笑 提交于 2019-12-05 10:04:24
In our project for chained if/else/if we would like to have following formatting: if (flag1) { // Do something 1 } else if (flag2) { // Do something 2 } else if (flag3) { // Do something 3 } And forbid following one: if (flag1) { // Do something 1 } else { if (flag2) { // Do something 2 } else { if (flag3) { // Do something 3 } } } Is there some predefined rule in either of listed above static code analysis tools to force this code style? If no - I know there is an ability to write custom rules in all of those tools, which one would you suggest to implement such a rule (not really familiar

CollapsibleIfStatements

筅森魡賤 提交于 2019-12-05 09:42:54
I recently stumpled upon the following warning using PMD (embedded in hudson), my code seems to suffer CollapsibleIfStatements , which I do not fully understand. The code looks like this // list to be filled with unique Somethingness List list = new ArrayList(); // fill list for (SomeObject obj : getSomeObjects()) { // interating if (!obj.getSomething().isEmpty()) { // check if "Something" is empty * if (!list.contains(obj.getSomething())) { // check if "Something" is already in my list ** list.add(obj.getSomething()); // add "Something" to my list } } } In my opinion this code isn't more

PMD rule God Class - understanding the metrics

孤者浪人 提交于 2019-12-05 07:23:47
We are using the source code analyzer PMD in our Java project. I am trying to resolve the reported issues and I am currently struggling with the GodClass rule. I know that the idea is not to create huge classes. However, I don't like the word "huge" because it's too vague. Can anybody explain how the metrics of this rule works? The report says e.g. Possible God class (WMC=47, ATFD=11, TCC=0.06315789473684211) What do all these numbers mean? Does anybody know the formula that decides whether a particular class is huge or not? Javadoc to this rule states The rule uses the detection strategy

Add an empty string vs toString - why is it bad?

荒凉一梦 提交于 2019-12-05 04:45:18
According to the tool PMD, the following is a bad practice: String s = "" + 123; // bad String t = Integer.toString(456); // ok This is an inefficient way to convert any type to a `String`. Why is it a bad thing to do? String s = "" + 123; // bad String t = Integer.toString(456); Will be compiled to: String s = "123"; String t = Integer.toString(456); so: "" +123 is obvious slightly better! Checked with JAD public static void main(String args[]) { // 0 0:ldc1 #16 <String "123"> // 1 2:astore_1 // 2 3:sipush 456 // 3 6:invokestatic #18 <Method String Integer.toString(int)> // 4 9:astore_2 // 5

Which is the highest priority in PMD?

谁都会走 提交于 2019-12-05 02:44:30
Maybe it's just me, but I can't find information which is the highest priority in PMD : 1 or 5 ? Because of http://pmd.sourceforge.net/running.html and the mention of the command line parameter -minimumpriority I think 5 is the highest and 1 is the lowest value. Am I right? lschin Actually 1 is highest priority and 5 is lowest priority. You can check the exported rule set, where <rule ref="rulesets/imports.xml/ImportFromSamePackage"/> <!-- Default --> <rule ref="rulesets/imports.xml/TooManyStaticImports"> <priority>5</priority> <!-- Change to priority [information] --> </rule> The all default

PMD coulnd't find ruleset

有些话、适合烂在心里 提交于 2019-12-04 16:59:20
I'm on creating a maven based java project, which contains the PMD maven plugin. I use my own rule set XML and it works like a charm, except two rule sets: the emptycode and the unnecessary : when I run the build, maven says: " can't find resource ". The role definitions look like: <role ref="rulesets/emptycode" /> and <role ref="rulesets/unnecessary" /> In every other cases, this kind of definition works. What I found out is that: there is a rule set with the name " unnecessary " under ecmasrcipt category, so maybe this definition needs some suggestion to use java version. I tried multiple

PMD ruleset file

你说的曾经没有我的故事 提交于 2019-12-04 16:22:48
问题 I am trying to figure where is the default ruleset file, name of the default ruleset file and how do we add our own rules to it. I tried to google, but that is just confusing me. So far, I have put the pmd plugin inside eclipse plugins folder and in preferences I can see PMD. 回答1: The standard ruleset file is *.xml inside pmd-bin-x.x.x.zip/.../lib/pmd-x.x.x.jar/rulesets/ , refer to http://pmd.sourceforge.net/rules/index.html. The default ruleset file of PMD Eclipse Plugin is inside pmd___.jar

Java PMD warning on non-transient class member

情到浓时终转凉″ 提交于 2019-12-04 16:11:11
问题 On line: private boolean someFlag; I get the following PMD warning: Found non-transient, non-static member. Please mark as transient or provide accessors. Can someone please explain why this warning is there and what it means? (I understand how to fix it, I don't understand why it's there...) I'm getting this on many other member declarations as well... EDIT: My class is definitely not a bean, and not serializable... 回答1: I assume your class is a bean that by definition implements