-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruleset.xml
89 lines (73 loc) · 5.32 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
<?xml version="1.0"?>
<ruleset name="PMD HappyCoders Rules (relaxed for binary tree repository)"
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>PMD ruleset for HappyCoders.eu</description>
<rule ref="category/java/bestpractices.xml">
<exclude name="ArrayIsStoredDirectly"/> <!-- This is usually a good rule as robustness is more important than performance. In Advent of Code, it's the other way round :-) -->
<exclude name="AvoidReassigningParameters"/> <!-- IMO, that's OK if you do it right at the beginning of a method, e.g., to trim a String parameter. -->
<exclude name="LiteralsFirstInComparisons"/> <!-- IMO, that's OK if you know that the variable is not null. -->
<exclude name="MethodReturnsInternalArray"/> <!-- This is usually a good rule as robustness is more important than performance. In Advent of Code, it's the other way round :-) -->
<exclude name="SystemPrintln"/> <!-- While this rule makes sense for most applications, here we just sometimes want to print things. -->
<exclude name="UseVarargs"/> <!-- PMD suggests this where it doesn't make sense, meaning where I always pass in an existing array. -->
</rule>
<rule ref="category/java/codestyle.xml">
<exclude name="AtLeastOneConstructor"/> <!-- We don't need artificial default constructors. -->
<exclude name="CallSuperInConstructor"/> <!-- We don't need to call the super constructor explicitly if it's done implicitly. -->
<exclude name="CommentDefaultAccessModifier"/> <!-- We don't comment why we make fields private, protected or public. So why should we comment on default access? -->
<exclude name="LocalVariableCouldBeFinal"/> <!-- Using 'final' on local variables (in contrast to fields) has no effect on the compiler; IMO it's noise. -->
<exclude name="MethodArgumentCouldBeFinal"/> <!-- Using 'final' on method arguments (in contrast to fields) has no effect on the compiler; IMO it's noise. -->
<exclude name="OnlyOneReturn"/> <!-- IMO not a good rule as it would make some methods more complicated than necessary. -->
<exclude name="ShortClassName"/> <!-- Wouldn't allow class names like "File" -->
<exclude name="ShortMethodName"/> <!-- Wouldn't allow method names like "of". -->
</rule>
<rule ref="category/java/codestyle.xml/ShortVariable">
<properties>
<property name="minimum" value="2" /> <!-- Default min is 3, but that wouldn't allow a variable name like "id". -->
</properties>
</rule>
<rule ref="category/java/codestyle.xml/TooManyStaticImports">
<properties>
<property name="maximumStaticImports" value="10" /><!-- Default is 4, which is too low IMO. -->
</properties>
</rule>
<rule ref="category/java/codestyle.xml/LongVariable">
<properties>
<property name="minimum" value="65" /> <!-- Default max is 16, which is not always enough for a descriptive name; allow longer variables. -->
</properties>
</rule>
<rule ref="category/java/design.xml">
<exclude name="LawOfDemeter"/> <!-- That rule also forbids fluent programming style. -->
<exclude name="UseUtilityClass"/> <!-- Usually, this is a good rule; in this project however, I would consider this noise. -->
</rule>
<!-- Ignore class length checks for puzzle inputs -->
<rule ref="category/java/design.xml/ExcessiveClassLength">
<properties>
<property name="violationSuppressXPath" value="//ClassOrInterfaceDeclaration['Main*.java']"/>
</properties>
</rule>
<rule ref="category/java/documentation.xml">
<exclude name="CommentRequired"/> <!-- Would require comments on all fields, public methods, and constructors. Good names are a much better documentation. -->
<exclude name="CommentSize"/> <!-- Don't limit the size of comments. -->
</rule>
<rule ref="category/java/errorprone.xml">
<exclude name="AvoidFieldNameMatchingMethodName"/> <!-- I personally like using the field name also as an accessor name for final fields (like in Java records). -->
<exclude name="NullAssignment"/> <!-- Sometimes, we want to reset a value, e.g. in an array backing a collection, so it can be garbage-collected. -->
<exclude name="NonSerializableClass"/> <!-- We don't use serialization. -->
</rule>
<!-- Allow a few other literals than the default (-1, 0). -->
<rule ref="category/java/errorprone.xml/AvoidLiteralsInIfCondition">
<properties>
<property name="ignoreMagicNumbers" value="-1,0,1,2" />
</properties>
</rule>
<rule ref="category/java/multithreading.xml">
<exclude name="UseConcurrentHashMap"/> <!-- We have no multithreading in Advent of Code. -->
</rule>
<rule ref="category/java/performance.xml">
<exclude name="AvoidInstantiatingObjectsInLoops"/> <!-- Rule makes sense only sometimes. -->
<exclude name="InsufficientStringBufferDeclaration"/><!-- I consider this premature optimization. -->
</rule>
<rule ref="category/java/security.xml"/>
</ruleset>