코딩 표준

기본적으로 적용되는 PMD 규칙에 대해서 설명을 합니다.

PMD 규칙에 대한 전체 내용을 [여기]를 참고하시기 바랍니다.

to be updated

PMD

Scanning Your Code Now that PMD is installed and configured, running a scan will be simple. By default, a file will be scanned when you open or save it. In addition, there are a couple of ways to manually scan:

In the Command Palette (View | Command Palette), choose "Apex Static Analysis: On File" or "Apex Static Analysis: On Workspace" Checking the results No alt text provided for this image PMD posts its results to the Problems panel (View | Problems). Click a row to navigate directly to the line with the problem. Stay tuned for a later post where we'll talk about the meanings of various warnings and how to resolve or silence them.

pmd

That's it for now. Stay safe and happy coding!

<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    name="Default ruleset used by the CodeClimate Engine for Salesforce.com Apex"
    xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">

    <description>Default ruleset used for Samsung DS MEM Project</description>
    <exclude-pattern>.*/.sfdx/.*</exclude-pattern>
    <!-- Rule Set based on discussion 2022-01-10 -->
    <!-- Best Practices start -->
    <rule ref="category/apex/bestpractices.xml/ApexUnitTestClassShouldHaveAsserts" 
        message="Apex unit tests should System.assert() or assertEquals() or assertNotEquals()">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/bestpractices.xml/ApexUnitTestShouldNotUseSeeAllDataTrue" 
        message="Apex unit tests should not use @isTest(seeAllData = true)">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/bestpractices.xml/AvoidGlobalModifier" 
        message="Avoid using global modifier">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/bestpractices.xml/AvoidLogicInTrigger" 
        message="Avoid logic in triggers">
        <priority>1</priority>
        <properties>
        </properties>
    </rule>
    <!-- Best Practices end -->
    <!-- Code Style start -->
    <rule ref="category/apex/codestyle.xml/ClassNamingConventions" 
        message="Class names should begin with an uppercase character">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/codestyle.xml/ForLoopsMustUseBraces" 
        message="Avoid using 'for' statements without curly braces">
        <priority>4</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/codestyle.xml/IfElseStmtsMustUseBraces" 
        message="Avoid using 'if...else' statements without curly braces">
        <priority>4</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/codestyle.xml/IfStmtsMustUseBraces" 
        message="Avoid using if statements without curly braces">
        <priority>4</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/codestyle.xml/MethodNamingConventions" 
        message="Method name does not begin with a lower case character.">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/codestyle.xml/OneDeclarationPerLine" 
        message="Use one statement for each line, it enhances code readability.">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/codestyle.xml/VariableNamingConventions" 
        message="{0} variable {1} should begin with {2}">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/codestyle.xml/WhileLoopsMustUseBraces" 
        message="Avoid using 'while' statements without curly braces">
        <priority>4</priority>
        <properties>
        </properties>
    </rule>
    <!-- Code Style end -->
    <!-- Design start -->
    <rule ref="category/apex/design.xml/AvoidDeeplyNestedIfStmts" 
        message="Deeply nested if..then statements are hard to read">
        <priority>2</priority>
        <properties>
            <property name="problemDepth" value="7" />
        </properties>
    </rule>
    <!--rule ref="category/apex/design.xml/CyclomaticComplexity" 
        message="The {0} ''{1}'' has a{2} cyclomatic complexity of {3}.">
        <priority>3</priority>
        <properties>
            <property name="classReportLevel" value="40" />
            <property name="methodReportLevel" value="10" />
        </properties>
    </rule-->
    <rule ref="category/apex/design.xml/ExcessiveClassLength" 
        message="Avoid really long classes.">
        <priority>3</priority>
        <properties>
            <property name="minimum" value="1000" />
        </properties>
    </rule>
    <rule ref="category/apex/design.xml/ExcessiveParameterList" 
        message="Avoid long parameter lists.">
        <priority>3</priority>
        <properties>
            <property name="minimum" value="4" />
        </properties>
    </rule>
    <rule ref="category/apex/design.xml/ExcessivePublicCount" 
        message="This class has a bunch of public methods and attributes">
        <priority>3</priority>
        <properties>
            <property name="minimum" value="25" />
        </properties>
    </rule>
    <rule ref="category/apex/design.xml/NcssConstructorCount" 
        message="The constructor has an NCSS line count of {0}">
        <priority>3</priority>
        <properties>
            <property name="minimum" value="20" />
        </properties>
    </rule>
    <rule ref="category/apex/design.xml/NcssMethodCount" 
        message="The method ''{0}()'' has an NCSS line count of {1}">
        <priority>3</priority>
        <properties>
            <property name="minimum" value="60" />
        </properties>
    </rule>
    <rule ref="category/apex/design.xml/NcssTypeCount" 
        message="The type has an NCSS line count of {0}">
        <priority>3</priority>
        <properties>
            <property name="minimum" value="700" />
        </properties>
    </rule>
    <!--rule ref="category/apex/design.xml/StdCyclomaticComplexity" 
        message="The {0} ''{1}'' has a Standard Cyclomatic Complexity of {2}.">
        <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" 
        message="Too many fields">
        <priority>3</priority>
        <properties>
            <property name="maxfields" value="20" />
        </properties>
    </rule>
    <!-- Design end -->
    <!-- Documentation start -->
    <!--rule ref="category/apex/document.xml/ApexDoc" 
        message="ApexDoc comment is missing or incorrect">
        <priority>3</priority>
        <properties>
        </properties>
    </rule-->
    <!-- Documentation end -->
    <!-- Error Prone start -->
    <rule ref="category/apex/errorprone.xml/AvoidDirectAccessTriggerMap" 
        message="Avoid directly accessing Trigger.old and Trigger.new">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/errorprone.xml/AvoidHardcodingId" 
        message="Hardcoding Id's is bound to break when changing environments.">
        <priority>1</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/errorprone.xml/AvoidNonExistentAnnotations" 
        message="Use of non existent annotations will lead to broken Apex code which will not compile in the future.">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/errorprone.xml/EmptyCatchBlock" 
        message="Avoid empty catch blocks">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/errorprone.xml/EmptyIfStmt" 
        message="Avoid empty 'if' statements">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/errorprone.xml/EmptyStatementBlock" 
        message="Avoid empty block statements.">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/errorprone.xml/EmptyTryOrFinallyBlock" 
        message="Avoid empty try or finally blocks">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/errorprone.xml/EmptyWhileStmt" 
        message="Avoid empty 'while' statements">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/errorprone.xml/MethodWithSameNameAsEnclosingClass" 
        message="Classes should not have non-constructor methods with the same name as the class">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <!-- Error Prone end -->
    <!-- Performance start -->
    <rule ref="category/apex/performance.xml/AvoidDmlStatementsInLoops" 
        message="Avoid DML statements inside loops">
        <priority>1</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/performance.xml/AvoidSoqlInLoops" 
        message="Avoid Soql queries inside loops">
        <priority>1</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/performance.xml/AvoidSoslInLoops" 
        message="Avoid Sosl queries inside loops">
        <priority>1</priority>
        <properties>
        </properties>
    </rule>
    <!-- Performance end -->
    <!-- Security start -->
    <rule ref="category/apex/security.xml/ApexBadCrypto" 
        message="Apex classes should use random IV/key">
        <priority>1</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/security.xml/ApexCRUDViolation" 
        message="Validate CRUD permission before SOQL/DML operation">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/security.xml/ApexCSRF" 
        message="Avoid making DML operations in Apex class constructor/init method">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/security.xml/ApexDangerousMethods" 
        message="Calling potentially dangerous method">
        <priority>3</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/security.xml/ApexInsecureEndpoint" 
        message="Apex callouts should use encrypted communication channels">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/security.xml/ApexOpenRedirect" 
        message="Apex classes should safely redirect to a known location">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/security.xml/ApexSharingViolations" 
        message="Apex classes should declare a sharing model if DML or SOQL/SOSL is used">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/security.xml/ApexSOQLInjection" 
        message="Avoid untrusted/unescaped variables in DML query">
        <priority>1</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/security.xml/ApexSuggestUsingNamedCred" 
        message="Suggest named credentials for authentication">
        <priority>2</priority>
        <properties>
        </properties>
   </rule>
    <rule ref="category/apex/security.xml/ApexXSSFromEscapeFalse" 
        message="Apex classes should escape Strings in error messages">
        <priority>1</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/apex/security.xml/ApexXSSFromURLParam" 
        message="Apex classes should escape/sanitize Strings obtained from URL parameters">
        <priority>1</priority>
        <properties>
        </properties>
    </rule>
    <!-- Security end -->
    <!-- Visualfoce Start -->
    <rule ref="category/vf/security.xml/VfCsrf" 
        message="Avoid calling VF action upon page load">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <rule ref="category/vf/security.xml/VfUnescapeEl" 
        message="Avoid unescaped user controlled content in EL">
        <priority>2</priority>
        <properties>
        </properties>
    </rule>
    <!-- Visualfoce End -->
    <!-- Lightning Start -->
    <!--rule ref="category/ecmascript/bestpractices.xml/AvoidWithStatement" 
        message="Avoid using with - it's bad news">
        <priority>1</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/bestpractices.xml/ConsistentReturn" 
        message="A function should not mix 'return' statements with and without a result.">
        <priority>2</priority>
        <properties>
            <property name="rhinoLanguageVersion" value="ES6" />
            <property name="recordingLocalJsDocComments" value="true" />
            <property name="recordingComments" value="true" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/bestpractices.xml/GlobalVariable" 
        message="Avoid using global variables">
        <priority>1</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/bestpractices.xml/ScopeForInVariable" 
        message="The for-in loop variable ''{0}'' should be explicitly scoped with 'var' to avoid pollution.">
        <priority>1</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/bestpractices.xml/UseBaseWithParseInt" 
        message="Always provide a base when using parseInt() functions">
        <priority>1</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/codestyle.xml/AssignmentInOperand" 
        message="Avoid assignments in operands">
        <priority>2</priority>
        <properties>
            <property name="version" value="2.0" />
            <property name="allowIf" type="Boolean" value="false" description="Allow assignment within the conditional expression of an if statement" />
            <property name="allowFor" type="Boolean" value="false" description="Allow assignment within the conditional expression of a for statement" />
            <property name="allowWhile" type="Boolean" value="false" description="Allow assignment within the conditional expression of a while statement" />
            <property name="allowTernary" type="Boolean" value="false" description="Allow assignment within the conditional expression of a ternary operator" />
            <property name="allowTernaryResults" type="Boolean" value="false" description="Allow assignment within the result expressions of a ternary operator" />
            <property name="allowIncrementDecrement" type="Boolean" value="false" description="Allow increment or decrement operators within the conditional expression of an if, for, or while statement" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/codestyle.xml/ForLoopsMustUseBraces" 
        message="Avoid using 'for' statements without curly braces">
        <priority>3</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/codestyle.xml/IfElseStmtsMustUseBraces" 
        message="Avoid using 'if...else' statements without curly braces">
        <priority>3</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/codestyle.xml/IfStmtsMustUseBraces" 
        message="Avoid using if statements without curly braces">
        <priority>3</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/codestyle.xml/NoElseReturn" 
        message="The else block is unnecessary">
        <priority>3</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/codestyle.xml/UnnecessaryBlock" 
        message="Unnecessary block.">
        <priority>3</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/codestyle.xml/UnnecessaryParentheses" 
        message="Unnecessary parentheses.">
        <priority>4</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/codestyle.xml/UnreachableCode" 
        message="A ''return'', ''break'', ''continue'', or ''throw'' statement should be the last in a block.">
        <priority>1</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/codestyle.xml/WhileLoopsMustUseBraces" 
        message="Avoid using 'while' statements without curly braces">
        <priority>3</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/errorprone.xml/AvoidTrailingComma" 
        message="Avoid trailing commas in object or array literals">
        <priority>1</priority>
        <properties>
            <property name="version" value="2.0" />
            <property name="allowObjectLiteral" type="Boolean" value="false" description="Allow a trailing comma within an object literal" />
            <property name="allowArrayLiteral" type="Boolean" value="false" description="Allow a trailing comma within an array literal" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/errorprone.xml/EqualComparison" 
        message="Use '==='/'!==' to compare with true/false or Numbers">
        <priority>3</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule>
    <rule ref="category/ecmascript/errorprone.xml/InnaccurateNumericLiteral" 
        message="The numeric literal ''{0}'' will have at different value at runtime.">
        <priority>3</priority>
        <properties>
            <property name="version" value="2.0" />
        </properties>
    </rule-->
    <!-- Lightning End -->
</ruleset>