ClassNamingConventions
Since: PMD 5.5.0
Priority: High (1)
Class names should always begin with an upper case character.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.apex.rule.codestyle.ClassNamingConventionsRule
Example(s):
public class Foo {}
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
cc_categories | Style | Code Climate Categories | yes. Delimiter is ‘|’. |
cc_remediation_points_multiplier | 1 | Code Climate Remediation Points multiplier | no |
cc_block_highlighting | false | Code Climate Block Highlighting | no |
Use this rule by referencing it:
<rule ref="category/apex/codestyle.xml/ClassNamingConventions" />
ForLoopsMustUseBraces
Since: PMD 5.6.0
Priority: Medium (3)
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 from the rest.
This rule is defined by the following XPath expression:
//ForLoopStatement/BlockStatement[@CurlyBrace='false']
|
//ForEachStatement/BlockStatement[@CurlyBrace='false']
Example(s):
for (int i = 0; i < 42; i++) // not recommended
foo();
for (int i = 0; i < 42; i++) { // preferred approach
foo();
}
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
cc_categories | Style | Code Climate Categories | yes. Delimiter is ‘|’. |
cc_remediation_points_multiplier | 1 | Code Climate Remediation Points multiplier | no |
cc_block_highlighting | false | Code Climate Block Highlighting | no |
Use this rule by referencing it:
<rule ref="category/apex/codestyle.xml/ForLoopsMustUseBraces" />
IfElseStmtsMustUseBraces
Since: PMD 5.6.0
Priority: Medium (3)
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 from the rest.
This rule is defined by the following XPath expression:
//IfBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0]
|
//IfElseBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0]
Example(s):
// this is OK
if (foo) x++;
// but this is not
if (foo)
x = x+1;
else
x = x-1;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
cc_categories | Style | Code Climate Categories | yes. Delimiter is ‘|’. |
cc_remediation_points_multiplier | 1 | Code Climate Remediation Points multiplier | no |
cc_block_highlighting | false | Code Climate Block Highlighting | no |
Use this rule by referencing it:
<rule ref="category/apex/codestyle.xml/IfElseStmtsMustUseBraces" />
IfStmtsMustUseBraces
Since: PMD 5.6.0
Priority: Medium (3)
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 controlled from the rest.
This rule is defined by the following XPath expression:
//IfBlockStatement/BlockStatement[@CurlyBrace='false']
Example(s):
if (foo) // not recommended
x++;
if (foo) { // preferred approach
x++;
}
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
cc_categories | Style | Code Climate Categories | yes. Delimiter is ‘|’. |
cc_remediation_points_multiplier | 1 | Code Climate Remediation Points multiplier | no |
cc_block_highlighting | false | Code Climate Block Highlighting | no |
Use this rule by referencing it:
<rule ref="category/apex/codestyle.xml/IfStmtsMustUseBraces" />
MethodNamingConventions
Since: PMD 5.5.0
Priority: High (1)
Method names should always begin with a lower case character, and should not contain underscores.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.apex.rule.codestyle.MethodNamingConventionsRule
Example(s):
public class Foo {
public void fooStuff() {
}
}
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
cc_categories | Style | Code Climate Categories | yes. Delimiter is ‘|’. |
cc_remediation_points_multiplier | 1 | Code Climate Remediation Points multiplier | no |
cc_block_highlighting | false | Code Climate Block Highlighting | no |
skipTestMethodUnderscores | false | Skip underscores in test methods | no |
Use this rule by referencing it:
<rule ref="category/apex/codestyle.xml/MethodNamingConventions" />
OneDeclarationPerLine
Since: PMD 6.7.0
Priority: High (1)
Apex allows the use of several variables declaration of the same type on one line. However, it can lead to quite messy code. This rule looks for several declarations on the same line.
This rule is defined by the following XPath expression:
//VariableDeclarationStatements
[count(VariableDeclaration) > 1]
[$strictMode or count(distinct-values(VariableDeclaration/@BeginLine)) != count(VariableDeclaration)]
|
//FieldDeclarationStatements
[count(FieldDeclaration) > 1]
[$strictMode or count(distinct-values(FieldDeclaration/VariableExpression/@BeginLine)) != count(FieldDeclaration/VariableExpression)]
Example(s):
Integer a, b; // not recommended
Integer a,
b; // ok by default, can be flagged setting the strictMode property
Integer a; // preferred approach
Integer b;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
cc_categories | Style | Code Climate Categories | yes. Delimiter is ‘|’. |
cc_remediation_points_multiplier | 1 | Code Climate Remediation Points multiplier | no |
cc_block_highlighting | false | Code Climate Block Highlighting | no |
strictMode | false | If true, mark combined declaration even if the declarations are on separate lines. | no |
Use this rule by referencing it:
<rule ref="category/apex/codestyle.xml/OneDeclarationPerLine" />
VariableNamingConventions
Since: PMD 5.5.0
Priority: High (1)
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 that should not include underscores.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.apex.rule.codestyle.VariableNamingConventionsRule
Example(s):
public class Foo {
public static final Integer MY_NUM = 0;
public String myTest = '';
DataModule dmTest = new DataModule();
}
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
cc_categories | Style | Code Climate Categories | yes. Delimiter is ‘|’. |
cc_remediation_points_multiplier | 1 | Code Climate Remediation Points multiplier | no |
cc_block_highlighting | false | Code Climate Block Highlighting | no |
checkMembers | true | Check member variables | no |
checkLocals | true | Check local variables | no |
checkParameters | true | Check constructor and method parameter variables | no |
staticPrefix | Static variable prefixes | yes. Delimiter is ‘,’. | |
staticSuffix | Static variable suffixes | yes. Delimiter is ‘,’. | |
memberPrefix | Member variable prefixes | yes. Delimiter is ‘,’. | |
memberSuffix | Member variable suffixes | yes. Delimiter is ‘,’. | |
localPrefix | Local variable prefixes | yes. Delimiter is ‘,’. | |
localSuffix | Local variable suffixes | yes. Delimiter is ‘,’. | |
parameterPrefix | Method parameter variable prefixes | yes. Delimiter is ‘,’. | |
parameterSuffix | Method parameter variable suffixes | yes. Delimiter is ‘,’. |
Use this rule by referencing it:
<rule ref="category/apex/codestyle.xml/VariableNamingConventions" />
WhileLoopsMustUseBraces
Since: PMD 5.6.0
Priority: Medium (3)
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 controlled from the rest.
This rule is defined by the following XPath expression:
//WhileLoopStatement/BlockStatement[@CurlyBrace='false']
Example(s):
while (true) // not recommended
x++;
while (true) { // preferred approach
x++;
}
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
cc_categories | Style | Code Climate Categories | yes. Delimiter is ‘|’. |
cc_remediation_points_multiplier | 1 | Code Climate Remediation Points multiplier | no |
cc_block_highlighting | false | Code Climate Block Highlighting | no |
Use this rule by referencing it:
<rule ref="category/apex/codestyle.xml/WhileLoopsMustUseBraces" />