-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruleset.xml
More file actions
230 lines (200 loc) · 8.38 KB
/
ruleset.xml
File metadata and controls
230 lines (200 loc) · 8.38 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
<?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>
<!-- IGNORE EXTERNAL LIBS -->
<include-pattern>.*/audicity/main/.*</include-pattern>
<!-- STANDARD RULES -->
<rule ref="category/apex/security.xml">
<priority>1</priority>
</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 -->
<exclude name="DebugsShouldUseLoggingLevel" /> <!-- No need for this -->
</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>
<!-- Improved by AvoidProductionDebugLogs below -->
<exclude name="AvoidDebugStatements" />
</rule>
<rule
name="AvoidDebugStatements"
language="apex"
message="Avoid leaving System.debug() statements in code as they negatively influence performance."
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
<priority>2</priority>
<properties>
<property
name="xpath"><value><![CDATA[
//MethodCallExpression[lower-case(@FullMethodName)='system.debug'][count(*)=2][not(ancestor::UserClass/ModifierNode/Annotation[@Image="IsTest"])]
]]></value></property>
</properties>
</rule>
<rule ref="category/apex/codestyle.xml">
<priority>2</priority>
<!-- Note: Just make a few class naming rules a bit stricter -->
</rule>
<rule ref="category/apex/codestyle.xml/ClassNamingConventions">
<priority>2</priority>
<properties>
<property name="testClassPattern" value="[A-Z][a-zA-Z0-9_]*" />
<property name="abstractClassPattern" value="[A-Z][a-zA-Z0-9]*" />
<property name="classPattern" value="[A-Z][a-zA-Z0-9]*" />
<property name="interfacePattern" value="[A-Z][a-zA-Z0-9]*" />
<property name="enumPattern" value="[A-Z][a-zA-Z0-9]*" />
</properties>
</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.xpath.XPathRule">
<priority>2</priority>
<properties>
<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.xpath.XPathRule">
<priority>3</priority>
<properties>
<property
name="xpath"><value><![CDATA[
//apiVersion/text[number(@Text) != 61.0]
]]></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.xpath.XPathRule">
<priority>2</priority>
<properties>
<property
name="xpath"><value><![CDATA[
//Flow/loops//targetReference/text[@Text=//Flow/(recordCreates|recordDeletes|recordUpdates)/name/text/@Text]
]]></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.xpath.XPathRule">
<priority>2</priority>
<properties>
<property
name="xpath"><value><![CDATA[
//(CustomObject | CustomField)[not(description)]
]]></value></property>
</properties>
</rule>
<!-- Profile and Permission Set Rules -->
<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.xpath.XPathRule">
<priority>1</priority>
<properties>
<property
name="xpath"><value><![CDATA[
//PermissionSet/userPermissions[ name/text[@Text='ModifyAllData' or @Text='ViewAllData'] and enabled/text[@Text='true'] ]
]]> </value>
</property>
</properties>
</rule>
<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.xpath.XPathRule">
<priority>1</priority>
<properties>
<property
name="xpath"><value><![CDATA[
//Profile/userPermissions[ name/text[@Text='ModifyAllData' or @Text='ViewAllData'] and enabled/text[@Text='true'] and pmd:fileName() != 'System Administrator' ]
]]> </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.xpath.XPathRule">
<priority>1</priority>
<properties>
<property
name="xpath"><value><![CDATA[
//Profile/userPermissions[ pmd:fileName() != 'System Administrator' and name/text[@Text='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.xpath.XPathRule">
<priority>1</priority>
<properties>
<property
name="xpath"><value><![CDATA[
//Profile/userPermissions[ pmd:fileName() != 'System Administrator' and enabled/text[@Text='true'] and name/text[@Text='ViewSetup'] ]
]]> </value>
</property>
</properties>
</rule>
</ruleset>