Skip to content

Instantly share code, notes, and snippets.

@rsoesemann
Last active May 26, 2021 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsoesemann/8a612d9b28d9c572dfb203c9769a5809 to your computer and use it in GitHub Desktop.
Save rsoesemann/8a612d9b28d9c572dfb203c9769a5809 to your computer and use it in GitHub Desktop.
PMD ruleset with custom XPath rule "AvoidProductionDebugLogs"
<?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 for PMD/Codacy</description>
<!-- CUSTOM RULES -->
<rule name="AvoidProductionDebugLogs" language="apex" class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
message="Avoid leaving System.debug() statments in code as they negativly influence performance.">
<description>Avoid leaving System.debug() statments in code as they negativly influence performance.</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//MethodCallExpression[@FullMethodName='System.debug'][count(*)=2]
]]></value>
</property>
</properties>
<example><![CDATA[
// this is OK
System.debug(LoggingLevel.ERROR, 'Failure');
// but this is not
System.debug('Debug' + var);
]]></example>
</rule>
</ruleset>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment