Rules which enforce a specific coding style.
Edit me

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

Use this rule by referencing it:

<rule ref="category/apex/codestyle.xml/MethodNamingConventions" />

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
parameterSuffix   Method parameter variable suffixes yes. Delimiter is ‘,’.
parameterPrefix   Method parameter variable prefixes yes. Delimiter is ‘,’.
localSuffix   Local variable suffixes yes. Delimiter is ‘,’.
localPrefix   Local variable prefixes yes. Delimiter is ‘,’.
memberSuffix   Member variable suffixes yes. Delimiter is ‘,’.
memberPrefix   Member variable prefixes yes. Delimiter is ‘,’.
staticSuffix   Static variable suffixes yes. Delimiter is ‘,’.
staticPrefix   Static variable prefixes yes. Delimiter is ‘,’.
checkParameters true Check constructor and method parameter variables no
checkLocals true Check local variables no
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

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" />