[doc] Add unit test for all rulesets and fix existing rulesets

This commit is contained in:
Andreas Dangel
2017-11-10 14:03:05 +01:00
parent 1c9c750a0a
commit 06a1244e15
6 changed files with 72 additions and 13 deletions

View File

@ -31,14 +31,14 @@ This ruleset contains links to rules that are new in PMD v5.1.0
<rule ref="rulesets/plsql/dates.xml/TO_TIMESTAMPWithoutDateFormat"/>
<rule ref="rulesets/plsql/TomKytesDespair.xml/TomKytesDespair"/>
<rule ref="rulestes/vm/basic.xml/AvoidDeeplyNestedIfStmts"/>
<rule ref="rulestes/vm/basic.xml/CollapsibleIfStatements"/>
<rule ref="rulestes/vm/basic.xml/ExcessiveTemplateLength"/>
<rule ref="rulestes/vm/basic.xml/AvoidReassigningParameters"/>
<rule ref="rulestes/vm/basic.xml/EmptyIfStmt"/>
<rule ref="rulestes/vm/basic.xml/EmptyForeachStmt"/>
<rule ref="rulestes/vm/basic.xml/UnusedMacroParameter"/>
<rule ref="rulestes/vm/basic.xml/NoInlineJavaScript"/>
<rule ref="rulestes/vm/basic.xml/NoInlineStyles"/>
<rule ref="rulesets/vm/basic.xml/AvoidDeeplyNestedIfStmts"/>
<rule ref="rulesets/vm/basic.xml/CollapsibleIfStatements"/>
<rule ref="rulesets/vm/basic.xml/ExcessiveTemplateLength"/>
<rule ref="rulesets/vm/basic.xml/AvoidReassigningParameters"/>
<rule ref="rulesets/vm/basic.xml/EmptyIfStmt"/>
<rule ref="rulesets/vm/basic.xml/EmptyForeachStmt"/>
<rule ref="rulesets/vm/basic.xml/UnusedMacroParameter"/>
<rule ref="rulesets/vm/basic.xml/NoInlineJavaScript"/>
<rule ref="rulesets/vm/basic.xml/NoInlineStyles"/>
</ruleset>

View File

@ -20,7 +20,7 @@ This ruleset contains links to rules that are new in PMD v5.5.0
<rule ref="rulesets/apex/complexity.xml/StdCyclomaticComplexity" />
<rule ref="rulesets/apex/complexity.xml/TooManyFields" />
<rule ref="rulesets/apex/complexity.xml/ExcessivePublicCount" />
<rule ref="rulesets/apex/complexity.xml/AvoidDmlStatementsInLoops" />
<rule ref="rulesets/apex/performance.xml/AvoidDmlStatementsInLoops" />
<rule ref="rulesets/apex/performance.xml/AvoidSoqlInLoops" />
<rule ref="rulesets/apex/style.xml/VariableNamingConventions" />
<rule ref="rulesets/apex/style.xml/MethodNamingConventions" />

View File

@ -8,7 +8,7 @@
This ruleset contains links to rules that are new in PMD v6.0.0
</description>
<rule ref="category/java/errorprone.xml/ForLoopCanBeForeach"/>
<rule ref="category/java/bestpractices.xml/ForLoopCanBeForeach"/>
<rule ref="category/java/errorprone.xml/DoNotExtendJavaLangThrowable"/>
<rule ref="category/java/design.xml/DataClass"/>
<rule ref="category/java/design.xml/NcssCount"/>

View File

@ -0,0 +1,57 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.docs;
import static org.junit.Assert.fail;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.junit.Test;
import net.sourceforge.pmd.RuleSetFactory;
import net.sourceforge.pmd.RuleSetNotFoundException;
public class RuleSetResolverTest {
private static List<String> excludedRulesets = new ArrayList<>();
static {
excludedRulesets.add("pmd-test/src/main/resources/rulesets/dummy/basic.xml");
}
@Test
public void resolveAllRulesets() {
Path basePath = FileSystems.getDefault().getPath(".").resolve("..").toAbsolutePath().normalize();
List<String> additionalRulesets = GenerateRuleDocsCmd.findAdditionalRulesets(basePath);
filterRuleSets(additionalRulesets);
RuleSetFactory ruleSetFactory = new RuleSetFactory();
for (String filename : additionalRulesets) {
try {
ruleSetFactory.createRuleSet(filename);
} catch (RuntimeException | RuleSetNotFoundException e) {
fail("Couldn't load ruleset " + filename + ": " + e.getMessage());
}
}
}
private void filterRuleSets(List<String> additionalRulesets) {
Iterator<String> it = additionalRulesets.iterator();
while (it.hasNext()) {
String filename = it.next();
for (String exclusion : excludedRulesets) {
if (filename.endsWith(exclusion)) {
it.remove();
break;
}
}
}
}
}

View File

@ -23,6 +23,8 @@ The Naming Ruleset contains rules regarding preferred usage of names and identif
<rule ref="category/java/codestyle.xml/LongVariable" deprecated="true" />
<rule ref="category/java/codestyle.xml/MethodNamingConventions" deprecated="true" />
<rule ref="category/java/codestyle.xml/MIsLeadingVariableName" name="MisleadingVariableName" deprecated="true" /> <!-- also renamed -->
<!-- providing also the new name, since RuleSetFactoryCompatibility will change existing rulesets to use the new rulename -->
<rule ref="category/java/codestyle.xml/MIsLeadingVariableName" deprecated="true" />
<rule ref="category/java/codestyle.xml/NoPackage" deprecated="true" />
<rule ref="category/java/codestyle.xml/PackageCase" deprecated="true" />
<rule ref="category/java/codestyle.xml/ShortClassName" deprecated="true" />

View File

@ -8,7 +8,7 @@
Rules concerning basic VF guidelines.
</description>
<rule ref="category/vf/VfCsrf" deprecated="true" />
<rule ref="category/vf/VfUnescapeEl" deprecated="true" />
<rule ref="category/vf/security.xml/VfCsrf" deprecated="true" />
<rule ref="category/vf/security.xml/VfUnescapeEl" deprecated="true" />
</ruleset>