-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathruleset.xml
217 lines (185 loc) · 9.18 KB
/
ruleset.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?xml version="1.0"?>
<ruleset name="Opinionated PMD Ruleset" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Opinionated PMD Ruleset</description>
<!-- STANDARD RULES -->
<rule ref="category/apex/security.xml">
<priority>1</priority>
<!-- All are good and not controversial -->
</rule>
<rule ref="category/apex/bestpractices.xml">
<priority>2</priority>
<exclude name="ApexUnitTestClassShouldHaveRunAs" /> <!-- No smart person does that -->
<exclude name="ApexAssertionsShouldIncludeMessage" /> <!-- Better have a focused well named method -->
<exclude name="ApexUnitTestClassShouldHaveAsserts" /> <!-- Configured below -->
</rule>
<rule ref="category/apex/bestpractices.xml/ApexUnitTestClassShouldHaveAsserts" message="Apex unit test classes should have at least one System.assert() or assertEquals() or AssertNotEquals() call">
<priority>3</priority>
<properties>
<property name="additionalAssertMethodPattern" value="((System\.Assert|Assert|Asserts)\.\w+|verify\w+)"/>
</properties>
</rule>
<rule ref="category/apex/design.xml">
<priority>2</priority>
<!-- Note: Cognitive Complexity covers all of that better -->
<exclude name="AvoidDeeplyNestedIfStmts" />
<exclude name="StdCyclomaticComplexity" />
<exclude name="CyclomaticComplexity" />
<exclude name="ExcessiveClassLength" />
<exclude name="ExcessiveParameterList" />
<exclude name="ExcessivePublicCount" />
<exclude name="TooManyFields" />
<exclude name="NcssConstructorCount" />
<exclude name="NcssMethodCount" />
<exclude name="NcssTypeCount" />
</rule>
<rule ref="category/apex/performance.xml">
<priority>2</priority>
<!-- Note: All below should be covered by OperationWithLimitsInLoop -->
<exclude name="AvoidDmlStatementsInLoops" />
<exclude name="AvoidSoqlInLoops" />
<exclude name="AvoidSoslInLoops" />
<!-- Improved by AvoidProductionDebugLogs below -->
<exclude name="AvoidDebugStatements" />
</rule>
<rule name="AvoidProductionDebugLogs" language="apex" message="Avoid leaving System.debug() statments in code as they negativly influence performance." class="net.sourceforge.pmd.lang.rule.XPathRule">
<priority>2</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//MethodCallExpression[lower-case(@FullMethodName)='system.debug'][count(*)=2]
]]></value>
</property>
</properties>
</rule>
<rule ref="category/apex/codestyle.xml">
<priority>2</priority>
<!-- Note: All are super crucial for readable, maintainable code -->
</rule>
<rule ref="category/apex/errorprone.xml">
<priority>2</priority>
<!-- Note: Stupid category but I think everything in there is valid and a 2 -->
</rule>
<!-- CUSTOM RULES -->
<!-- Apex Rules -->
<rule name="NullValueCheckBeforeEmptyCheck" language="apex" message="Apex code must check != null before .isEmpty()" class="net.sourceforge.pmd.lang.rule.XPathRule">
<priority>2</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//BooleanExpression[@Op="&&"][
child::*[2][
self::BooleanExpression[@Op="!="][
child::*[1][self::VariableExpression] and
child::*[2][self::LiteralExpression[@LiteralType="NULL"]]
]
]
]
]]></value>
</property>
</properties>
</rule>
<!-- Metadata XML Rules -->
<rule name="BumpApiVersion" language="xml" message="Metadata should use the latest API version." class="net.sourceforge.pmd.lang.rule.XPathRule">
<priority>3</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//apiVersion/text[number(@Image) < 50]
]]></value>
</property>
</properties>
</rule>
<!-- Flow Rules -->
<rule name="DMLStatementInFlowLoop" language="xml" message="DML Operations shouldn't be done inside of Flow loops" class="net.sourceforge.pmd.lang.rule.XPathRule">
<priority>2</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//Flow/loops//targetReference/text[@Image=//Flow/(recordCreates|recordDeletes|recordUpdates)/name/text/@Image]
]]></value>
</property>
</properties>
</rule>
<!-- Custom Objects / Fields Rules -->
<rule name="MetadataRequiresDescription" language="xml" message="Add a description to explain custom metadata" class="net.sourceforge.pmd.lang.rule.XPathRule">
<priority>2</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//*[self::CustomObject or self::CustomField][not(description)]
]]></value>
</property>
</properties>
</rule>
<!-- Profile and Permission Set Rules -->
<rule name="ModifyOrViewAllOnSysAdminProfile" language="xml" message="Only Admins can view and modify all data, if any other profile get these permissions, they could manipulate records that shouldn't" class="net.sourceforge.pmd.lang.rule.XPathRule">
<priority>1</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//Profile/userPermissions[ name/text[@Image='ModifyAllData' or @Image='ViewAllData'] and enabled/text[@Image='true'] and pmd:fileName() != 'System Administrator' ]
]]> </value>
</property>
</properties>
</rule>
<rule name="ModifyOrViewAllOnPermSet" language="xml" message="Allowing this user permission can give access and ability to modify sensitive data." class="net.sourceforge.pmd.lang.rule.XPathRule">
<priority>1</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//PermissionSet/userPermissions[ name/text[@Image='ModifyAllData' or @Image='ViewAllData'] and enabled/text[@Image='true'] ]
]]> </value>
</property>
</properties>
</rule>
<rule name="ManageUsersByNonSysAdmins" language="xml" message="Managing users need to be limited to System Administrator Profile only." class="net.sourceforge.pmd.lang.rule.XPathRule">
<priority>1</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//Profile/userPermissions[ pmd:fileName() != 'System Administrator' and name/text[@Image='ManageUsers'] ]
]]> </value>
</property>
</properties>
</rule>
<rule name="ViewSetupByNonSysAdmins" language="xml" message="Exposing the setup menu to non-authorized users." class="net.sourceforge.pmd.lang.rule.XPathRule">
<priority>1</priority>
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//Profile/userPermissions[ pmd:fileName() != 'System Administrator' and enabled/text[@Image='true'] and name/text[@Image='ViewSetup'] ]
]]> </value>
</property>
</properties>
</rule>
<!-- Org Setting Rules -->
<rule name="TooLongSessionTimeout" language="xml" message="Allowing access to an inactive session for more than 12 hours is a security risk." class="net.sourceforge.pmd.lang.rule.XPathRule">
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//SecuritySettings/sessionTimeout[ text[@Image='24 hours of inactivity'] or text[@Image='12 hours of inactivity'] ]
]]> </value>
</property>
</properties>
</rule>
<rule name="PasswordsNeverExpire" language="xml" message="Passwords need to expire every 90 days for security." class="net.sourceforge.pmd.lang.rule.XPathRule">
<properties>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//SecuritySettings/passwordPolicies/expiration[ text[@Image=('Never', 'SixMonths', 'OneYear')] ]
]]> </value>
</property>
</properties>
</rule>
</ruleset>