[doc] [apex] Adjust externalInfoUrl properties to new site - Part 5
Note: I also took the chance to fix tab damage
This commit is contained in:
@ -20,7 +20,7 @@ import net.sourceforge.pmd.lang.apex.ast.ApexNode;
|
|||||||
*
|
*
|
||||||
* @author a.subramanian
|
* @author a.subramanian
|
||||||
*/
|
*/
|
||||||
public class ApexUnitTestClassShouldHaveAsserts extends AbstractApexUnitTestRule {
|
public class ApexUnitTestClassShouldHaveAssertsRule extends AbstractApexUnitTestRule {
|
||||||
|
|
||||||
private static final Set<String> ASSERT_METHODS = new HashSet<>();
|
private static final Set<String> ASSERT_METHODS = new HashSet<>();
|
||||||
|
|
@ -25,7 +25,7 @@ import apex.jorje.services.Version;
|
|||||||
*
|
*
|
||||||
* @author a.subramanian
|
* @author a.subramanian
|
||||||
*/
|
*/
|
||||||
public class ApexUnitTestShouldNotUseSeeAllDataTrue extends AbstractApexUnitTestRule {
|
public class ApexUnitTestShouldNotUseSeeAllDataTrueRule extends AbstractApexUnitTestRule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(final ASTUserClass node, final Object data) {
|
public Object visit(final ASTUserClass node, final Object data) {
|
@ -11,8 +11,8 @@
|
|||||||
<rule name="ApexUnitTestClassShouldHaveAsserts"
|
<rule name="ApexUnitTestClassShouldHaveAsserts"
|
||||||
since="5.5.1"
|
since="5.5.1"
|
||||||
message="Apex unit tests should System.assert() or assertEquals() or assertNotEquals()"
|
message="Apex unit tests should System.assert() or assertEquals() or assertNotEquals()"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.apexunit.ApexUnitTestClassShouldHaveAsserts"
|
class="net.sourceforge.pmd.lang.apex.rule.apexunit.ApexUnitTestClassShouldHaveAssertsRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/apexunit.html#ApexUnitTestClassShouldHaveAsserts">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_apexunit.html#apexunittestclassshouldhaveasserts">
|
||||||
<description>
|
<description>
|
||||||
Apex unit tests should include at least one assertion. This makes the tests more robust, and using assert
|
Apex unit tests should include at least one assertion. This makes the tests more robust, and using assert
|
||||||
with messages provide the developer a clearer idea of what the test does.
|
with messages provide the developer a clearer idea of what the test does.
|
||||||
@ -35,8 +35,8 @@ public class Foo {
|
|||||||
<rule name="ApexUnitTestShouldNotUseSeeAllDataTrue"
|
<rule name="ApexUnitTestShouldNotUseSeeAllDataTrue"
|
||||||
since="5.5.1"
|
since="5.5.1"
|
||||||
message="Apex unit tests should not use @isTest(seeAllData = true)"
|
message="Apex unit tests should not use @isTest(seeAllData = true)"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.apexunit.ApexUnitTestShouldNotUseSeeAllDataTrue"
|
class="net.sourceforge.pmd.lang.apex.rule.apexunit.ApexUnitTestShouldNotUseSeeAllDataTrueRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/apexunit.html#ApexUnitTestShouldNotUseSeeAllDataTrue">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_apexunit.html#apexunittestshouldnotuseseealldatatrue">
|
||||||
<description>
|
<description>
|
||||||
Apex unit tests should not use @isTest(seeAllData=true) because it opens up the existing database data for unexpected modification by tests.
|
Apex unit tests should not use @isTest(seeAllData=true) because it opens up the existing database data for unexpected modification by tests.
|
||||||
</description>
|
</description>
|
||||||
|
@ -8,135 +8,133 @@
|
|||||||
The Braces ruleset contains rules regarding the use and placement of braces.
|
The Braces ruleset contains rules regarding the use and placement of braces.
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<rule name="IfStmtsMustUseBraces"
|
<rule name="IfStmtsMustUseBraces"
|
||||||
language="apex"
|
language="apex"
|
||||||
since="5.6.0"
|
since="5.6.0"
|
||||||
message="Avoid using if statements without curly braces"
|
message="Avoid using if statements without curly braces"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/braces.html#IfStmtsMustUseBraces">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_braces.html#ifstmtsmustusebraces">
|
||||||
<description>
|
<description>
|
||||||
Avoid using if statements without using braces to surround the code block. If the code
|
Avoid using if statements without using braces to surround the code block. If the code
|
||||||
formatting or indentation is lost then it becomes difficult to separate the code being
|
formatting or indentation is lost then it becomes difficult to separate the code being
|
||||||
controlled from the rest.
|
controlled from the rest.
|
||||||
</description>
|
</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
<value>
|
<value>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
//IfBlockStatement/BlockStatement[@CurlyBrace='false']
|
//IfBlockStatement/BlockStatement[@CurlyBrace='false']
|
||||||
]]>
|
]]>
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
</properties>
|
</properties>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
|
if (foo) // not recommended
|
||||||
|
x++;
|
||||||
|
|
||||||
if (foo) // not recommended
|
if (foo) { // preferred approach
|
||||||
x++;
|
x++;
|
||||||
|
|
||||||
if (foo) { // preferred approach
|
|
||||||
x++;
|
|
||||||
}
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
]]>
|
<rule name="WhileLoopsMustUseBraces"
|
||||||
</example>
|
language="apex"
|
||||||
</rule>
|
since="5.6.0"
|
||||||
|
message="Avoid using 'while' statements without curly braces"
|
||||||
<rule name="WhileLoopsMustUseBraces"
|
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
||||||
language="apex"
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_braces.html#whileloopsmustusebraces">
|
||||||
since="5.6.0"
|
<description>
|
||||||
message="Avoid using 'while' statements without curly braces"
|
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/braces.html#WhileLoopsMustUseBraces">
|
|
||||||
<description>
|
|
||||||
Avoid using 'while' statements without using braces to surround the code block. If the code
|
Avoid using 'while' statements without using braces to surround the code block. If the code
|
||||||
formatting or indentation is lost then it becomes difficult to separate the code being
|
formatting or indentation is lost then it becomes difficult to separate the code being
|
||||||
controlled from the rest.
|
controlled from the rest.
|
||||||
</description>
|
</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
<value>
|
<value>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
//WhileLoopStatement/BlockStatement[@CurlyBrace='false']
|
//WhileLoopStatement/BlockStatement[@CurlyBrace='false']
|
||||||
]]>
|
]]>
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
</properties>
|
</properties>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
while (true) // not recommended
|
while (true) // not recommended
|
||||||
x++;
|
x++;
|
||||||
|
|
||||||
while (true) { // preferred approach
|
while (true) { // preferred approach
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<rule name="IfElseStmtsMustUseBraces"
|
<rule name="IfElseStmtsMustUseBraces"
|
||||||
language="apex"
|
language="apex"
|
||||||
since="5.6.0"
|
since="5.6.0"
|
||||||
message="Avoid using 'if...else' statements without curly braces"
|
message="Avoid using 'if...else' statements without curly braces"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/braces.html#IfElseStmtsMustUseBraces">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_braces.html#ifelsestmtsmustusebraces">
|
||||||
<description>
|
<description>
|
||||||
Avoid using if..else statements without using surrounding braces. If the code formatting
|
Avoid using if..else statements without using surrounding braces. If the code formatting
|
||||||
or indentation is lost then it becomes difficult to separate the code being controlled
|
or indentation is lost then it becomes difficult to separate the code being controlled
|
||||||
from the rest.
|
from the rest.
|
||||||
</description>
|
</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
<value>
|
<value>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
//IfBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0]
|
//IfBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0]
|
||||||
|
|
|
|
||||||
//IfElseBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0]
|
//IfElseBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0]
|
||||||
]]>
|
]]>
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
</properties>
|
</properties>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
// this is OK
|
// this is OK
|
||||||
if (foo) x++;
|
if (foo) x++;
|
||||||
|
|
||||||
// but this is not
|
// but this is not
|
||||||
if (foo)
|
if (foo)
|
||||||
x = x+1;
|
x = x+1;
|
||||||
else
|
else
|
||||||
x = x-1;
|
x = x-1;
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<rule name="ForLoopsMustUseBraces"
|
<rule name="ForLoopsMustUseBraces"
|
||||||
language="apex"
|
language="apex"
|
||||||
since="5.6.0"
|
since="5.6.0"
|
||||||
message="Avoid using 'for' statements without curly braces"
|
message="Avoid using 'for' statements without curly braces"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/braces.html#ForLoopsMustUseBraces">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_braces.html#forloopsmustusebraces">
|
||||||
<description>
|
<description>
|
||||||
Avoid using 'for' statements without using surrounding braces. If the code formatting or
|
Avoid using 'for' statements without using surrounding braces. If the code formatting or
|
||||||
indentation is lost then it becomes difficult to separate the code being controlled
|
indentation is lost then it becomes difficult to separate the code being controlled
|
||||||
from the rest.
|
from the rest.
|
||||||
</description>
|
</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<properties>
|
<properties>
|
||||||
<property name="xpath">
|
<property name="xpath">
|
||||||
<value>
|
<value>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
//ForLoopStatement/BlockStatement[@CurlyBrace='false']
|
//ForLoopStatement/BlockStatement[@CurlyBrace='false']
|
||||||
|
|
|
|
||||||
//ForEachStatement/BlockStatement[@CurlyBrace='false']
|
//ForEachStatement/BlockStatement[@CurlyBrace='false']
|
||||||
]]>
|
]]>
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
</properties>
|
</properties>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
for (int i = 0; i < 42; i++) // not recommended
|
for (int i = 0; i < 42; i++) // not recommended
|
||||||
foo();
|
foo();
|
||||||
@ -145,7 +143,7 @@ for (int i = 0; i < 42; i++) { // preferred approach
|
|||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
</ruleset>
|
</ruleset>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,7 @@
|
|||||||
since="6.0.0"
|
since="6.0.0"
|
||||||
class="net.sourceforge.pmd.lang.apex.metrics.rule.CyclomaticComplexityRule"
|
class="net.sourceforge.pmd.lang.apex.metrics.rule.CyclomaticComplexityRule"
|
||||||
metrics="true"
|
metrics="true"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/metrics.html#CyclomaticComplexity">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_metrics.html#cyclomaticcomplexity">
|
||||||
<description>
|
<description>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
The complexity of methods directly affects maintenance costs and readability. Concentrating too much decisional logic
|
The complexity of methods directly affects maintenance costs and readability. Concentrating too much decisional logic
|
||||||
|
@ -12,18 +12,19 @@ The Performance ruleset contains a collection of good practices which should be
|
|||||||
since="5.5.0"
|
since="5.5.0"
|
||||||
message="Avoid Soql queries inside loops"
|
message="Avoid Soql queries inside loops"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.performance.AvoidSoqlInLoopsRule"
|
class="net.sourceforge.pmd.lang.apex.rule.performance.AvoidSoqlInLoopsRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/performance.html#AvoidSoqlInLoops">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_performance.html#avoidsoqlinloops">
|
||||||
<description>
|
<description>
|
||||||
New objects created within loops should be checked to see if they can created outside them and reused.
|
New objects created within loops should be checked to see if they can created outside them and reused.
|
||||||
</description>
|
</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[public class Something {
|
<![CDATA[
|
||||||
public static void main( String as[] ) {
|
public class Something {
|
||||||
for (Integer i = 0; i < 10; i++) {
|
public static void main( String as[] ) {
|
||||||
List<Account> accounts = [SELECT Id FROM Account];
|
for (Integer i = 0; i < 10; i++) {
|
||||||
}
|
List<Account> accounts = [SELECT Id FROM Account];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
@ -33,19 +34,21 @@ New objects created within loops should be checked to see if they can created ou
|
|||||||
since="5.5.0"
|
since="5.5.0"
|
||||||
message="Avoid DML statements inside loops"
|
message="Avoid DML statements inside loops"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.performance.AvoidDmlStatementsInLoopsRule"
|
class="net.sourceforge.pmd.lang.apex.rule.performance.AvoidDmlStatementsInLoopsRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/performance.html#AvoidDmlStatementsInLoops">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_performance.html#avoiddmlstatementsinloops">
|
||||||
<description>Avoid DML statements inside loops to avoid hitting the DML governor limit. Instead, try to batch up the data into a list and invoke your DML once on that list of data outside the loop.</description>
|
<description>
|
||||||
<priority>3</priority>
|
Avoid DML statements inside loops to avoid hitting the DML governor limit. Instead, try to batch up the data into a list and invoke your DML once on that list of data outside the loop.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
public class Something {
|
public class Something {
|
||||||
public void foo() {
|
public void foo() {
|
||||||
for (Integer i = 0; i < 151; i++) {
|
for (Integer i = 0; i < 151; i++) {
|
||||||
Account account;
|
Account account;
|
||||||
...
|
// ...
|
||||||
insert account;
|
insert account;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
|
@ -2,4 +2,10 @@
|
|||||||
# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||||
#
|
#
|
||||||
|
|
||||||
rulesets.filenames=rulesets/apex/complexity.xml,rulesets/apex/performance.xml,rulesets/apex/style.xml,rulesets/apex/apexunit.xml,rulesets/apex/security.xml,rulesets/apex/braces.xml
|
rulesets.filenames=\
|
||||||
|
rulesets/apex/apexunit.xml,\
|
||||||
|
rulesets/apex/braces.xml,\
|
||||||
|
rulesets/apex/complexity.xml,\
|
||||||
|
rulesets/apex/performance.xml,\
|
||||||
|
rulesets/apex/security.xml,\
|
||||||
|
rulesets/apex/style.xml
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -8,105 +8,110 @@
|
|||||||
The Style Ruleset contains rules regarding preferred usage of names and identifiers.
|
The Style Ruleset contains rules regarding preferred usage of names and identifiers.
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<rule name="VariableNamingConventions"
|
<rule name="VariableNamingConventions"
|
||||||
since="5.5.0"
|
since="5.5.0"
|
||||||
message="{0} variable {1} should begin with {2}"
|
message="{0} variable {1} should begin with {2}"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.style.VariableNamingConventionsRule"
|
class="net.sourceforge.pmd.lang.apex.rule.style.VariableNamingConventionsRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/style.html#VariableNamingConventions">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_style.html#variablenamingconventions">
|
||||||
<description>
|
<description>
|
||||||
A variable naming conventions rule - customize this to your liking. Currently, it
|
A variable naming conventions rule - customize this to your liking. Currently, it
|
||||||
checks for final variables that should be fully capitalized and non-final variables
|
checks for final variables that should be fully capitalized and non-final variables
|
||||||
that should not include underscores.
|
that should not include underscores.
|
||||||
</description>
|
</description>
|
||||||
<priority>1</priority>
|
<priority>1</priority>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[public class Foo {
|
<![CDATA[
|
||||||
public static final Integer MY_NUM = 0;
|
public class Foo {
|
||||||
public String myTest = '';
|
public static final Integer MY_NUM = 0;
|
||||||
DataModule dmTest = new DataModule();
|
public String myTest = '';
|
||||||
|
DataModule dmTest = new DataModule();
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<rule name="MethodNamingConventions"
|
<rule name="MethodNamingConventions"
|
||||||
since="5.5.0"
|
since="5.5.0"
|
||||||
message="Method name does not begin with a lower case character."
|
message="Method name does not begin with a lower case character."
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.style.MethodNamingConventionsRule"
|
class="net.sourceforge.pmd.lang.apex.rule.style.MethodNamingConventionsRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/style.html#MethodNamingConventions">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_style.html#methodnamingconventions">
|
||||||
<description>
|
<description>
|
||||||
Method names should always begin with a lower case character, and should not contain underscores.
|
Method names should always begin with a lower case character, and should not contain underscores.
|
||||||
</description>
|
</description>
|
||||||
<priority>1</priority>
|
<priority>1</priority>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[public class Foo {
|
<![CDATA[
|
||||||
public void fooStuff() {
|
public class Foo {
|
||||||
}
|
public void fooStuff() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<rule name="ClassNamingConventions"
|
<rule name="ClassNamingConventions"
|
||||||
since="5.5.0"
|
since="5.5.0"
|
||||||
message="Class names should begin with an uppercase character"
|
message="Class names should begin with an uppercase character"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.style.ClassNamingConventionsRule"
|
class="net.sourceforge.pmd.lang.apex.rule.style.ClassNamingConventionsRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/style.html#ClassNamingConventions">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_style.html#classnamingconventions">
|
||||||
<description>
|
<description>
|
||||||
Class names should always begin with an upper case character.
|
Class names should always begin with an upper case character.
|
||||||
</description>
|
</description>
|
||||||
<priority>1</priority>
|
<priority>1</priority>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[public class Foo {}
|
<![CDATA[
|
||||||
|
public class Foo {}
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<rule name="MethodWithSameNameAsEnclosingClass"
|
<rule name="MethodWithSameNameAsEnclosingClass"
|
||||||
since="5.5.0"
|
since="5.5.0"
|
||||||
message="Classes should not have non-constructor methods with the same name as the class"
|
message="Classes should not have non-constructor methods with the same name as the class"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.style.MethodWithSameNameAsEnclosingClassRule"
|
class="net.sourceforge.pmd.lang.apex.rule.style.MethodWithSameNameAsEnclosingClassRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/style.html#MethodWithSameNameAsEnclosingClass">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_style.html#methodwithsamenameasenclosingclass">
|
||||||
<description>
|
<description>
|
||||||
Non-constructor methods should not have the same name as the enclosing class.
|
Non-constructor methods should not have the same name as the enclosing class.
|
||||||
</description>
|
</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[public class MyClass {
|
<![CDATA[
|
||||||
// this is OK because it is a constructor
|
public class MyClass {
|
||||||
public MyClass() {}
|
// this is OK because it is a constructor
|
||||||
// this is bad because it is a method
|
public MyClass() {}
|
||||||
public void MyClass() {}
|
// this is bad because it is a method
|
||||||
|
public void MyClass() {}
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<rule name="AvoidLogicInTrigger"
|
<rule name="AvoidLogicInTrigger"
|
||||||
since="5.5.0"
|
since="5.5.0"
|
||||||
message="Avoid logic in triggers"
|
message="Avoid logic in triggers"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.style.AvoidLogicInTriggerRule"
|
class="net.sourceforge.pmd.lang.apex.rule.style.AvoidLogicInTriggerRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/style.html#AvoidLogicInTrigger">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_style.html#avoidlogicintrigger">
|
||||||
<description>
|
<description>
|
||||||
As triggers do not allow methods like regular classes they are less flexible and suited to apply good encapsulation style.
|
As triggers do not allow methods like regular classes they are less flexible and suited to apply good encapsulation style.
|
||||||
Therefore delegate the triggers work to a regular class (often called Trigger handler class).
|
Therefore delegate the triggers work to a regular class (often called Trigger handler class).
|
||||||
|
|
||||||
See more here: https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices
|
See more here: https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex_Trigger_Best_Practices
|
||||||
</description>
|
</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[trigger Accounts on Account (before insert, before update, before delete, after insert, after update, after delete, after undelete) {
|
<![CDATA[
|
||||||
for(Account acc : Trigger.new) {
|
trigger Accounts on Account (before insert, before update, before delete, after insert, after update, after delete, after undelete) {
|
||||||
if(Trigger.isInsert) {
|
for(Account acc : Trigger.new) {
|
||||||
...
|
if(Trigger.isInsert) {
|
||||||
}
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
...
|
// ...
|
||||||
|
|
||||||
if(Trigger.isDelete) {
|
if(Trigger.isDelete) {
|
||||||
...
|
// ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
@ -116,17 +121,18 @@ See more here: https://developer.salesforce.com/page/Trigger_Frameworks_and_Apex
|
|||||||
since="5.5.0"
|
since="5.5.0"
|
||||||
message="Avoid using global modifier"
|
message="Avoid using global modifier"
|
||||||
class="net.sourceforge.pmd.lang.apex.rule.style.AvoidGlobalModifierRule"
|
class="net.sourceforge.pmd.lang.apex.rule.style.AvoidGlobalModifierRule"
|
||||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/style.html#AvoidGlobalModifier">
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_style.html#avoidglobalmodifier">
|
||||||
<description>
|
<description>
|
||||||
Global classes should be avoided (especially in managed packages) as they can never be deleted or changed in signature. Always check twice if something needs to be global.
|
Global classes should be avoided (especially in managed packages) as they can never be deleted or changed in signature. Always check twice if something needs to be global.
|
||||||
Many interfaces (e.g. Batch) required global modifiers in the past but don't require this anymore. Don't lock yourself in.
|
Many interfaces (e.g. Batch) required global modifiers in the past but don't require this anymore. Don't lock yourself in.
|
||||||
</description>
|
</description>
|
||||||
<priority>3</priority>
|
<priority>3</priority>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[global class Unchangeable {
|
<![CDATA[
|
||||||
global UndeletableType unchangable(UndeletableType param) {
|
global class Unchangeable {
|
||||||
// ...
|
global UndeletableType unchangable(UndeletableType param) {
|
||||||
}
|
// ...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</example>
|
</example>
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.sourceforge.pmd.lang.apex;
|
||||||
|
|
||||||
|
import net.sourceforge.pmd.AbstractRuleSetFactoryTest;
|
||||||
|
import net.sourceforge.pmd.lang.apex.rule.ApexXPathRule;
|
||||||
|
|
||||||
|
public class RuleSetFactoryTest extends AbstractRuleSetFactoryTest {
|
||||||
|
public RuleSetFactoryTest() {
|
||||||
|
super();
|
||||||
|
validXPathClassNames.add(ApexXPathRule.class.getName());
|
||||||
|
}
|
||||||
|
}
|
@ -17,10 +17,13 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import javax.xml.parsers.SAXParser;
|
import javax.xml.parsers.SAXParser;
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
@ -49,6 +52,12 @@ public abstract class AbstractRuleSetFactoryTest {
|
|||||||
private static ValidateDefaultHandler validateDefaultHandlerDtd;
|
private static ValidateDefaultHandler validateDefaultHandlerDtd;
|
||||||
private static SAXParser saxParser;
|
private static SAXParser saxParser;
|
||||||
|
|
||||||
|
protected Set<String> validXPathClassNames = new HashSet<>();
|
||||||
|
|
||||||
|
public AbstractRuleSetFactoryTest() {
|
||||||
|
validXPathClassNames.add(XPathRule.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setups the XML parser with validation.
|
* Setups the XML parser with validation.
|
||||||
*
|
*
|
||||||
@ -134,7 +143,7 @@ public abstract class AbstractRuleSetFactoryTest {
|
|||||||
String expectedClassName = "net.sourceforge.pmd.lang." + language.getTerseName() + ".rule." + group
|
String expectedClassName = "net.sourceforge.pmd.lang." + language.getTerseName() + ".rule." + group
|
||||||
+ "." + rule.getName() + "Rule";
|
+ "." + rule.getName() + "Rule";
|
||||||
if (!rule.getRuleClass().equals(expectedClassName)
|
if (!rule.getRuleClass().equals(expectedClassName)
|
||||||
&& !rule.getRuleClass().equals(XPathRule.class.getName())) {
|
&& !validXPathClassNames.contains(rule.getRuleClass())) {
|
||||||
invalidClassName++;
|
invalidClassName++;
|
||||||
messages += "Rule " + fileName + "/" + rule.getName() + " seems to have an invalid 'class' value ("
|
messages += "Rule " + fileName + "/" + rule.getName() + " seems to have an invalid 'class' value ("
|
||||||
+ rule.getRuleClass() + "), it should be:" + expectedClassName + PMD.EOL;
|
+ rule.getRuleClass() + "), it should be:" + expectedClassName + PMD.EOL;
|
||||||
|
Reference in New Issue
Block a user