Skip to content

Commit 973f535

Browse files
committed
feat: configure Salesforce Code Analyzer with custom PMD rules
Add code-analyzer.yml configuration file to customize PMD rules and engines. Create custom PMD ruleset that relaxes ApexDoc requirements for test data factories by ignoring missing @description while keeping other documentation checks. Update analysis script to use both Recommended rules and the new custom TestDataFactoryDocs ruleset.
1 parent 939cfc9 commit 973f535

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

code-analyzer.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Custom settings for Salesforce Code Analyzer
2+
rules:
3+
pmd:
4+
ApexDoc:
5+
# Remove the Recommended tag so the stock ApexDoc rule isn't pulled in automatically
6+
tags: []
7+
engines:
8+
pmd:
9+
custom_rulesets:
10+
- config/pmd-test-data-factory-overrides.xml
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="TestDataFactoryDocs"
3+
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
6+
<description>
7+
Overrides ApexDoc so missing @description is ignored while keeping the rest of the documentation checks.
8+
</description>
9+
10+
<rule ref="category/apex/documentation.xml/ApexDoc">
11+
<properties>
12+
<property name="reportMissingDescription" value="false"/>
13+
</properties>
14+
</rule>
15+
</ruleset>

generateCodeAnalysis.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ if ! command -v sf >/dev/null 2>&1; then
1010
exit 1
1111
fi
1212

13-
echo "Running Salesforce Code Analyzer with Recommended rules..."
13+
RULE_SELECTORS="Recommended,pmd:TestDataFactoryDocs"
14+
15+
echo "Running Salesforce Code Analyzer with rule selectors: $RULE_SELECTORS"
1416
sf code-analyzer run \
1517
--workspace "$ROOT_DIR" \
1618
--target "$ROOT_DIR/force-app" \
17-
--rule-selector Recommended \
19+
--rule-selector "$RULE_SELECTORS" \
1820
--output-file "$OUTPUT_JSON" \
1921
--output-file "$OUTPUT_HTML" \
2022
--view table

0 commit comments

Comments
 (0)