Skip to content

Commit 0e32762

Browse files
Code Quality: Add CheckStyle (#284)
* Add checkStyle to build.gradle. * Add checkstyle configuration files.
1 parent 057516f commit 0e32762

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ plugins {
44
id 'java'
55
id "io.freefair.lombok" version "5.1.0"
66
id 'jacoco'
7+
id 'checkstyle'
78
}
89

10+
apply plugin: 'checkstyle'
11+
912
group = 'uk.nhs.digital.nhsconnect'
1013
version = '0.0.1-SNAPSHOT'
1114
sourceCompatibility = '11'

config/checkstyle/checkstyle.xml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
5+
6+
<module name="Checker">
7+
<!--
8+
If you set the basedir property below, then all reported file
9+
names will be relative to the specified directory. See
10+
http://checkstyle.sourceforge.net/5.x/config.html#Checker
11+
12+
<property name="basedir" value="${basedir}"/>
13+
-->
14+
15+
<property name="fileExtensions" value="java, properties, xml"/>
16+
17+
<!-- Checks that property files contain the same keys. -->
18+
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
19+
<module name="Translation"/>
20+
21+
<!-- Checks for Size Violations. -->
22+
<!-- See http://checkstyle.sf.net/config_sizes.html -->
23+
<module name="FileLength"/>
24+
25+
<!-- Checks for whitespace -->
26+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
27+
<!-- No tabs, only spaces -->
28+
<module name="FileTabCharacter"/>
29+
30+
<!-- Miscellaneous other checks. -->
31+
<!-- See http://checkstyle.sf.net/config_misc.html -->
32+
<module name="RegexpSingleline">
33+
<property name="format" value="\s+$"/>
34+
<property name="minimum" value="0"/>
35+
<property name="maximum" value="0"/>
36+
<property name="message" value="Line has trailing spaces."/>
37+
</module>
38+
39+
<module name="LineLength">
40+
<property name="max" value="140"/>
41+
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
42+
</module>
43+
44+
<module name="TreeWalker">
45+
<module name="Indentation">
46+
<property name="basicOffset" value="4" />
47+
</module>
48+
49+
<!-- Checks for Naming Conventions. -->
50+
<!-- See http://checkstyle.sf.net/config_naming.html -->
51+
<module name="ConstantName"/>
52+
<module name="LocalVariableName"/>
53+
<module name="MemberName"/>
54+
55+
<module name="MethodName">
56+
<property name="format" value="^(([a-z][a-z0-9][a-zA-Z0-9]*)|(When_[A-Z][a-zA-Z0-9]*(_[A-Z][a-zA-Z0-9]*)*_Expect_[A-Z][a-zA-Z0-9]*))$"/>
57+
</module>
58+
59+
60+
<module name="PackageName">
61+
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
62+
<message key="name.invalidPattern"
63+
value="Package name ''{0}'' must match pattern ''{1}''."/>
64+
</module>
65+
66+
<module name="ParameterName"/>
67+
<module name="StaticVariableName"/>
68+
<module name="TypeName"/>
69+
70+
<!-- Checks for imports -->
71+
<!-- See http://checkstyle.sf.net/config_import.html -->
72+
<module name="AvoidStarImport"/>
73+
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
74+
<module name="RedundantImport"/>
75+
<module name="UnusedImports">
76+
<property name="processJavadoc" value="false"/>
77+
</module>
78+
79+
<!-- Checks for Size Violations. -->
80+
<!-- See http://checkstyle.sf.net/config_sizes.html -->
81+
<module name="MethodLength"/>
82+
<module name="ParameterNumber"/>
83+
84+
<!-- Checks for whitespace -->
85+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
86+
<module name="EmptyForIteratorPad"/>
87+
<module name="GenericWhitespace"/>
88+
<module name="MethodParamPad"/>
89+
<module name="NoWhitespaceAfter"/>
90+
<module name="NoWhitespaceBefore"/>
91+
<module name="OperatorWrap"/>
92+
<module name="ParenPad"/>
93+
<module name="TypecastParenPad"/>
94+
<module name="WhitespaceAfter"/>
95+
<module name="WhitespaceAround"/>
96+
97+
<!-- Modifier Checks -->
98+
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
99+
<module name="ModifierOrder"/>
100+
<module name="RedundantModifier"/>
101+
102+
<!-- Checks for blocks. You know, those {}'s -->
103+
<!-- See http://checkstyle.sf.net/config_blocks.html -->
104+
<module name="AvoidNestedBlocks"/>
105+
<module name="EmptyBlock"/>
106+
<module name="LeftCurly"/>
107+
<module name="NeedBraces"/>
108+
<module name="RightCurly"/>
109+
110+
<!-- Checks for common coding problems -->
111+
<!-- See http://checkstyle.sf.net/config_coding.html -->
112+
<module name="EmptyStatement"/>
113+
<module name="EqualsHashCode"/>
114+
<module name="IllegalInstantiation"/>
115+
<module name="InnerAssignment"/>
116+
<module name="MagicNumber"/>
117+
<module name="MissingSwitchDefault"/>
118+
<module name="SimplifyBooleanExpression"/>
119+
<module name="SimplifyBooleanReturn"/>
120+
121+
<!-- Checks for class design -->
122+
<!-- See http://checkstyle.sf.net/config_design.html -->
123+
<module name="FinalClass"/>
124+
<module name="HideUtilityClassConstructor"/>
125+
<module name="InterfaceIsType"/>
126+
<module name="VisibilityModifier"/>
127+
128+
<!-- Miscellaneous other checks. -->
129+
<!-- See http://checkstyle.sf.net/config_misc.html -->
130+
<module name="ArrayTypeStyle"/>
131+
<module name="UpperEll"/>
132+
<module name="SuppressWarningsHolder" />
133+
</module>
134+
135+
<module name="SuppressWarningsFilter"/>
136+
137+
<module name="SuppressionFilter">
138+
<property name="file" value="${config_loc}/suppressions.xml"/>
139+
</module>
140+
</module>

config/checkstyle/suppressions.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE suppressions PUBLIC
4+
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
5+
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
6+
7+
<suppressions>
8+
<suppress files=".*\.java" checks="HideUtilityClassConstructorCheck"/>
9+
</suppressions>

0 commit comments

Comments
 (0)