From c3da9ec086456af9be0300d29585f41ef5595cb8 Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Sun, 17 Sep 2017 16:19:51 +0200 Subject: [PATCH 01/13] empty code ruleset for apex --- docs/pages/pmd/rules/apex/empty.md | 203 ++++++++++++++++ .../main/resources/rulesets/apex/empty.xml | 216 ++++++++++++++++++ .../rulesets/apex/rulesets.properties | 1 + 3 files changed, 420 insertions(+) create mode 100644 docs/pages/pmd/rules/apex/empty.md create mode 100644 pmd-apex/src/main/resources/rulesets/apex/empty.xml diff --git a/docs/pages/pmd/rules/apex/empty.md b/docs/pages/pmd/rules/apex/empty.md new file mode 100644 index 0000000000..4153209bc3 --- /dev/null +++ b/docs/pages/pmd/rules/apex/empty.md @@ -0,0 +1,203 @@ +--- +title: Empty Code +summary: The Empty Code ruleset contains rules that find empty statements of any kind (empty method, empty block statement, empty try or catch block,...). +permalink: pmd_rules_apex_empty.html +folder: pmd/rules/apex +sidebaractiveurl: /pmd_rules_apex.html +editmepath: ../pmd-apex/src/main/resources/rulesets/apex/empty.xml +keywords: Empty Code, EmptyCatchBlock, EmptyIfStmt, EmptyWhileStmt, EmptyTryBlock, EmptyFinallyBlock, EmptyStaticInitializer +--- +## EmptyCatchBlock + +**Since:** PMD 5.8.2 + +**Priority:** Medium (3) + +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. + +``` +//CatchStatement + [count(Block/BlockStatement) = 0 and ($allowCommentedBlocks != 'true' or Block/@containsComment = 'false')] + [FormalParameter/Type/ReferenceType + /ClassOrInterfaceType[@Image != 'InterruptedException' and @Image != 'CloneNotSupportedException'] + ] + [FormalParameter/VariableDeclaratorId[not(matches(@Image, $allowExceptionNameRegex))]] +``` + +**Example(s):** + +``` java +public void doSomething() { + ... + try { + insert accounts; + } catch (DmlException dmle) { + // not good + } +} +``` + +**This rule has the following properties:** + +|Name|Default Value|Description| +|----|-------------|-----------| +|allowCommentedBlocks|false|Empty blocks containing comments will be skipped| +|allowExceptionNameRegex|^$|Empty blocks catching exceptions with names matching this regular expression will be skipped| + +**Use this rule by referencing it:** +``` xml + +``` + +## EmptyFinallyBlock + +**Since:** PMD 5.8.2 + +**Priority:** Medium (3) + +Empty finally blocks serve no purpose and should be removed. + +``` +//FinallyStatement[count(Block/BlockStatement) = 0] +``` + +**Example(s):** + +``` java +public class Foo { + public void bar() { + try { + Integer x=2; + } finally { + // empty! + } + } +} +``` + +**Use this rule by referencing it:** +``` xml + +``` + +## EmptyIfStmt + +**Since:** PMD 5.8.2 + +**Priority:** Medium (3) + +Empty If Statement finds instances where a condition is checked but nothing is done about it. + +``` +//IfStatement/Statement + [EmptyStatement or Block[count(*) = 0]] +``` + +**Example(s):** + +``` java +public class Foo { + void bar(Integer x) { + if (x == 0) { + // empty! + } + } +} +``` + +**Use this rule by referencing it:** +``` xml + +``` + +## EmptyStaticInitializer + +**Since:** PMD 5.8.2 + +**Priority:** Medium (3) + +An empty static initializer serve no purpose and should be removed. + +``` +//Initializer[@Static='true']/Block[count(*)=0] +``` + +**Example(s):** + +``` java +public class Foo { + static { + // empty + } +} +``` + +**Use this rule by referencing it:** +``` xml + +``` + +## EmptyTryBlock + +**Since:** PMD 5.8.2 + +**Priority:** Medium (3) + +Avoid empty try blocks - what's the point? + +``` +//TryStatement[not(ResourceSpecification)]/Block[1][count(*) = 0] +``` + +**Example(s):** + +``` java +public class Foo { + public void bar() { + try { + // this has no use + } catch (Exception e) { + e.printStackTrace(); + } + } +} +``` + +**Use this rule by referencing it:** +``` xml + +``` + +## EmptyWhileStmt + +**Since:** PMD 5.8.2 + +**Priority:** Medium (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 is +a while loop that does a lot in the exit expression, rewrite it to make it clearer. + +``` +//WhileStatement/Statement[./Block[count(*) = 0] or ./EmptyStatement] +``` + +**Example(s):** + +``` java +public class Foo { + public void bar(Integer a, Integer b) { + while (a == b) { + // empty! + } + } +} +``` + +**Use this rule by referencing it:** +``` xml + +``` + diff --git a/pmd-apex/src/main/resources/rulesets/apex/empty.xml b/pmd-apex/src/main/resources/rulesets/apex/empty.xml new file mode 100644 index 0000000000..5f85efb703 --- /dev/null +++ b/pmd-apex/src/main/resources/rulesets/apex/empty.xml @@ -0,0 +1,216 @@ + + + + +The Empty Code ruleset contains rules that find empty statements 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 + + + + + + + + + + + + + + + + +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 is +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 + + + + + + + + + + + + + + +Empty finally blocks serve no purpose and should be removed. + + 3 + + + + + + + + + + + + + + +An empty static initializer serve no purpose and should be removed. + + 3 + + + + + + + + + + + + + \ No newline at end of file diff --git a/pmd-apex/src/main/resources/rulesets/apex/rulesets.properties b/pmd-apex/src/main/resources/rulesets/apex/rulesets.properties index 879f524f1d..61d607e55d 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/rulesets.properties +++ b/pmd-apex/src/main/resources/rulesets/apex/rulesets.properties @@ -6,6 +6,7 @@ rulesets.filenames=\ rulesets/apex/apexunit.xml,\ rulesets/apex/braces.xml,\ rulesets/apex/complexity.xml,\ + rulesets/apex/empty.xml,\ rulesets/apex/performance.xml,\ rulesets/apex/security.xml,\ rulesets/apex/style.xml From cacb82ace5b9734a592d75ead8f988691ed4acd9 Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Sun, 17 Sep 2017 18:45:37 +0200 Subject: [PATCH 02/13] [apex] Add test for empty xpath checks. --- .../lang/apex/rule/empty/EmptyRulesTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java new file mode 100644 index 0000000000..2f4a80e207 --- /dev/null +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java @@ -0,0 +1,22 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.apex.rule.empty; + +import net.sourceforge.pmd.testframework.SimpleAggregatorTst; + +public class EmptyRulesTest extends SimpleAggregatorTst { + + private static final String RULESET = "apex-empty"; + + @Override + public void setUp() { + addRule(RULESET, "EmptyCatchBlock"); + addRule(RULESET, "EmptyFinallyBlock"); + addRule(RULESET, "EmptyIfStmt"); + addRule(RULESET, "EmptyStaticInitializer"); + addRule(RULESET, "EmptyTryBlock"); + addRule(RULESET, "EmptyWhileStmt"); + } +} From 00b06ef8104ff002bcb058d81b558b135278c86b Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Sun, 17 Sep 2017 18:46:05 +0200 Subject: [PATCH 03/13] [apex] version since in empty rules, correct xpath expression --- .../src/main/resources/rulesets/apex/empty.xml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pmd-apex/src/main/resources/rulesets/apex/empty.xml b/pmd-apex/src/main/resources/rulesets/apex/empty.xml index 5f85efb703..9a13d39eff 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/empty.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/empty.xml @@ -11,7 +11,7 @@ empty block statement, empty try or catch block,...). @@ -27,8 +27,7 @@ or reported. @@ -53,7 +52,7 @@ public void doSomething() { @@ -86,7 +85,7 @@ public class Foo { @@ -118,7 +117,7 @@ public void bar(Integer a, Integer b) { @@ -151,7 +150,7 @@ public class Foo { @@ -185,7 +184,7 @@ public class Foo { From bec10ce1d29fd8cca2066358c5b890a2f36746d5 Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Sun, 17 Sep 2017 19:42:24 +0200 Subject: [PATCH 04/13] [apex] add tests for empty checks --- .../apex/rule/empty/xml/EmptyCatchBlock.xml | 39 ++++++++++++++++ .../apex/rule/empty/xml/EmptyFinallyBlock.xml | 46 +++++++++++++++++++ .../lang/apex/rule/empty/xml/EmptyIfStmt.xml | 35 ++++++++++++++ .../rule/empty/xml/EmptyStaticInitializer.xml | 41 +++++++++++++++++ .../apex/rule/empty/xml/EmptyTryBlock.xml | 40 ++++++++++++++++ .../apex/rule/empty/xml/EmptyWhileStmt.xml | 39 ++++++++++++++++ 6 files changed, 240 insertions(+) create mode 100644 pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml create mode 100644 pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml create mode 100644 pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml create mode 100644 pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStaticInitializer.xml create mode 100644 pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml create mode 100644 pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyWhileStmt.xml diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml new file mode 100644 index 0000000000..7ec5326b7b --- /dev/null +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml @@ -0,0 +1,39 @@ + + + + + 1 + bar = [SELECT Id FROM Account]; + } + catch(Exception e) {} + } +} + ]]> + + + + 0 + bar = [SELECT Id FROM Account]; + } catch(Exception e) { + system.debug('Oh oh there has been an error', e); + } + } +} + ]]> + + diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml new file mode 100644 index 0000000000..920988d319 --- /dev/null +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml @@ -0,0 +1,46 @@ + + + + + 1 + accounts = [SELECT Id FROM Account LIMIT 200]: + + try { + insert accounts; + } catch(Exception e) { + // Generic exception handling code + system.debug('Something has gone wrong', e); + } finally { + } + } +} + ]]> + + + + 0 + bar = [SELECT Id FROM Account]; + } catch(Exception e) { + system.debug('Oh oh there has been an error', e); + } finally { + system.debug('This could be a very cool action, but it isnt'); + } + } +} + ]]> + + diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml new file mode 100644 index 0000000000..a054458d62 --- /dev/null +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml @@ -0,0 +1,35 @@ + + + + + 1 + + + + + 0 + + + diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStaticInitializer.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStaticInitializer.xml new file mode 100644 index 0000000000..528a96f1f2 --- /dev/null +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStaticInitializer.xml @@ -0,0 +1,41 @@ + + + + + 1 + + + + + 0 + + + diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml new file mode 100644 index 0000000000..343144fae8 --- /dev/null +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml @@ -0,0 +1,40 @@ + + + + + 1 + + + + + 0 + bar = [SELECT Id FROM Account]; + } catch(Exception e) { + system.debug('Oh oh there has been an error', e); + } + } +} + ]]> + + diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyWhileStmt.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyWhileStmt.xml new file mode 100644 index 0000000000..b48eb7acbd --- /dev/null +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyWhileStmt.xml @@ -0,0 +1,39 @@ + + + + + 1 + + + + + 0 + + + From 8a95fcd2578b8fead9e0f04269673c513c843ba3 Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Sun, 17 Sep 2017 19:54:01 +0200 Subject: [PATCH 05/13] [apex] fix xpath, test recheck --- pmd-apex/src/main/resources/rulesets/apex/empty.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pmd-apex/src/main/resources/rulesets/apex/empty.xml b/pmd-apex/src/main/resources/rulesets/apex/empty.xml index 9a13d39eff..8c8f40a02e 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/empty.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/empty.xml @@ -28,7 +28,6 @@ or reported. //CatchStatement [count(Block/BlockStatement) = 0 and ($allowCommentedBlocks != 'true' or Block/@containsComment = 'false')] [FormalParameter/Type/ReferenceType] - ] [FormalParameter/VariableDeclaratorId[not(matches(@Image, $allowExceptionNameRegex))]] ]]> From 1ddd5d2ac6e72d8548f70612966b29f9c4cc33ac Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Sun, 17 Sep 2017 21:37:54 +0200 Subject: [PATCH 06/13] [apex] fix catch xpath and add meaningful names for test cases --- pmd-apex/src/main/resources/rulesets/apex/empty.xml | 1 - .../pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml | 4 ++-- .../pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml | 4 ++-- .../sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml | 4 ++-- .../pmd/lang/apex/rule/empty/xml/EmptyStaticInitializer.xml | 4 ++-- .../pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml | 4 ++-- .../pmd/lang/apex/rule/empty/xml/EmptyWhileStmt.xml | 4 ++-- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/pmd-apex/src/main/resources/rulesets/apex/empty.xml b/pmd-apex/src/main/resources/rulesets/apex/empty.xml index 8c8f40a02e..eaf5d08655 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/empty.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/empty.xml @@ -27,7 +27,6 @@ or reported. diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml index 7ec5326b7b..fc23e519be 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> 1 0 1 0 1 0 1 0 1 0 1 0 Date: Sun, 17 Sep 2017 21:50:39 +0200 Subject: [PATCH 07/13] [apex] single quote ruining tests xml --- .../pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml | 2 +- .../pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml | 6 +++--- .../pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml | 2 +- .../pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml index fc23e519be..c48577403a 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml @@ -30,7 +30,7 @@ public class Foo { try { List bar = [SELECT Id FROM Account]; } catch(Exception e) { - system.debug('Oh oh there has been an error', e); + system.debug("Oh oh there has been an error", e); } } } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml index 045fb0d09a..b9a31d8a40 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml @@ -17,7 +17,7 @@ public class Foo { insert accounts; } catch(Exception e) { // Generic exception handling code - system.debug('Something has gone wrong', e); + system.debug("Something has gone wrong", e); } finally { } } @@ -35,9 +35,9 @@ public class Foo { try { List bar = [SELECT Id FROM Account]; } catch(Exception e) { - system.debug('Oh oh there has been an error', e); + system.debug("Oh oh there has been an error", e); } finally { - system.debug('This could be a very cool action, but it isnt'); + system.debug("This could be a very cool action, but it isnt"); } } } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml index 223d233bec..89cac96a79 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml @@ -26,7 +26,7 @@ Success Case: Empty If statement public class Foo { void foo() { if (true) { - system.debug('This works like a charm'); + system.debug("This works like a charm"); } } } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml index 8edad083a6..10336b8931 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml @@ -14,7 +14,7 @@ public class Foo { try { } catch(Exception e) { - system.debug('This will never ever get called.', e); + system.debug("This will never ever get called.", e); } } } @@ -31,7 +31,7 @@ public class Foo { try { List bar = [SELECT Id FROM Account]; } catch(Exception e) { - system.debug('Oh oh there has been an error', e); + system.debug("Oh oh there has been an error", e); } } } From 882139e189d60fc55ef1864dface2131137d6dbc Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Sun, 17 Sep 2017 23:35:42 +0200 Subject: [PATCH 08/13] [apex] fix tests and add to ruleset for tests --- .../main/resources/rulesets/apex/empty.xml | 12 ++-- .../main/resources/rulesets/apex/ruleset.xml | 59 ++++++++++++++++++- .../apex/rule/empty/xml/EmptyCatchBlock.xml | 10 ++-- .../apex/rule/empty/xml/EmptyFinallyBlock.xml | 12 ++-- .../lang/apex/rule/empty/xml/EmptyIfStmt.xml | 8 +-- .../rule/empty/xml/EmptyStaticInitializer.xml | 3 +- .../apex/rule/empty/xml/EmptyTryBlock.xml | 6 +- 7 files changed, 82 insertions(+), 28 deletions(-) diff --git a/pmd-apex/src/main/resources/rulesets/apex/empty.xml b/pmd-apex/src/main/resources/rulesets/apex/empty.xml index eaf5d08655..99f8e1fd67 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/empty.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/empty.xml @@ -13,7 +13,7 @@ empty block statement, empty try or catch block,...). language="apex" since="6.0.0" message="Avoid empty catch blocks" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_empty.html#emptycatchblock"> Empty Catch Block finds instances where an exception is caught, but nothing is done. @@ -52,7 +52,7 @@ public void doSomething() { language="apex" since="6.0.0" message="Avoid empty 'if' statements" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_empty.html#emptyifstmt"> Empty If Statement finds instances where a condition is checked but nothing is done about it. @@ -85,7 +85,7 @@ public class Foo { language="apex" since="6.0.0" message="Avoid empty 'while' statements" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_empty.html#emptywhilestmt"> Empty While Statement finds all instances where a while statement does nothing. @@ -117,7 +117,7 @@ public void bar(Integer a, Integer b) { language="apex" since="6.0.0" message="Avoid empty try blocks" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_empty.html#emptytryblock"> Avoid empty try blocks - what's the point? @@ -150,7 +150,7 @@ public class Foo { language="apex" since="6.0.0" message="Avoid empty finally blocks" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_empty.html#emptyfinallyblock"> Empty finally blocks serve no purpose and should be removed. @@ -184,7 +184,7 @@ public class Foo { language="apex" since="6.0.0" message="Empty static initializer was found" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_empty.html#emptystaticinitializer"> An empty static initializer serve no purpose and should be removed. diff --git a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml index 768ecd8994..e00242eaa8 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml @@ -324,4 +324,61 @@ - \ No newline at end of file + + + 3 + + + + + + + + + + + 3 + + + + + + + + + 3 + + + + + + + + + 3 + + + + + + + + + 3 + + + + + + + + + 3 + + + + + + + + diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml index c48577403a..6531f3f39a 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml @@ -10,9 +10,9 @@ Failure case: Empty Catch Block 1 bar = [SELECT Id FROM Account]; + system.debug("test"); } catch(Exception e) {} } @@ -26,11 +26,11 @@ Success case: Empty Catch Block 0 bar = [SELECT Id FROM Account]; + system.debug("test"); } catch(Exception e) { - system.debug("Oh oh there has been an error", e); + system.debug(e); } } } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml index b9a31d8a40..2ca8e4a1e5 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml @@ -11,13 +11,11 @@ Failure Case: Empty Finally Block accounts = [SELECT Id FROM Account LIMIT 200]: - try { - insert accounts; + insert account; } catch(Exception e) { // Generic exception handling code - system.debug("Something has gone wrong", e); + system.debug(e); } finally { } } @@ -33,11 +31,11 @@ Success Case: Empty Finally Block public class Foo { void foo() { try { - List bar = [SELECT Id FROM Account]; + insert account; } catch(Exception e) { - system.debug("Oh oh there has been an error", e); + system.debug(e); } finally { - system.debug("This could be a very cool action, but it isnt"); + someAction(); } } } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml index 89cac96a79..00b5ba0560 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyIfStmt.xml @@ -10,7 +10,7 @@ Failure Case: Empty If Statement 1 0 bar = [SELECT Id FROM Account]; + insert account; } catch(Exception e) { - system.debug("Oh oh there has been an error", e); + system.debug(e); } } } From 5d7237cd2d98c0f580a7ea1382bb7d73d39b1421 Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Mon, 18 Sep 2017 00:35:00 +0200 Subject: [PATCH 09/13] [apex] style, indent --- .../main/resources/rulesets/apex/empty.xml | 2 +- .../main/resources/rulesets/apex/ruleset.xml | 40 +++++++++---------- .../apex/rule/empty/xml/EmptyCatchBlock.xml | 9 +++-- .../apex/rule/empty/xml/EmptyWhileStmt.xml | 4 +- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/pmd-apex/src/main/resources/rulesets/apex/empty.xml b/pmd-apex/src/main/resources/rulesets/apex/empty.xml index 99f8e1fd67..225b4c6073 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/empty.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/empty.xml @@ -210,4 +210,4 @@ public class Foo { - \ No newline at end of file + diff --git a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml index e00242eaa8..ce3cf76c75 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml @@ -290,95 +290,95 @@ 3 - + - + 3 - + - + 3 - + - + 3 - + - + 3 - + - + 3 - + - + 3 - + - + 3 - + - + 3 - + - + 3 - + - + diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml index 6531f3f39a..2a82791147 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyCatchBlock.xml @@ -10,11 +10,12 @@ Failure case: Empty Catch Block 1 @@ -28,7 +29,7 @@ Success case: Empty Catch Block public class Foo { public void foo() { try { - system.debug("test"); + system.debug(1); } catch(Exception e) { system.debug(e); } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyWhileStmt.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyWhileStmt.xml index 561cb5e636..85c98fee7b 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyWhileStmt.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyWhileStmt.xml @@ -12,8 +12,8 @@ Failure Case: Empty While Statement public class Foo { void foo() { Integer count = 1; - - while (count < 11) {} + while (count < 11) { + } } } ]]> From a890dbf68c27c0f4a268551439c62fc9846e41fb Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Mon, 18 Sep 2017 20:12:57 +0200 Subject: [PATCH 10/13] [apex] use correct AST --- docs/pages/pmd/rules/apex/empty.md | 113 ++++--------- .../main/resources/rulesets/apex/empty.xml | 154 ++++++------------ .../main/resources/rulesets/apex/ruleset.xml | 22 +-- .../lang/apex/rule/empty/EmptyRulesTest.java | 4 +- .../rule/empty/xml/EmptyStaticInitializer.xml | 40 ----- .../apex/rule/empty/xml/EmptyTryBlock.xml | 40 ----- ...lyBlock.xml => EmptyTryOrFinallyBlock.xml} | 34 ++++ 7 files changed, 113 insertions(+), 294 deletions(-) delete mode 100644 pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStaticInitializer.xml delete mode 100644 pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml rename pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/{EmptyFinallyBlock.xml => EmptyTryOrFinallyBlock.xml} (61%) diff --git a/docs/pages/pmd/rules/apex/empty.md b/docs/pages/pmd/rules/apex/empty.md index 4153209bc3..7ff4634022 100644 --- a/docs/pages/pmd/rules/apex/empty.md +++ b/docs/pages/pmd/rules/apex/empty.md @@ -5,11 +5,11 @@ permalink: pmd_rules_apex_empty.html folder: pmd/rules/apex sidebaractiveurl: /pmd_rules_apex.html editmepath: ../pmd-apex/src/main/resources/rulesets/apex/empty.xml -keywords: Empty Code, EmptyCatchBlock, EmptyIfStmt, EmptyWhileStmt, EmptyTryBlock, EmptyFinallyBlock, EmptyStaticInitializer +keywords: Empty Code, EmptyCatchBlock, EmptyIfStmt, EmptyWhileStmt, EmptyTryOrFinallyBlock --- ## EmptyCatchBlock -**Since:** PMD 5.8.2 +**Since:** PMD 6.0.0 **Priority:** Medium (3) @@ -18,12 +18,8 @@ In most circumstances, this swallows an exception which should either be acted o or reported. ``` -//CatchStatement - [count(Block/BlockStatement) = 0 and ($allowCommentedBlocks != 'true' or Block/@containsComment = 'false')] - [FormalParameter/Type/ReferenceType - /ClassOrInterfaceType[@Image != 'InterruptedException' and @Image != 'CloneNotSupportedException'] - ] - [FormalParameter/VariableDeclaratorId[not(matches(@Image, $allowExceptionNameRegex))]] +//CatchBlockStatement +[./BlockStatement[count(*) = 0]] ``` **Example(s):** @@ -39,60 +35,22 @@ public void doSomething() { } ``` -**This rule has the following properties:** - -|Name|Default Value|Description| -|----|-------------|-----------| -|allowCommentedBlocks|false|Empty blocks containing comments will be skipped| -|allowExceptionNameRegex|^$|Empty blocks catching exceptions with names matching this regular expression will be skipped| - **Use this rule by referencing it:** ``` xml ``` -## EmptyFinallyBlock - -**Since:** PMD 5.8.2 - -**Priority:** Medium (3) - -Empty finally blocks serve no purpose and should be removed. - -``` -//FinallyStatement[count(Block/BlockStatement) = 0] -``` - -**Example(s):** - -``` java -public class Foo { - public void bar() { - try { - Integer x=2; - } finally { - // empty! - } - } -} -``` - -**Use this rule by referencing it:** -``` xml - -``` - ## EmptyIfStmt -**Since:** PMD 5.8.2 +**Since:** PMD 6.0.0 **Priority:** Medium (3) Empty If Statement finds instances where a condition is checked but nothing is done about it. ``` -//IfStatement/Statement - [EmptyStatement or Block[count(*) = 0]] +//IfBlockStatement + [BlockStatement[count(*) = 0]] ``` **Example(s):** @@ -112,67 +70,52 @@ public class Foo { ``` -## EmptyStaticInitializer +## EmptyTryOrFinallyBlock -**Since:** PMD 5.8.2 +**Since:** PMD 6.0.0 **Priority:** Medium (3) -An empty static initializer serve no purpose and should be removed. +Avoid empty try or finally blocks - what's the point? ``` -//Initializer[@Static='true']/Block[count(*)=0] +//TryCatchFinallyBlockStatement[./BlockStatement[count(*) = 0]] ``` **Example(s):** ``` java public class Foo { - static { - // empty + public void bar() { + try { + // empty ! + } catch (Exception e) { + e.printStackTrace(); + } } } -``` -**Use this rule by referencing it:** -``` xml - -``` - -## EmptyTryBlock - -**Since:** PMD 5.8.2 - -**Priority:** Medium (3) - -Avoid empty try blocks - what's the point? - -``` -//TryStatement[not(ResourceSpecification)]/Block[1][count(*) = 0] -``` - -**Example(s):** - -``` java public class Foo { - public void bar() { - try { - // this has no use - } catch (Exception e) { - e.printStackTrace(); + public void bar() { + try { + int x=2; + } catch (Exception e) { + system.debug(e): + } finally { + // empty! + } } - } } ``` **Use this rule by referencing it:** ``` xml - + ``` ## EmptyWhileStmt -**Since:** PMD 5.8.2 +**Since:** PMD 6.0.0 **Priority:** Medium (3) @@ -181,7 +124,7 @@ If it is a timing loop, then you should use Thread.sleep() for it; if it is a while loop that does a lot in the exit expression, rewrite it to make it clearer. ``` -//WhileStatement/Statement[./Block[count(*) = 0] or ./EmptyStatement] +//WhileLoopStatement[./BlockStatement[count(*) = 0]] ``` **Example(s):** diff --git a/pmd-apex/src/main/resources/rulesets/apex/empty.xml b/pmd-apex/src/main/resources/rulesets/apex/empty.xml index 225b4c6073..1fc42ae75c 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/empty.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/empty.xml @@ -25,14 +25,10 @@ or reported. - - @@ -81,6 +77,51 @@ public class Foo { + + + +Avoid empty try or finally blocks - what's the point? + + 3 + + + + + + + + + + + + @@ -111,103 +152,6 @@ public void bar(Integer a, Integer b) { } ]]> - - - - -Avoid empty try blocks - what's the point? - - 3 - - - - - - - - - - - - - - -Empty finally blocks serve no purpose and should be removed. - - 3 - - - - - - - - - - - - - - -An empty static initializer serve no purpose and should be removed. - - 3 - - - - - - - - - - diff --git a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml index ce3cf76c75..89fb089fae 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml @@ -328,8 +328,6 @@ 3 - - @@ -354,25 +352,7 @@ - - 3 - - - - - - - - - 3 - - - - - - - - + 3 diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java index 2f4a80e207..e84da1479e 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java @@ -13,10 +13,8 @@ public class EmptyRulesTest extends SimpleAggregatorTst { @Override public void setUp() { addRule(RULESET, "EmptyCatchBlock"); - addRule(RULESET, "EmptyFinallyBlock"); addRule(RULESET, "EmptyIfStmt"); - addRule(RULESET, "EmptyStaticInitializer"); - addRule(RULESET, "EmptyTryBlock"); + addRule(RULESET, "EmptyTryOrFinallyBlock"); addRule(RULESET, "EmptyWhileStmt"); } } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStaticInitializer.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStaticInitializer.xml deleted file mode 100644 index 5f2e8a69ee..0000000000 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStaticInitializer.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - 1 - - - - - 0 - - - diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml deleted file mode 100644 index 1a0f94a931..0000000000 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryBlock.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - 1 - - - - - 0 - - - diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryOrFinallyBlock.xml similarity index 61% rename from pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml rename to pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryOrFinallyBlock.xml index 2ca8e4a1e5..74700f4dd1 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyFinallyBlock.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyTryOrFinallyBlock.xml @@ -5,6 +5,40 @@ xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> + 1 + + + + + 0 + + + + 1 From 8bc6810196a2da817770455d3b42a9567b8ee77d Mon Sep 17 00:00:00 2001 From: Jan Aertgeerts Date: Tue, 19 Sep 2017 10:21:55 +0200 Subject: [PATCH 11/13] [apex] add empty statement block rule --- docs/pages/pmd/rules/apex/empty.md | 30 ++++++++++++++++ .../main/resources/rulesets/apex/empty.xml | 35 +++++++++++++++++++ .../main/resources/rulesets/apex/ruleset.xml | 9 +++++ .../lang/apex/rule/empty/EmptyRulesTest.java | 1 + .../rule/empty/xml/EmptyStatementBlock.xml | 35 +++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStatementBlock.xml diff --git a/docs/pages/pmd/rules/apex/empty.md b/docs/pages/pmd/rules/apex/empty.md index 7ff4634022..c185ad1fae 100644 --- a/docs/pages/pmd/rules/apex/empty.md +++ b/docs/pages/pmd/rules/apex/empty.md @@ -144,3 +144,33 @@ public class Foo { ``` +## EmptyStatementBlock + +**Since:** PMD 6.0.0 + +**Priority:** Medium (3) + +Empty block statements serve no purpose and should be removed. + +``` +//Method/ModifierNode[@Abstract!='true' and ../BlockStatement[count(*) = 0]] +| //Method/BlockStatement//BlockStatement[count(*) = 0]``` + +**Example(s):** + +``` java +public class Foo { + public void setBar(int bar) { + // empty, not allowed + } + + public abstract void foo() { + // this is allowed + } +} +``` + +**Use this rule by referencing it:** +``` xml + +``` diff --git a/pmd-apex/src/main/resources/rulesets/apex/empty.xml b/pmd-apex/src/main/resources/rulesets/apex/empty.xml index 1fc42ae75c..497d065fe1 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/empty.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/empty.xml @@ -154,4 +154,39 @@ public void bar(Integer a, Integer b) { + + + +Empty block statements serve no purpose and should be removed. + + 3 + + + + + + + + + + + diff --git a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml index 89fb089fae..e820675888 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml @@ -361,4 +361,13 @@ + + 3 + + + + + + + diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java index e84da1479e..3ece406df7 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/empty/EmptyRulesTest.java @@ -16,5 +16,6 @@ public class EmptyRulesTest extends SimpleAggregatorTst { addRule(RULESET, "EmptyIfStmt"); addRule(RULESET, "EmptyTryOrFinallyBlock"); addRule(RULESET, "EmptyWhileStmt"); + addRule(RULESET, "EmptyStatementBlock"); } } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStatementBlock.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStatementBlock.xml new file mode 100644 index 0000000000..d0fd844c87 --- /dev/null +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/empty/xml/EmptyStatementBlock.xml @@ -0,0 +1,35 @@ + + + + + 1 + + + + + 0 + + + From 3c067d807166e64929aeb26c6c5fb296a3fc5d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Sun, 8 Oct 2017 19:55:32 -0300 Subject: [PATCH 12/13] Add references to 6.0.0 release ruleset --- pmd-core/src/main/resources/rulesets/releases/600.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pmd-core/src/main/resources/rulesets/releases/600.xml b/pmd-core/src/main/resources/rulesets/releases/600.xml index cebdca8529..2bf4795f25 100644 --- a/pmd-core/src/main/resources/rulesets/releases/600.xml +++ b/pmd-core/src/main/resources/rulesets/releases/600.xml @@ -11,5 +11,10 @@ This ruleset contains links to rules that are new in PMD v6.0.0 + + + + + From 34a565ca00ca81084a9cc1c30458151a4ccaa929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Sun, 8 Oct 2017 20:00:36 -0300 Subject: [PATCH 13/13] Update changelog, refs #625 --- docs/pages/release_notes.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 9db55ecea6..fbb6f3a4bc 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -105,6 +105,14 @@ and include them to such reports. * The new rule `ForLoopCanBeForeach` (ruleset `java-migration`) helps to identify those for-loops that can be safely refactored into for-each-loops available since java 1.5. +* A whole new ruleset has been added to Apex, `apex-empty`. It currently migrates 5 rules from the equivalent + `java-empty` ruleset for Apex. The ruleset includes: + * `EmptyCatchBlock` to detect catch blocks completely ignoring exceptions. + * `EmptyIfStmt` for if blocks with no content, that can be safely removed. + * `EmptyTryOrFinallyBlock` for empty try / finally blocks that can be safely removed. + * `EmptyWhileStmt` for empty while loops that can be safely removed. + * `EmptyStatementBlock` for empty code blocks that can be safely removed. + #### Modified Rules * The rule `UnnecessaryFinalModifier` (ruleset `java-unnecessarycode`) has been revamped to detect more cases. @@ -292,4 +300,5 @@ All existing rules have been updated to reflect these changes. If you have custo * [#588](https://github.com/pmd/pmd/pull/588): \[java] XPath function to compute metrics - [Clément Fournier](https://github.com/oowekyala) * [#598](https://github.com/pmd/pmd/pull/598): \[java] Fix #388: controversial.AvoidLiteralsInIfCondition 0.0 false positive - [Clément Fournier](https://github.com/oowekyala) * [#620](https://github.com/pmd/pmd/pull/620): \[core] Moved properties to n.s.pmd.properties - [Clément Fournier](https://github.com/oowekyala) +* [#625](https://github.com/pmd/pmd/pull/625): \[apex] empty code ruleset for apex - [Jan Aertgeerts](https://github.com/JAertgeerts)