Showing content from https://docs.pmd-code.org/latest/pmd_rules_apex.html below:
Apex Rules | PMD Source Code Analyzer
Index of all built-in rules available for Apex
Table of Contents Best Practices
Rules which enforce generally accepted best practices.
Code Style
Rules which enforce a specific coding style.
Design
Rules that help you discover design issues.
- AvoidBooleanMethodParameters: Boolean parameters in a systemâs API can make method calls difficult to understand and â¦
- AvoidDeeplyNestedIfStmts: Avoid creating deeply nested if-then statements since they are harder to read and error-prone to â¦
- CognitiveComplexity: Methods that are highly complex are difficult to read and more costly to maintain. If you includeâ¦
- CyclomaticComplexity: The complexity of methods directly affects maintenance costs and readability. Concentrating too mâ¦
- ExcessiveClassLength: Excessive class file lengths are usually indications that the class may be burdened with excessivâ¦
- ExcessiveParameterList: Methods with numerous parameters are a challenge to maintain, especially if most of them share thâ¦
- ExcessivePublicCount: Classes with large numbers of public methods, attributes, and properties require disproportionateâ¦
- NcssConstructorCount: This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of lâ¦
- NcssMethodCount: This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of lâ¦
- NcssTypeCount: This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of lâ¦
- StdCyclomaticComplexity: Complexity directly affects maintenance costs is determined by the number of decision points in aâ¦
- TooManyFields: Classes that have too many fields can become unwieldy and could be redesigned to have fewer fieldâ¦
- UnusedMethod: Avoid having unused methods since they make understanding and maintaining code harder. This rule â¦
Documentation
Rules that are related to code documentation.
- ApexDoc: This rule validates that: ApexDoc comments are present for classes, methods, and properties thâ¦
Error Prone
Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
- ApexCSRF: Having DML operations in Apex class constructor or initializers can have unexpected side effects:â¦
- AvoidDirectAccessTriggerMap: Avoid directly accessing Trigger.old and Trigger.new as it can lead to a bug. Triggers should be â¦
- AvoidHardcodingId: When deploying Apex code between sandbox and production environments, or installing Force.com Appâ¦
- AvoidNonExistentAnnotations: Apex supported non existent annotations for legacy reasons. In the future, use of such non-â¦
- AvoidStatefulDatabaseResult: Using instance variables of the following types (or collections of these types) within a statefulâ¦
- EmptyCatchBlock: Empty Catch Block finds instances where an exception is caught, but nothing is done. In mosâ¦
- EmptyIfStmt: Empty If Statement finds instances where a condition is checked but nothing is done about it.
- EmptyStatementBlock: Empty block statements serve no purpose and should be removed.
- EmptyTryOrFinallyBlock: Avoid empty try or finally blocks - whatâs the point?
- EmptyWhileStmt: Empty While Statement finds all instances where a while statement does nothing. If it is a â¦
- InaccessibleAuraEnabledGetter: In the Summer â21 release, a mandatory security update enforces access modifiers on Apex propertiâ¦
- MethodWithSameNameAsEnclosingClass: Non-constructor methods should not have the same name as the enclosing class.
- OverrideBothEqualsAndHashcode: Override both âpublic Boolean equals(Object obj)â, and âpublic Integer hashCode()â, or override nâ¦
- TestMethodsMustBeInTestClasses: Test methods marked as a testMethod or annotated with @IsTest, but not residing in a test câ¦
- TypeShadowsBuiltInNamespace: This rule finds Apex classes, enums, and interfaces that have the same name as a class, enum, or â¦
Performance
Rules that flag suboptimal code.
Security
Rules that flag potential security flaws.
- ApexBadCrypto: The rule makes sure you are using randomly generated IVs and keys for âCryptoâ calls. Hard-wiringâ¦
- ApexCRUDViolation: The rule validates you are checking for access permissions before a SOQL/SOSL/DML operation. Sincâ¦
- ApexDangerousMethods: Checks against calling dangerous methods. For the time being, it reports: Against âFinancialForcâ¦
- ApexInsecureEndpoint: Checks against accessing endpoints under plain http. You should always use https for security.
- ApexOpenRedirect: Checks against redirects to user-controlled locations. This prevents attackers from redirecting uâ¦
- ApexSharingViolations: Detect classes declared without explicit sharing mode if DML methods are used. This forces the deâ¦
- ApexSOQLInjection: Detects the usage of untrusted / unescaped variables in DML queries.
- ApexSuggestUsingNamedCred: Detects hardcoded credentials used in requests to an endpoint. You should refrain from hardcodingâ¦
- ApexXSSFromEscapeFalse: Reports on calls to âaddErrorâ with disabled escaping. The message passed to âaddErrorâ will be dâ¦
- ApexXSSFromURLParam: Makes sure that all values obtained from URL parameters are properly escaped / sanitized to avoidâ¦
Additional rulesets
-
quickstart (rulesets/apex/quickstart.xml
):
Quickstart configuration of PMD for Salesforce.com Apex. Includes the rules that are most likely to apply everywhere.
It contains the following rules:
ApexBadCrypto, ApexCRUDViolation, ApexCSRF, ApexDangerousMethods, ApexDoc, ApexInsecureEndpoint, ApexOpenRedirect, ApexSharingViolations, ApexSOQLInjection, ApexSuggestUsingNamedCred, ApexUnitTestClassShouldHaveAsserts, ApexUnitTestClassShouldHaveRunAs, ApexUnitTestShouldNotUseSeeAllDataTrue, ApexXSSFromEscapeFalse, ApexXSSFromURLParam, AvoidDeeplyNestedIfStmts, AvoidDirectAccessTriggerMap, AvoidGlobalModifier, AvoidHardcodingId, AvoidLogicInTrigger, AvoidNonExistentAnnotations, ClassNamingConventions, CyclomaticComplexity, DebugsShouldUseLoggingLevel, EmptyCatchBlock, EmptyIfStmt, EmptyStatementBlock, EmptyTryOrFinallyBlock, EmptyWhileStmt, ExcessiveClassLength, ExcessiveParameterList, ExcessivePublicCount, FieldNamingConventions, ForLoopsMustUseBraces, FormalParameterNamingConventions, IfElseStmtsMustUseBraces, IfStmtsMustUseBraces, LocalVariableNamingConventions, MethodNamingConventions, MethodWithSameNameAsEnclosingClass, NcssConstructorCount, NcssMethodCount, NcssTypeCount, OneDeclarationPerLine, OperationWithHighCostInLoop, OperationWithLimitsInLoop, PropertyNamingConventions, StdCyclomaticComplexity, TooManyFields, WhileLoopsMustUseBraces
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4