<?xml version="1.0"?>

<ruleset name="Code Style"
         xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">

    <description>
Rules which enforce a specific coding style.
    </description>

    <rule name="ClassNamingConventions"
          since="5.5.0"
          message="Class names should begin with an uppercase character"
          class="net.sourceforge.pmd.lang.apex.rule.codestyle.ClassNamingConventionsRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#classnamingconventions">
        <description>
Class names should always begin with an upper case character.
        </description>
        <priority>1</priority>
        <example>
<![CDATA[
public class Foo {}
]]>
        </example>
    </rule>

    <rule name="IfElseStmtsMustUseBraces"
          language="apex"
          since="5.6.0"
          message="Avoid using 'if...else' statements without curly braces"
          class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#ifelsestmtsmustusebraces">
        <description>
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.
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//IfBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0]
|
//IfElseBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0]
]]>
                </value>
            </property>
        </properties>
        <example>
<![CDATA[
// this is OK
if (foo) x++;

// but this is not
if (foo)
    x = x+1;
else
    x = x-1;
]]>
        </example>
    </rule>

    <rule name="IfStmtsMustUseBraces"
          language="apex"
          since="5.6.0"
          message="Avoid using if statements without curly braces"
          class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#ifstmtsmustusebraces">
        <description>
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.
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//IfBlockStatement/BlockStatement[@CurlyBrace='false']
]]>
                </value>
            </property>
        </properties>
        <example>
 <![CDATA[
if (foo)    // not recommended
    x++;

if (foo) {  // preferred approach
    x++;
}
]]>
        </example>
    </rule>

    <rule name="ForLoopsMustUseBraces"
          language="apex"
          since="5.6.0"
          message="Avoid using 'for' statements without curly braces"
          class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#forloopsmustusebraces">
        <description>
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.
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//ForLoopStatement/BlockStatement[@CurlyBrace='false']
|
//ForEachStatement/BlockStatement[@CurlyBrace='false']
]]>
                </value>
            </property>
        </properties>
        <example>
<![CDATA[
for (int i = 0; i < 42; i++) // not recommended
    foo();

for (int i = 0; i < 42; i++) { // preferred approach
    foo();
}
]]>
        </example>
    </rule>

    <rule name="MethodNamingConventions"
          since="5.5.0"
          message="Method name does not begin with a lower case character."
          class="net.sourceforge.pmd.lang.apex.rule.codestyle.MethodNamingConventionsRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#methodnamingconventions">
        <description>
Method names should always begin with a lower case character, and should not contain underscores.
        </description>
        <priority>1</priority>
        <example>
<![CDATA[
public class Foo {
    public void fooStuff() {
    }
}
]]>
        </example>
    </rule>

    <rule name="VariableNamingConventions"
          since="5.5.0"
          message="{0} variable {1} should begin with {2}"
          class="net.sourceforge.pmd.lang.apex.rule.codestyle.VariableNamingConventionsRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#variablenamingconventions">
        <description>
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.
        </description>
        <priority>1</priority>
        <example>
<![CDATA[
public class Foo {
    public static final Integer MY_NUM = 0;
    public String myTest = '';
    DataModule dmTest = new DataModule();
}
]]>
        </example>
    </rule>

    <rule name="WhileLoopsMustUseBraces"
          language="apex"
          since="5.6.0"
          message="Avoid using 'while' statements without curly braces"
          class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_codestyle.html#whileloopsmustusebraces">
        <description>
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.
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
                <value>
<![CDATA[
//WhileLoopStatement/BlockStatement[@CurlyBrace='false']
]]>
                </value>
            </property>
        </properties>
        <example>
<![CDATA[
while (true)    // not recommended
    x++;

while (true) {  // preferred approach
    x++;
}
]]>
        </example>
    </rule>

</ruleset>
