<?xml version="1.0"?>
<ruleset name="Custom Rules"
    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 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">

    <description>PMD Rules</description>

    <!--
    * Note on priorities:
    *   1: hihgest level
    *   5: lowest level
    *
    *   1: must fix (CI will stop on any of those)
    *   2: should fix (CI might refuse the PR). Not fixing those will make the code difficult to understand, test or debug.
    *   3: default value
    *   4: generic code style, naming conventions, etc..
    *   5: for information no immediate action required
    -->

    <!-- best practices -->
    <rule ref="category/apex/bestpractices.xml/ApexAssertionsShouldIncludeMessage">
        <priority>5</priority>
    </rule>
    <rule ref="category/apex/bestpractices.xml/ApexUnitTestClassShouldHaveAsserts">
        <priority>3</priority>
    </rule>
    <rule ref="category/apex/bestpractices.xml/ApexUnitTestMethodShouldHaveIsTestAnnotation">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/bestpractices.xml/ApexUnitTestShouldNotUseSeeAllDataTrue">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/bestpractices.xml/AvoidGlobalModifier">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/bestpractices.xml/AvoidLogicInTrigger">
        <priority>3</priority>
    </rule>
    <rule ref="category/apex/bestpractices.xml/DebugsShouldUseLoggingLevel">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/bestpractices.xml/UnusedLocalVariable">
        <priority>1</priority>
    </rule>

    <!-- codestyle -->
    <rule ref="category/apex/codestyle.xml/ClassNamingConventions">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/codestyle.xml/FieldDeclarationsShouldBeAtStart">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/codestyle.xml/FieldNamingConventions">
        <priority>3</priority>
    </rule>
    <rule ref="category/apex/codestyle.xml/ForLoopsMustUseBraces">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/codestyle.xml/FormalParameterNamingConventions">
        <priority>3</priority>
    </rule>
    <rule ref="category/apex/codestyle.xml/IfElseStmtsMustUseBraces">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/codestyle.xml/IfStmtsMustUseBraces">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/codestyle.xml/LocalVariableNamingConventions">
        <priority>3</priority>
    </rule>
    <rule ref="category/apex/codestyle.xml/MethodNamingConventions">
        <priority>2</priority>
        <properties>
            <property name="skipTestMethodUnderscores" value="true" />
        </properties>
    </rule>
    <rule ref="category/apex/codestyle.xml/OneDeclarationPerLine">
        <priority>4</priority>
        <properties>
            <property name="strictMode" value="true" />
        </properties>
    </rule>
    <rule ref="category/apex/codestyle.xml/PropertyNamingConventions">
        <priority>3</priority>
    </rule>
    <rule ref="category/apex/codestyle.xml/WhileLoopsMustUseBraces">
        <priority>1</priority>
    </rule>

    <!-- design -->
    <rule ref="category/apex/design.xml/AvoidDeeplyNestedIfStmts">
        <priority>3</priority>
    </rule>
    <rule ref="category/apex/design.xml/CognitiveComplexity">
      <priority>4</priority>
      <properties>
        <property name="classReportLevel" value="50" />
        <property name="methodReportLevel" value="15" />
      </properties>
    </rule>
   <rule ref="category/apex/design.xml/CyclomaticComplexity">
        <priority>3</priority>
        <properties>
            <property name="classReportLevel" value="40" />
            <property name="methodReportLevel" value="10" />
        </properties>
    </rule>
    <rule ref="category/apex/design.xml/ExcessiveClassLength">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/design.xml/ExcessiveParameterList">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/design.xml/ExcessivePublicCount">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/design.xml/NcssConstructorCount">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/design.xml/NcssMethodCount">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/design.xml/NcssTypeCount">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/design.xml/StdCyclomaticComplexity">
        <priority>3</priority>
        <properties>
            <property name="reportLevel" value="10" />
            <property name="showClassesComplexity" value="true" />
            <property name="showMethodsComplexity" value="true" />
        </properties>
    </rule>
    <rule ref="category/apex/design.xml/TooManyFields">
        <priority>4</priority>
    </rule>

    <!-- documentation -->
    <rule ref="category/apex/documentation.xml/ApexDoc">
        <priority>5</priority>
        <properties>
          <property name="reportProtected" value="true" />
          <property name="reportPrivate" value="false" />
        </properties>
    </rule>

    <!-- error prone -->
    <rule ref="category/apex/errorprone.xml/ApexCSRF">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/AvoidDirectAccessTriggerMap">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/AvoidHardcodingId">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/AvoidNonExistentAnnotations">
        <priority>5</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/EmptyCatchBlock">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/EmptyIfStmt">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/EmptyStatementBlock">
        <priority>4</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/EmptyTryOrFinallyBlock">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/EmptyWhileStmt">
      <priority>1</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/InaccessibleAuraEnabledGetter">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/MethodWithSameNameAsEnclosingClass">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/OverrideBothEqualsAndHashcode">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/errorprone.xml/TestMethodsMustBeInTestClasses">
        <priority>3</priority>
    </rule>

    <!-- Performance -->
    <rule ref="category/apex/performance.xml/AvoidDebugStatements">
        <priority>2</priority>
    </rule>>
    <rule ref="category/apex/performance.xml/OperationWithLimitsInLoop">
        <priority>2</priority>
    </rule>

    <!-- security -->
    <rule ref="category/apex/security.xml/ApexBadCrypto">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/security.xml/ApexCRUDViolation">
        <priority>5</priority>
    </rule>
    <rule ref="category/apex/security.xml/ApexDangerousMethods">
        <priority>3</priority>
    </rule>
    <rule ref="category/apex/security.xml/ApexInsecureEndpoint">
        <priority>3</priority>
    </rule>
    <rule ref="category/apex/security.xml/ApexOpenRedirect">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/security.xml/ApexSharingViolations">
        <priority>3</priority>
    </rule>
    <rule ref="category/apex/security.xml/ApexSOQLInjection">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/security.xml/ApexSuggestUsingNamedCred">
        <priority>2</priority>
    </rule>
    <rule ref="category/apex/security.xml/ApexXSSFromEscapeFalse">
        <priority>1</priority>
    </rule>
    <rule ref="category/apex/security.xml/ApexXSSFromURLParam">
        <priority>1</priority>
    </rule>

    <!-- Visualforce -->
    <rule ref="category/vf/security.xml/VfCsrf">
        <priority>1</priority>
    </rule>
    <rule ref="category/vf/security.xml/VfHtmlStyleTagXss">
        <priority>1</priority>
    </rule>
    <rule ref="category/vf/security.xml/VfUnescapeEl">
        <priority>1</priority>
    </rule>
</ruleset>
