forked from yegor256/qulice
/
ruleset.xml
259 lines (255 loc) · 10.9 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?xml version="1.0"?>
<!--
Copyright (c) 2011-2024 Qulice.com
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met: 1) Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer. 2) Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution. 3) Neither the name of the Qulice.com nor
the names of its contributors may be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Qulice Ruleset" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
This ruleset checks code for potential mess
</description>
<rule ref="category/java/bestpractices.xml">
<exclude name="JUnitTestsShouldIncludeAssert"/>
<exclude name="GuardLogStatement"/>
<exclude name="PositionLiteralsFirstInComparisons"/>
<exclude name="PositionLiteralsFirstInCaseInsensitiveComparisons"/>
</rule>
<rule ref="category/java/codestyle.xml">
<exclude name="AtLeastOneConstructor"/>
<exclude name="AvoidFinalLocalVariable"/>
<exclude name="ShortClassName"/>
<exclude name="ShortVariable"/>
<exclude name="AbstractNaming"/>
<exclude name="ClassNamingConventions"/>
<exclude name="CommentDefaultAccessModifier"/>
<exclude name="DefaultPackage"/>
<exclude name="LinguisticNaming"/>
<exclude name="CallSuperInConstructor"/>
</rule>
<rule ref="category/java/design.xml">
<exclude name="LoosePackageCoupling"/>
<exclude name="LawOfDemeter"/>
<exclude name="SignatureDeclareThrowsException"/>
<exclude name="ExcessiveImports"/>
<exclude name="CyclomaticComplexity"/>
</rule>
<rule ref="category/java/documentation.xml">
<exclude name="CommentRequired"/>
<exclude name="CommentSize"/>
</rule>
<rule ref="category/java/errorprone.xml">
<exclude name="DataflowAnomalyAnalysis"/>
<exclude name="AvoidLiteralsInIfCondition"/>
<exclude name="NonSerializableClass"/>
<exclude name="MissingSerialVersionUID"/>
</rule>
<rule ref="category/java/performance.xml">
<exclude name="AvoidInstantiatingObjectsInLoops"/>
</rule>
<rule ref="category/java/multithreading.xml">
<exclude name="AvoidUsingVolatile"/>
<exclude name="UseConcurrentHashMap"/>
<exclude name="DoNotUseThreads"/>
</rule>
<rule ref="category/java/errorprone.xml/AvoidDuplicateLiterals">
<properties>
<property name="maxDuplicateLiterals">
<value>5</value>
</property>
<property name="skipAnnotations">
<value>true</value>
</property>
</properties>
</rule>
<rule name="ProhibitPlainJunitAssertionsRule" message="Avoid using Plain JUnit assertions" class="com.qulice.pmd.rules.ProhibitPlainJunitAssertionsRule">
<description>
Instead of using plain JUnit assertions like org.junit.Assert.assert*
junit.framework.Assert.assert* - use Matchers from package org.hamcrest
</description>
</rule>
<rule name="UseStringIsEmptyRule" message="Use String.isEmpty() when checking for empty string" class="com.qulice.pmd.rules.UseStringIsEmptyRule">
<description>
Method String.isEmpty() should be used when testing for empty string, rather than using
String.length() compared to 0
</description>
</rule>
<rule name="UnnecessaryLocalRule" message="Avoid creating unnecessary local variables like ''{0}''" class="com.qulice.pmd.rules.UnnecessaryLocalRule">
</rule>
<rule name="ConstructorShouldDoInitialization" message="Avoid doing field initialization outside constructor." language="java" class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>
Avoid doing field initialization outside class constructor.
Such initialization is allowed only when there is no constructor.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//ClassOrInterfaceBody
[count(ClassOrInterfaceBodyDeclaration/ConstructorDeclaration)>0]
[count(ClassOrInterfaceBodyDeclaration/FieldDeclaration[@Static='false']/VariableDeclarator/VariableInitializer)>0]
]]></value>
</property>
</properties>
</rule>
<rule name="OnlyOneConstructorShouldDoInitialization" message="Avoid field initialization in several constructors." language="java" class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>
Avoid doing field initialization in several constructors.
Only one main constructor should do real work.
Other constructors should delegate initialization to it.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//ClassOrInterfaceBody[count(ClassOrInterfaceBodyDeclaration/ConstructorDeclaration)>1]
[count(ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[BlockStatement])>1]
]]></value>
</property>
</properties>
</rule>
<rule name="ConstructorOnlyInitializesOrCallOtherConstructors" message="Only field initialization or call to other constructors in a constructor." language="java" class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>
Avoid putting anything other than field assignments into constructors.
The only exception should be calling other constructors
or calling super class constructor.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//ConstructorDeclaration/BlockStatement[count(Statement/StatementExpression/PrimaryExpression[count(following-sibling::AssignmentOperator[1])>0]/PrimaryPrefix[@ThisModifier="true"])!=count(*)]
]]></value>
</property>
</properties>
</rule>
<rule name="AvoidDirectAccessToStaticFields" message="Static fields should be accessed in a static way [CLASS_NAME.FIELD_NAME]." language="java" class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>
Avoid accessing static fields directly.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//Name[@Image = //FieldDeclaration[@Static='true']/@VariableName]
]]></value>
</property>
</properties>
<example>
<![CDATA[
public final class DirectAccessToStaticFields {
private static int num = 1;
public static int number() {
return num;
}
}
]]>
</example>
</rule>
<rule name="AvoidAccessToStaticMembersViaThis" message="Static members should be accessed in a static way [CLASS_NAME.FIELD_NAME], not via instance reference." language="java" class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>
Avoid accessing static fields or methods via instance with 'this' keyword.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//PrimaryExpression[
(./PrimaryPrefix[@ThisModifier='true']) and
(./PrimarySuffix[
@Image=//FieldDeclaration[@Static='true']/@VariableName
or @Image=//MethodDeclaration[@Static='true']/@MethodName
])
]
]]></value>
</property>
</properties>
</rule>
<rule name="ProhibitPublicStaticMethods" message="Public static methods are prohibited." language="java" class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>
Public static methods are prohibited.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//ClassOrInterfaceBodyDeclaration[
MethodDeclaration[@Static='true' and @Public='true'
and not (
MethodDeclarator[
count(FormalParameters/FormalParameter)=1
and FormalParameters/FormalParameter[1]/Type/ReferenceType/ClassOrInterfaceType[@Image='String']
and FormalParameters/FormalParameter[@Varargs='true']
] and not(ResultType/Type) and @Name='main'
)
] and (
Annotation/MarkerAnnotation/Name[@Image!='BeforeClass' and @Image!='AfterClass'
and @Image!='Parameterized.Parameters']
or not (Annotation)
)
]
]]></value>
</property>
</properties>
</rule>
<rule name="ProhibitFilesCreateFileInTests" message="Files.createFile should not be used in tests, replace them with @Rule TemporaryFolder" language="java" class="net.sourceforge.pmd.lang.rule.XPathRule">
<description>
Files.createFile shouldn't be used in tests.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//ClassOrInterfaceDeclaration[ends-with(@SimpleName, 'Test')]//PrimaryPrefix/Name[@Image='Files.createFile']
]]></value>
</property>
</properties>
</rule>
<rule name="JUnitTestClassShouldBeFinal" language="java" class="net.sourceforge.pmd.lang.rule.XPathRule" message="JUnit test class should be final">
<description><![CDATA[
Reports on JUnit test classes declared non-final.
]]></description>
<priority>3</priority>
<properties>
<property name="version" value="2.0"/>
<!--Solve priority confict-->
<property name="xpath">
<value><![CDATA[
//TypeDeclaration
//ClassOrInterfaceDeclaration[
(: a Junit 3,4 and 5 test class :)
@Interface=false() and
ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration
[Annotation//Name[
pmd-java:typeIs('junit.framework.TestCase')
or pmd-java:typeIs('org.junit.Test')
or pmd-java:typeIs('org.junit.jupiter.api.Test')
]]
]
[@Final = false()]
]]></value>
</property>
</properties>
</rule>
</ruleset>