We are working on the Apex PMD configuration to generate the PMD report for our Salesforce Apex code, Below is the information required, Request to kindly help on providing the same,
1.) As per one of the performance ruleset, we observe the below snippet
<rule name="AvoidDmlStatementsInLoops" since="5.5.0" message="Avoid DML statements inside loops" class="net.sourceforge.pmd.lang.apex.rule.performance.AvoidDmlStatementsInLoopsRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_performance.html#avoidsoqlinloops">
Can we download the Java Files (located at net.sourceforge.pmd.lang.apex.rule.performance.AvoidDmlStatementsInLoopsRule) to our local system and execute the PMD report.
2.) If Yes. request to kindly help us the way forward.
3.) Please let us where is this URL defined in PMD ( externalInfoUrl="${pmd.website.baseurl} )
4.) How to create a new rule and configure.
Thanks,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here are some answers:
1) PMD is packaged as a binary distribution, which you can download from https://pmd.github.io . This includes all the rules, including your mentioned AvoidDmlStatementsInLoop.
In order to execute it, you'll need to create a custom ruleset, to enable the rules you want. See https://pmd.github.io/pmd-6.5.0/pmd_userdocs_making_rulesets.html
Hi Andreas, Thank you very much for your response,
As we are working on few custom rules for Salesforce Apex classes, Request to let us know if there is any existing Rule related to comments (report PMD violation if comments are not there in a Apex Class).
If there is no such existing, Kindly help us on creating a custom java rule class for scanning the apex class and identify the presence of comments.( I am able to configure a new rule in the ruleset and able to generate the .csv report with my new custom rule.)
Thanks in advance,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can you also please share some details/documentation on writing custom rules with respect to below usecases, which would be really helpful,
1.) Classes that handle Trigger events should always have the suffix “TriggerHandler”.
2.) The class name should be suffixed by Batch
3.)CamelCase Convention
4.)Single Letter Variable within Loops
5.)Avoid @future inside Loops
Thanks in advance,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
your rule ideas sound interesting. Please have a look at the already existing rules for apex at https://pmd.github.io/pmd-6.6.0/pmd_rules_apex_codestyle.html - for 1) 2) 3) 4) there might be already rules available, that you can use or adjust (classnamingconvention, variablenamingconvention).
Hi ,
Good morning,
We are working on the Apex PMD configuration to generate the PMD report for our Salesforce Apex code, Below is the information required, Request to kindly help on providing the same,
1.) As per one of the performance ruleset, we observe the below snippet
<rule name="AvoidDmlStatementsInLoops" since="5.5.0" message="Avoid DML statements inside loops" class="net.sourceforge.pmd.lang.apex.rule.performance.AvoidDmlStatementsInLoopsRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_performance.html#avoidsoqlinloops">
Can we download the Java Files (located at net.sourceforge.pmd.lang.apex.rule.performance.AvoidDmlStatementsInLoopsRule) to our local system and execute the PMD report.
2.) If Yes. request to kindly help us the way forward.
3.) Please let us where is this URL defined in PMD ( externalInfoUrl="${pmd.website.baseurl} )
4.) How to create a new rule and configure.
Thanks,
Hi, you might get more response on github: https://github.com/pmd/pmd/issues or on gitter https://gitter.im/pmd/pmd
Here are some answers:
1) PMD is packaged as a binary distribution, which you can download from https://pmd.github.io . This includes all the rules, including your mentioned AvoidDmlStatementsInLoop.
In order to execute it, you'll need to create a custom ruleset, to enable the rules you want. See https://pmd.github.io/pmd-6.5.0/pmd_userdocs_making_rulesets.html
2) If you want to look at the source, you can got to github: https://github.com/pmd/pmd
3) The external Info Url is set during the release and points to https://pmd.github.io/pmd-<version>/ , e.g. you can see the documentation fo the rule here: https://pmd.github.io/pmd-6.5.0/pmd_rules_apex_performance.html#avoiddmlstatementsinloops
4) https://pmd.github.io/pmd-6.5.0/pmd_userdocs_extending_writing_pmd_rules.html
Regards,
Andreas
Hi Andreas, Thank you very much for your response,
As we are working on few custom rules for Salesforce Apex classes, Request to let us know if there is any existing Rule related to comments (report PMD violation if comments are not there in a Apex Class).
If there is no such existing, Kindly help us on creating a custom java rule class for scanning the apex class and identify the presence of comments.( I am able to configure a new rule in the ruleset and able to generate the .csv report with my new custom rule.)
Thanks in advance,
Hi,
unfortunately analyzing the comments is not possible with apex: See https://github.com/pmd/pmd/issues/1136
Regards,
Andreas
Hi Andreas, Thanks for your share on comments,
Can you also please share some details/documentation on writing custom rules with respect to below usecases, which would be really helpful,
1.) Classes that handle Trigger events should always have the suffix “TriggerHandler”.
2.) The class name should be suffixed by Batch
3.)CamelCase Convention
4.)Single Letter Variable within Loops
5.)Avoid @future inside Loops
Thanks in advance,
Hi,
your rule ideas sound interesting. Please have a look at the already existing rules for apex at https://pmd.github.io/pmd-6.6.0/pmd_rules_apex_codestyle.html - for 1) 2) 3) 4) there might be already rules available, that you can use or adjust (classnamingconvention, variablenamingconvention).
General documentation about writing rules can be found here: https://pmd.github.io/pmd-6.6.0/pmd_userdocs_extending_writing_pmd_rules.html
In any case, if you have questions, you can also reach out to our gitter chat at https://gitter.im/pmd/pmd
Regards,
Andreas