/
pmd.xml
429 lines (421 loc) · 21.8 KB
/
pmd.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<?xml version="1.0"?>
<ruleset name="PMD ruleset for Checkstyle"
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
http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
PMD common ruleset for Checkstyle main/test sourcesets
</description>
<rule ref="category/java/bestpractices.xml">
<!-- We do not care about this minor overhead, we are not Android application and we do not
want to change visibility of methods. Package-private visibility should be avoid almost
always. -->
<exclude name="AccessorMethodGeneration"/>
<!-- The PMD mistakes the AbstractViolationReporter::log() as a debug log. -->
<exclude name="GuardLogStatement"/>
<!-- Till https://github.com/pmd/pmd/issues/1181 -->
<exclude name="UnusedPrivateMethod"/>
</rule>
<rule ref="category/java/bestpractices.xml/AvoidPrintStackTrace">
<properties>
<!-- It is ok to use print stack trace in CLI class. -->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='Main']"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/JUnitAssertionsShouldIncludeMessage">
<properties>
<!-- The PMD check accepts only a string constant as the assert message.
This check uses a method call. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='JavadocCatchCheck']
//MethodDeclaration[@Name='visitJavadocToken']"/>
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/SystemPrintln">
<properties>
<!-- it is ok to use println in CLI class. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration
[@Image='Main' or @Image='Main$CliOptions'
or @Image='JavadocPropertiesGenerator']"/>
</properties>
</rule>
<rule ref="category/java/documentation.xml">
<!-- We use class comments as source for xdoc files,
so content is big and that is by design. -->
<exclude name="CommentSize"/>
</rule>
<rule ref="category/java/documentation.xml/CommentRequired">
<properties>
<!-- *TokenTypes are special class, comments are as trailing comments.
RequireThisCheck$AbstractFrame is a private class, no comment is required.
Main.runCli has a false positive for an anonymous class.
-->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='JavadocTokenTypes']
| //ClassOrInterfaceDeclaration[@Image='RequireThisCheck']
| //ClassOrInterfaceDeclaration[@Image='AbstractFrame']
| //ClassOrInterfaceDeclaration[@Image='Main']//MethodDeclaration[@Name='runCli']"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml">
<!-- Opposite to UnnecessaryConstructor. -->
<exclude name="AtLeastOneConstructor"/>
<!-- Turning a local variable to the field may create design problems and extend the scope of
the variable. -->
<exclude name="AvoidFinalLocalVariable"/>
<!-- Conflicts with names that does not mean in/out. -->
<exclude name="AvoidPrefixingMethodParameters"/>
<!-- Calling super() is completely pointless, no matter if class inherits anything or not;
it is meaningful only if you do not call implicit constructor of the base class. -->
<exclude name="CallSuperInConstructor"/>
<!-- Till https://github.com/checkstyle/checkstyle/issues/5665 -->
<exclude name="CommentDefaultAccessModifier"/>
<!-- Pollutes code with modifiers. -->
<exclude name="LocalVariableCouldBeFinal"/>
<!-- Pollutes the code with modifiers. We use the ParameterAssignmentCheck to protect the
parameters. -->
<exclude name="MethodArgumentCouldBeFinal"/>
<!-- It is possible only in functional languages and fanatically-pristine code, without
additional option that are done at ReturnCountExtendedCheck it is not a good rule. -->
<exclude name="OnlyOneReturn"/>
<!-- We use CheckstyleCustomShortVariable, to control the length and skip Override methods. -->
<exclude name="ShortVariable"/>
</rule>
<rule ref="category/java/codestyle.xml/AbstractNaming">
<properties>
<!-- We can not brake compatibility with previous versions. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration
[@Image='AbstractClassNameCheck' or @Image='AutomaticBean']"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/ClassNamingConventions">
<properties>
<!-- Definitions and XmlLoader.LoadExternalDtdFeatureProvider aren't utility classes.
JavadocTokenTypes and TokenTypes aren't utility classes.
They are token definition classes. Also, they are part of the API. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='Definitions'
or @Image='JavadocTokenTypes' or @Image='TokenTypes'
or @Image='LoadExternalDtdFeatureProvider']"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/ConfusingTernary">
<properties>
<!-- False positives on IF_ELSE-IF-ELSE-IF. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='XMLLogger']
//MethodDeclarator[@Image='isReference']
| //ClassOrInterfaceDeclaration[@Image='DetailAST']
//MethodDeclarator[@Image='addPreviousSibling']
| //ClassOrInterfaceDeclaration[@Image='AnnotationLocationCheck']
//MethodDeclarator[@Image='checkAnnotations']
| //ClassOrInterfaceDeclaration[@Image='AbstractImportControl']
//MethodDeclarator[@Image='checkAccess']
| //ClassOrInterfaceDeclaration[@Image='HandlerFactory']
//MethodDeclarator[@Image='getHandler']"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/EmptyMethodInAbstractClassShouldBeAbstract">
<properties>
<!-- Can not change the API. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='AbstractFileSetCheck'
or @Image='AbstractCheck' or @Image='AbstractJavadocCheck' or @Image='AbstractNode'
or @Image='AbstractViolationReporter']"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/LongVariable">
<properties>
<!-- Nothing bad with the long and descriptive variable names if only they fit the line,
but still keep it reasonable. -->
<property name="minimum" value="45"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/ShortClassName">
<properties>
<!-- Main is a good name for the class containing the main method.
Tag as inner class name is fine. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='Main' or @Image='Tag']"/>
</properties>
</rule>
<rule ref="category/java/errorprone.xml">
<!-- That rule is not practical, no options to allow some magic numbers,
we will use our implementation. -->
<exclude name="AvoidLiteralsInIfCondition"/>
<!-- It is not our goal for now to keep all Serializable, maybe in the future. -->
<exclude name="BeanMembersShouldSerialize"/>
<!-- We need compare by ref as Tree structure is immutable, we can easily
rely on refs. -->
<exclude name="CompareObjectsWithEquals"/>
<!-- Too many false positives. -->
<exclude name="DataflowAnomalyAnalysis"/>
<!-- This rule does not have any option, unreasonable to use. -->
<exclude name="MissingBreakInSwitch"/>
<!-- We reuse Check instances between java files, we need to clear state of
class in beginTree() methods. -->
<exclude name="NullAssignment"/>
<!-- Till https://github.com/checkstyle/checkstyle/issues/5680 -->
<exclude name="UseProperClassLoader"/>
</rule>
<rule ref="category/java/errorprone.xml/AvoidDuplicateLiterals">
<properties>
<!-- Annotations like '@SuppressWarnings' don't need to be checked, it is better to keep their
strings connected to the annotation instead of separating. -->
<property name="skipAnnotations" value="true"/>
</properties>
</rule>
<rule ref="category/java/errorprone.xml/EmptyCatchBlock">
<properties>
<property name="allowCommentedBlocks" value="true"/>
</properties>
</rule>
<rule ref="category/java/errorprone.xml/DoNotCallSystemExit">
<properties>
<!-- There is no alternative to using System.exit in the CLI class
to report the return code. -->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='Main']"/>
</properties>
</rule>
<rule ref="category/java/design.xml">
<!-- Too much false-positives on the check classes.
We do not follow the philosophy of complete encapsulation, we like data classes
(preferable immutable) to transfer content from one part to another.
There is no way to configure the rule (it has no properties). -->
<exclude name="DataClass"/>
<!-- Too much alarms on the check classes, we will never move logic out of the check,
each check is an independent logic container. -->
<exclude name="GodClass"/>
<!-- Too many violations, will be suppressed until we find out how use these metrics. -->
<exclude name="LawOfDemeter"/>
<!-- We use our ImportControl to control imports in packages and classes. -->
<exclude name="LoosePackageCoupling"/>
</rule>
<rule ref="category/java/design.xml/AvoidCatchingGenericException">
<properties>
<!-- Checker: There is no other way to deliver the filename that was under processing.
See https://github.com/checkstyle/checkstyle/issues/2285
TranslationCheck: It is better to catch all exceptions since it can throw
a runtime exception. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='Checker']
//MethodDeclaration[@Name='processFiles']
|//ClassOrInterfaceDeclaration[@Image='TranslationCheck']
//MethodDeclaration[@Name='getTranslationKeys']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/AvoidDeeplyNestedIfStmts">
<properties>
<!-- The default is 3 but we try to use single point of exit from the method and that require
some extra IFs. -->
<property name="problemDepth" value="4"/>
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='ClassResolver']
//MethodDeclarator[@Image='resolve']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/AvoidThrowingRawExceptionTypes">
<properties>
<!-- There is no other way to deliver the filename that was under processing.
See https://github.com/checkstyle/checkstyle/issues/2285 -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='Checker']
//MethodDeclaration[@Name='processFiles']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/CouplingBetweenObjects">
<properties>
<!-- I do not see any problem, looks like a false positive. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='HandlerFactory']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/NcssCount">
<properties>
<property name="methodReportLevel" value="32"/>
<!-- Main, PackageObjectFactory, CheckstyleAntTask, RequireThisCheck, HandlerFactory,
VariableDeclarationUsageDistanceCheck, CommentsIndentationCheck, JavadocMethodCheck,
are big and should not be split without a good reason.
The methods visitToken/leaveToken are a big SWITCH block with a number of IF blocks.
If we split the block to several methods it will damage the readability.
XMLLogger.encode, FallThroughCheck.isTerminated, ElementNode.iterateAxis,
NoWhitespaceAfterCheck.getArrayDeclaratorPreviousElement are also huge switches,
they has to be monolithic. -->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='Main'
or @Image='PackageObjectFactory' or @Image='CheckstyleAntTask' or @Image='RequireThisCheck'
or @Image='VariableDeclarationUsageDistanceCheck' or @Image='CommentsIndentationCheck'
or @Image='JavadocMethodCheck' or @Image='HandlerFactory']
| //ClassOrInterfaceDeclaration[@Image='XMLLogger']//MethodDeclaration[@Name='encode']
| //ClassOrInterfaceDeclaration[@Image='LeftCurlyCheck' or @Image='FinalLocalVariableCheck'
or @Image='ImportOrderCheck' or @Image='NPathComplexityCheck']
//MethodDeclaration[@Name='visitToken']
| //ClassOrInterfaceDeclaration[@Image='FallThroughCheck']
//MethodDeclaration[@Name='isTerminated']
| //ClassOrInterfaceDeclaration[@Image='ModifiedControlVariableCheck'
or @Image='NPathComplexityCheck']//MethodDeclaration[@Name='leaveToken']
| //ClassOrInterfaceDeclaration[@Image='NoWhitespaceAfterCheck']
//MethodDeclaration[@Name='getArrayDeclaratorPreviousElement']
| //ClassOrInterfaceDeclaration[@Image='ElementNode']//MethodDeclaration[@Name='iterateAxis']
"/>
</properties>
</rule>
<rule ref="category/java/design.xml/CyclomaticComplexity">
<properties>
<property name="classReportLevel" value="76"/>
<property name="methodReportLevel" value="11"/>
<!-- RequireThisCheck, VariableDeclarationUsageDistanceCheck, XdocsPagesTest,
JavadocMethodCheck and CommentsIndentationCheck are big classes and should not
be split without a good reason.
Main.validateCli is not reasonable to split as encapsulation of the logic will be
damaged.
*.visitToken are a big SWITCH block with a number of IF blocks.
If we split the block to several methods it will damage the readability.
JavadocStyleCheck is deprecated.
SuppressWarningsHolder.getAcceptableParent, FallThroughCheck.isTerminated,
ElementNode.iterateAxis, RootNode.iterateAxis are also huge switches,
they has to be monolithic.
CustomImportOrderCheck.finishImportList, CustomImportOrderCheck.getImportGroup are
validated by checkstyle version of Npath, we think that pmd is wrong here.
Checker.processFiles is validated by checkstyle version of Npath, we think that pmd is
wrong here.
XdocsJavaDocsTest.testAllCheckSectionJavaDocs is needed until all suppressions are
removed. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='RequireThisCheck'
or @Image='VariableDeclarationUsageDistanceCheck' or @Image='XdocsPagesTest'
or @Image='JavadocMethodCheck' or @Image='CommentsIndentationCheck']
| //ClassOrInterfaceDeclaration[@Image='Main']//MethodDeclaration[@Name='validateCli']
| //ClassOrInterfaceDeclaration[@Image='Checker']//MethodDeclaration[@Name='processFiles']
| //ClassOrInterfaceDeclaration[@Image='FallThroughCheck']
//MethodDeclaration[@Name='isTerminated']
| //ClassOrInterfaceDeclaration[@Image='SuppressWarningsHolder']
//MethodDeclaration[@Name='getAcceptableParent']
| //ClassOrInterfaceDeclaration[@Image='CustomImportOrderCheck']
//MethodDeclaration[@Name='finishImportList' or @Name='getImportGroup']
| //ClassOrInterfaceDeclaration[@Image='JavadocStyleCheck']
//MethodDeclaration[@Name='checkHtmlTags']
| //ClassOrInterfaceDeclaration[@Image='ElementNode' or @Image='RootNode']
//MethodDeclaration[@Name='iterateAxis']
| //ClassOrInterfaceDeclaration[@Image='NPathComplexityCheck'
or @Image='EmptyLineSeparatorCheck' or @Image='LeftCurlyCheck' or @Image='ImportOrderCheck'
or @Image='DeclarationOrderCheck' or @Image='MissingOverrideCheck'
or @Image='FinalLocalVariableCheck' or @Image='ModifiedControlVariableCheck'
or @Image='ParameterAssignmentCheck' or @Image='UnnecessaryParenthesesCheck'
or @Image='AbstractClassCouplingCheck' or @Image='BooleanExpressionComplexityCheck'
or @Image='ParenPadCheck' or @Image='IllegalTypeCheck']//MethodDeclaration[@Name='visitToken']
| //ClassOrInterfaceDeclaration[@Image='XdocsJavaDocsTest']
//MethodDeclaration[@Name='testAllCheckSectionJavaDocs']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/TooManyFields">
<properties>
<!-- Unable to split fields out of the class. -->
<!-- Main has an annotated field for each command line option. This is by design. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='Checker']
| //ClassOrInterfaceDeclaration[@Image='Main']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/ImmutableField">
<properties>
<!-- Main has annotated fields whose value is injected by picocli.
These fields should not be marked final. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='Main']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/TooManyMethods">
<properties>
<property name="maxmethods" value="20"/>
<!-- Reducing the number of methods in RequireThisCheck requires making an excessive hierarchy
or duplicating the code, or making existing methods too complex.
The class PackageObjectFactory has many boilerplate methods. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='RequireThisCheck'
or @Image='PackageObjectFactory']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/ExcessiveClassLength">
<properties>
<!-- *TokenTypes are special classes that are big due to a lot of description comments.
JavadocMethodCheck is a deprecated class, till it is redone to use JavadocAst.
RequireThisCheck has to work with and identify many frames. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='JavadocTokenTypes'
or @Image='TokenTypes' or @Image='JavadocMethodCheck' or @Image='RequireThisCheck']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/ExcessiveParameterList">
<properties>
<!-- The class LocalizedMessage has a constructor with many parameters by design. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='LocalizedMessage']"/>
</properties>
</rule>
<rule ref="category/java/design.xml/ExcessiveImports">
<properties>
<!-- Main actively uses Checkstyle, logging and command line parsing API.
Checker collects external resource locations and sets up the configuration.
CheckstyleAntTask integrates Checkstyle with Ant.
TranslationCheck just get one extra import by annotation usage.
-->
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration[@Image='Main'
or @Image='Checker' or @Image='CheckstyleAntTask' or @Image='TranslationCheck']"/>
</properties>
</rule>
<rule ref="category/java/multithreading.xml">
<!-- Checkstyle is not thread safe till https://github.com/checkstyle/checkstyle/projects/5. -->
<exclude name="UseConcurrentHashMap"/>
</rule>
<rule ref="category/java/multithreading.xml/AvoidSynchronizedAtMethodLevel">
<properties>
<!-- UniqueProperties#put overloads a synchronized method, so it should have synchronized
modifier. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='UniqueProperties']
//MethodDeclarator[@Image='put']"/>
</properties>
</rule>
<rule ref="category/java/performance.xml">
<!-- Produces more false positives than real problems. -->
<exclude name="AvoidInstantiatingObjectsInLoops"/>
<!-- Not configurable, decreases readability. -->
<exclude name="UseStringBufferForStringAppends"/>
</rule>
<rule ref="category/java/performance.xml/AvoidUsingShortType">
<properties>
<!-- This class uses the class java.lang.Short for properties only. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='AutomaticBean']"/>
</properties>
</rule>
<!-- Checkstyle own rules. -->
<rule name="CheckstyleCustomShortVariable"
message="Avoid variables with short names that shorter than 2 symbols: {0}"
language="java"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="">
<description>
Fields, local variables, or parameter names that are very short are not helpful to the reader.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//VariableDeclaratorId[string-length(@Image) < 2]
[not(ancestor::ForInit)]
[not(../../VariableDeclarator and ../../../LocalVariableDeclaration
and ../../../../ForStatement)]
[not((ancestor::FormalParameter) and (ancestor::TryStatement))]
[not(ancestor::ClassOrInterfaceDeclaration[
//MarkerAnnotation/Name[pmd-java:typeIs('java.lang.Override')]])]
]]>
</value>
</property>
</properties>
</rule>
</ruleset>