From a8613accc073982238e7ef062ee715fbbb5bd97c Mon Sep 17 00:00:00 2001 From: Romain Pelisse Date: Sat, 21 Jun 2008 09:43:42 +0000 Subject: [PATCH] Moving all the "Empty rules" out of basic.xml into empty.xml (Added a ref to empty rules in basic.xml, so that the empty rules are still accessible from basic ruleset). git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@6239 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 15 + .../test/net/sourceforge/pmd/RuleSetTest.java | 2 +- .../pmd/rules/basic/BasicRulesTest.java | 11 - .../{basic => empty}/xml/EmptyCatchBlock.xml | 0 .../xml/EmptyFinallyBlock.xml | 0 .../{basic => empty}/xml/EmptyIfStmt.xml | 0 .../{basic => empty}/xml/EmptyInitializer.xml | 0 .../xml/EmptyStatementBlock.xml | 0 .../xml/EmptyStatementNotInLoop.xml | 0 .../xml/EmptyStaticInitializer.xml | 0 .../xml/EmptySwitchStatements.xml | 0 .../xml/EmptySynchronizedBlock.xml | 0 .../{basic => empty}/xml/EmptyTryBlock.xml | 0 .../{basic => empty}/xml/EmptyWhileStmt.xml | 0 pmd/rulesets/basic.xml | 395 +---------------- pmd/rulesets/empty.xml | 403 ++++++++++++++++++ .../pmd/SimpleRuleSetNameMapper.java | 1 + 17 files changed, 425 insertions(+), 402 deletions(-) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptyCatchBlock.xml (100%) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptyFinallyBlock.xml (100%) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptyIfStmt.xml (100%) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptyInitializer.xml (100%) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptyStatementBlock.xml (100%) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptyStatementNotInLoop.xml (100%) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptyStaticInitializer.xml (100%) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptySwitchStatements.xml (100%) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptySynchronizedBlock.xml (100%) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptyTryBlock.xml (100%) rename pmd/regress/test/net/sourceforge/pmd/rules/{basic => empty}/xml/EmptyWhileStmt.xml (100%) create mode 100644 pmd/rulesets/empty.xml diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index c546549dc0..25bc4ea9cb 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -287,6 +287,21 @@ The default Java version processed by PMD is now uniformly Java 1.5. RuleViolations in Reports now uses List internally, and RuleViolationComparator is no longer broken TokenManager errors now include a file name whenever possible for every AST in PMD Added file encoding option to CPD GUI, which already existed for the command line and Ant +Creating an Empty Code Ruleset and moved the following rules from Basic ruleset: + * Empty Code Rules + * EmptyCatchBlock + * EmptyIfStmt + * EmptyWhileStmt + * EmptyTryBlock + * EmptyFinallyBlock + * EmptySwitchStatements + * EmptySynchronizedBlock + * EmptyStatementNotInLoop + * EmptyInitializer + * EmptyStatementBlock + * EmptyStaticInitializer + Basic rulesets still includes a reference to those rules. + Fixed bug 1932242 - EmptyMethodInAbstractClassShouldBeAbstract false + Fixed bug 1928009 - Error using migration ruleset in PMD 4.2 diff --git a/pmd/regress/test/net/sourceforge/pmd/RuleSetTest.java b/pmd/regress/test/net/sourceforge/pmd/RuleSetTest.java index fc4be0d8d2..7567967ad7 100644 --- a/pmd/regress/test/net/sourceforge/pmd/RuleSetTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/RuleSetTest.java @@ -339,7 +339,7 @@ public class RuleSetTest extends RuleTst { RuleSet ruleSet1 = new RuleSet(); ruleSet1.setName("RuleSet1"); - Rule rule = findRule("basic", "EmptyIfStmt"); + Rule rule = findRule("empty", "EmptyIfStmt"); assertTrue("RuleChain rule", rule.usesRuleChain()); ruleSet1.addRule(rule); diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/BasicRulesTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/basic/BasicRulesTest.java index 09ea5863d7..5e019951e5 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/basic/BasicRulesTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/basic/BasicRulesTest.java @@ -25,17 +25,6 @@ public class BasicRulesTest extends SimpleAggregatorTst { addRule("basic", "ClassCastExceptionWithToArray"); addRule("basic", "CollapsibleIfStatements"); addRule("basic", "DoubleCheckedLocking"); - addRule("basic", "EmptyCatchBlock"); - addRule("basic", "EmptyFinallyBlock"); - addRule("basic", "EmptyIfStmt"); - addRule("basic", "EmptyInitializer"); - addRule("basic", "EmptyStatementBlock"); - addRule("basic", "EmptyStatementNotInLoop"); - addRule("basic", "EmptyStaticInitializer"); - addRule("basic", "EmptySwitchStatements"); - addRule("basic", "EmptySynchronizedBlock"); - addRule("basic", "EmptyTryBlock"); - addRule("basic", "EmptyWhileStmt"); addRule("basic", "ExtendsObject"); addRule("basic", "ForLoopShouldBeWhileLoop"); addRule("basic", "JumbledIncrementer"); diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyCatchBlock.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyCatchBlock.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyCatchBlock.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyCatchBlock.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyFinallyBlock.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyFinallyBlock.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyFinallyBlock.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyFinallyBlock.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyIfStmt.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyIfStmt.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyIfStmt.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyIfStmt.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyInitializer.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyInitializer.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyInitializer.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyInitializer.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyStatementBlock.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyStatementBlock.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyStatementBlock.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyStatementBlock.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyStatementNotInLoop.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyStatementNotInLoop.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyStatementNotInLoop.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyStatementNotInLoop.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyStaticInitializer.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyStaticInitializer.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyStaticInitializer.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyStaticInitializer.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptySwitchStatements.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptySwitchStatements.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptySwitchStatements.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptySwitchStatements.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptySynchronizedBlock.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptySynchronizedBlock.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptySynchronizedBlock.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptySynchronizedBlock.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyTryBlock.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyTryBlock.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyTryBlock.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyTryBlock.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyWhileStmt.xml b/pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyWhileStmt.xml similarity index 100% rename from pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/EmptyWhileStmt.xml rename to pmd/regress/test/net/sourceforge/pmd/rules/empty/xml/EmptyWhileStmt.xml diff --git a/pmd/rulesets/basic.xml b/pmd/rulesets/basic.xml index 2388ad144e..a55ce640a9 100644 --- a/pmd/rulesets/basic.xml +++ b/pmd/rulesets/basic.xml @@ -8,221 +8,8 @@ The Basic Ruleset contains a collection of good practices which everyone should follow. - - - - -Empty Catch Block finds instances where an exception is caught, -but nothing is done. In most circumstances, this swallows an exception -which should either be acted on or reported. - - 3 - - - - - - - - false - - - - - - - - - -Empty If Statement finds instances where a condition is checked but nothing is done about it. - - 3 - - - - - - - - - - - - - - - -Empty While Statement finds all instances where a while statement -does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if -it's a while loop that does a lot in the exit expression, rewrite it to make it clearer. - - 3 - - - - - - - - - - - - - - - -Avoid empty try blocks - what's the point? - - 3 - - - - - - - - - - - - - - -Avoid empty finally blocks - these can be deleted. - - 3 - - - - - - - - - - - - - - - -Avoid empty switch statements. - - 3 - - - - - - - - - - - - - - - - - Avoid empty synchronized blocks - they're useless. - - 3 - - - - - - - - - - - - - - - -An empty static initializer was found. - - 3 - - - - - - - - - - - - - - -An empty statement (aka a semicolon by itself) that is not used -as the sole body of a for loop or while loop is probably a bug. It -could also be a double semicolon, which is useless and should be -removed. - - 3 - - - - - - - - - - - - - - -An empty initializer was found. - - 3 - - - - - - - - - - - - - - - Empty block statements are useless so they should be removed. - 3 - - - - - - - - - - - + - - + + \ No newline at end of file diff --git a/pmd/rulesets/empty.xml b/pmd/rulesets/empty.xml new file mode 100644 index 0000000000..ef0b9f615a --- /dev/null +++ b/pmd/rulesets/empty.xml @@ -0,0 +1,403 @@ + + + + +The Empty Code Ruleset contains a collection of rules that find empty statement of any kind (empty method, +empty block statement, empty try or catch block,...). + + + + +Empty Catch Block finds instances where an exception is caught, +but nothing is done. In most circumstances, this swallows an exception +which should either be acted on or reported. + + 3 + + + + + + + + false + + + + + + + + + +Empty If Statement finds instances where a condition is checked but nothing is done about it. + + 3 + + + + + + + + + + + + + + + +Empty While Statement finds all instances where a while statement +does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if +it's a while loop that does a lot in the exit expression, rewrite it to make it clearer. + + 3 + + + + + + + + + + + + + + + +Avoid empty try blocks - what's the point? + + 3 + + + + + + + + + + + + + + +Avoid empty finally blocks - these can be deleted. + + 3 + + + + + + + + + + + + + + + +Avoid empty switch statements. + + 3 + + + + + + + + + + + + + + + Avoid empty synchronized blocks - they're useless. + + 3 + + + + + + + + + + + + + + + +An empty statement (aka a semicolon by itself) that is not used +as the sole body of a for loop or while loop is probably a bug. It +could also be a double semicolon, which is useless and should be +removed. + + 3 + + + + + + + + + + + + + + +An empty initializer was found. + + 3 + + + + + + + + + + + + + + + Empty block statements are useless so they should be removed. + 3 + + + + + + + + + + + + + + + + +An empty static initializer was found. + + 3 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java b/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java index d167d54d1d..5053cadd28 100644 --- a/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java +++ b/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java @@ -50,6 +50,7 @@ public class SimpleRuleSetNameMapper { nameMap.put("controversial", "rulesets/controversial.xml"); nameMap.put("coupling", "rulesets/coupling.xml"); nameMap.put("design", "rulesets/design.xml"); + nameMap.put("empty", "rulesets/empty.xml"); nameMap.put("finalizers", "rulesets/finalizers.xml"); nameMap.put("imports", "rulesets/imports.xml"); nameMap.put("j2ee", "rulesets/j2ee.xml");