Skip to content

Commit 8ec5b2d

Browse files
authored
Merge pull request #125 from novuhq/coding-standards
Implement Coding Standard Adherence with Checkstyle
2 parents 156a809 + b1b4d5c commit 8ec5b2d

File tree

156 files changed

+1075
-637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+1075
-637
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
3+
<!DOCTYPE suppressions PUBLIC
4+
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN" "https://checkstyle.org/dtds/suppressions_1_0.dtd">
5+
6+
<suppressions>
7+
<suppress checks="JavadocPackage" files="."/>
8+
<suppress checks="HideUtilityClassConstructor" files="."/>
9+
<suppress checks="JavadocType" files="."/>
10+
<suppress checks="JavadocMethod" files="."/>
11+
<suppress checks="JavadocVariable" files="."/>
12+
</suppressions>

config/checkstyle/checkstyle.xml

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
6+
<!--
7+
8+
Checkstyle configuration that checks the sun coding conventions from:
9+
10+
- the Java Language Specification at
11+
https://docs.oracle.com/javase/specs/jls/se11/html/index.html
12+
13+
- the Sun Code Conventions at https://www.oracle.com/java/technologies/javase/codeconventions-contents.html
14+
15+
- the Javadoc guidelines at
16+
https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html
17+
18+
- the JDK Api documentation https://docs.oracle.com/en/java/javase/11/
19+
20+
- some best practices
21+
22+
Checkstyle is very configurable. Be sure to read the documentation at
23+
https://checkstyle.org (or in your downloaded distribution).
24+
25+
Most Checks are configurable, be sure to consult the documentation.
26+
27+
To completely disable a check, just comment it out or delete it from the file.
28+
To suppress certain violations please review suppression filters.
29+
30+
Finally, it is worth reading the documentation.
31+
32+
-->
33+
34+
<module name="Checker">
35+
<!--
36+
If you set the basedir property below, then all reported file
37+
names will be relative to the specified directory. See
38+
https://checkstyle.org/config.html#Checker
39+
40+
<property name="basedir" value="${basedir}"/>
41+
-->
42+
<property name="severity" value="error"/>
43+
44+
<property name="fileExtensions" value="java, properties, xml"/>
45+
46+
<!-- Excludes all 'module-info.java' files -->
47+
<!-- See https://checkstyle.org/filefilters/index.html -->
48+
<module name="BeforeExecutionExclusionFileFilter">
49+
<property name="fileNamePattern" value="module\-info\.java$"/>
50+
</module>
51+
52+
<!-- https://checkstyle.org/filters/suppressionfilter.html -->
53+
<module name="SuppressionFilter">
54+
<property name="file" value="${org.checkstyle.sun.suppressionfilter.config}"
55+
default="checkstyle-suppressions.xml" />
56+
<property name="optional" value="true"/>
57+
</module>
58+
59+
<!-- Checks that a package-info.java file exists for each package. -->
60+
<!-- See https://checkstyle.org/checks/javadoc/javadocpackage.html#JavadocPackage -->
61+
<module name="JavadocPackage"/>
62+
63+
<!-- Checks whether files end with a new line. -->
64+
<!-- See https://checkstyle.org/checks/misc/newlineatendoffile.html -->
65+
<module name="NewlineAtEndOfFile"/>
66+
67+
<!-- Checks that property files contain the same keys. -->
68+
<!-- See https://checkstyle.org/checks/misc/translation.html -->
69+
<module name="Translation"/>
70+
71+
<!-- Checks for Size Violations. -->
72+
<!-- See https://checkstyle.org/checks/sizes/index.html -->
73+
<module name="FileLength"/>
74+
<module name="LineLength">
75+
<property name="fileExtensions" value="java"/>
76+
<property name="max" value="120"/>
77+
</module>
78+
79+
<!-- Checks for whitespace -->
80+
<!-- See https://checkstyle.org/checks/whitespace/index.html -->
81+
<module name="FileTabCharacter"/>
82+
83+
<!-- Miscellaneous other checks. -->
84+
<!-- See https://checkstyle.org/checks/misc/index.html -->
85+
<module name="RegexpSingleline">
86+
<property name="format" value="\s+$"/>
87+
<property name="minimum" value="0"/>
88+
<property name="maximum" value="0"/>
89+
<property name="message" value="Line has trailing spaces."/>
90+
</module>
91+
92+
<!-- Checks for Headers -->
93+
<!-- See https://checkstyle.org/checks/header/index.html -->
94+
<!-- <module name="Header"> -->
95+
<!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
96+
<!-- <property name="fileExtensions" value="java"/> -->
97+
<!-- </module> -->
98+
99+
<module name="TreeWalker">
100+
101+
<!-- Checks for Javadoc comments. -->
102+
<!-- See https://checkstyle.org/checks/javadoc/index.html -->
103+
<module name="InvalidJavadocPosition"/>
104+
<module name="JavadocMethod"/>
105+
<module name="JavadocType"/>
106+
<module name="JavadocVariable"/>
107+
<module name="JavadocStyle"/>
108+
<module name="MissingJavadocMethod"/>
109+
110+
<!-- Checks for Naming Conventions. -->
111+
<!-- See https://checkstyle.org/checks/naming/index.html -->
112+
<module name="ConstantName"/>
113+
<module name="LocalFinalVariableName"/>
114+
<module name="LocalVariableName"/>
115+
<module name="MemberName"/>
116+
<module name="MethodName"/>
117+
<module name="PackageName"/>
118+
<module name="ParameterName"/>
119+
<module name="StaticVariableName"/>
120+
<module name="TypeName"/>
121+
122+
<!-- Checks for imports -->
123+
<!-- See https://checkstyle.org/checks/imports/index.html -->
124+
<module name="AvoidStarImport"/>
125+
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
126+
<module name="RedundantImport"/>
127+
<module name="UnusedImports">
128+
<property name="processJavadoc" value="false"/>
129+
</module>
130+
131+
<!-- Checks for Size Violations. -->
132+
<!-- See https://checkstyle.org/checks/sizes/index.html -->
133+
<module name="MethodLength"/>
134+
<module name="ParameterNumber"/>
135+
136+
<!-- Checks for whitespace -->
137+
<!-- See https://checkstyle.org/checks/whitespace/index.html -->
138+
<module name="EmptyForIteratorPad"/>
139+
<module name="GenericWhitespace"/>
140+
<module name="MethodParamPad"/>
141+
<module name="NoWhitespaceAfter"/>
142+
<module name="NoWhitespaceBefore"/>
143+
<module name="OperatorWrap"/>
144+
<module name="ParenPad"/>
145+
<module name="TypecastParenPad"/>
146+
<module name="WhitespaceAfter"/>
147+
<module name="WhitespaceAround"/>
148+
149+
<!-- Modifier Checks -->
150+
<!-- See https://checkstyle.org/checks/modifier/index.html -->
151+
<module name="ModifierOrder"/>
152+
<module name="RedundantModifier"/>
153+
154+
<!-- Checks for blocks. You know, those {}'s -->
155+
<!-- See https://checkstyle.org/checks/blocks/index.html -->
156+
<module name="AvoidNestedBlocks"/>
157+
<module name="EmptyBlock"/>
158+
<module name="LeftCurly"/>
159+
<module name="NeedBraces"/>
160+
<module name="RightCurly"/>
161+
162+
<!-- Checks for common coding problems -->
163+
<!-- See https://checkstyle.org/checks/coding/index.html -->
164+
<module name="EmptyStatement"/>
165+
<module name="EqualsHashCode"/>
166+
<module name="HiddenField"/>
167+
<module name="IllegalInstantiation"/>
168+
<module name="InnerAssignment"/>
169+
<module name="MagicNumber"/>
170+
<module name="MissingSwitchDefault"/>
171+
<module name="MultipleVariableDeclarations"/>
172+
<module name="SimplifyBooleanExpression"/>
173+
<module name="SimplifyBooleanReturn"/>
174+
175+
<!-- Checks for class design -->
176+
<!-- See https://checkstyle.org/checks/design/index.html -->
177+
<module name="DesignForExtension"/>
178+
<module name="FinalClass"/>
179+
<module name="HideUtilityClassConstructor"/>
180+
<module name="InterfaceIsType"/>
181+
<module name="VisibilityModifier"/>
182+
183+
<!-- Miscellaneous other checks. -->
184+
<!-- See https://checkstyle.org/checks/misc/index.html -->
185+
<module name="ArrayTypeStyle"/>
186+
<module name="FinalParameters"/>
187+
<module name="TodoComment"/>
188+
<module name="UpperEll"/>
189+
190+
<!-- https://checkstyle.org/filters/suppressionxpathfilter.html -->
191+
<module name="SuppressionXpathFilter">
192+
<property name="file" value="${org.checkstyle.sun.suppressionxpathfilter.config}"
193+
default="checkstyle-xpath-suppressions.xml" />
194+
<property name="optional" value="true"/>
195+
</module>
196+
197+
</module>
198+
199+
</module>

pom.xml

+32-9
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,38 @@
124124
</profiles>
125125

126126
<build>
127-
<pluginManagement>
128-
<plugins>
129-
<plugin>
130-
<groupId>org.apache.maven.plugins</groupId>
131-
<artifactId>maven-surefire-plugin</artifactId>
132-
<version>3.0.0</version>
133-
</plugin>
134-
</plugins>
135-
</pluginManagement>
127+
<plugins>
128+
<plugin>
129+
<groupId>org.apache.maven.plugins</groupId>
130+
<artifactId>maven-surefire-plugin</artifactId>
131+
<version>3.0.0</version>
132+
</plugin>
133+
<plugin>
134+
<groupId>org.apache.maven.plugins</groupId>
135+
<artifactId>maven-checkstyle-plugin</artifactId>
136+
<version>3.3.1</version>
137+
<configuration>
138+
<configLocation>config/checkstyle/checkstyle.xml</configLocation>
139+
<suppressionsLocation>config/checkstyle/checkstyle-suppressions.xml</suppressionsLocation>
140+
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
141+
</configuration>
142+
<executions>
143+
<execution>
144+
<id>lint-check</id>
145+
<phase>validate</phase>
146+
<configuration>
147+
<encoding>UTF-8</encoding>
148+
<consoleOutput>true</consoleOutput>
149+
<failsOnError>true</failsOnError>
150+
<linkXRef>false</linkXRef>
151+
</configuration>
152+
<goals>
153+
<goal>check</goal>
154+
</goals>
155+
</execution>
156+
</executions>
157+
</plugin>
158+
</plugins>
136159
</build>
137160

138161
<properties>

src/main/java/co/novu/api/blueprints/BlueprintsHandler.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88

99
import java.io.IOException;
1010

11-
public class BlueprintsHandler {
11+
public final class BlueprintsHandler {
1212

1313
private final RestHandler restHandler;
1414

1515
private final BlueprintsApi blueprintsApi;
1616

17-
public BlueprintsHandler(RestHandler restHandler) {
18-
this.restHandler = restHandler;
19-
this.blueprintsApi = restHandler.buildRetrofit().create(BlueprintsApi.class);
17+
public BlueprintsHandler(final RestHandler handler) {
18+
this.restHandler = handler;
19+
this.blueprintsApi = handler.buildRetrofit().create(BlueprintsApi.class);
2020
}
2121

2222
public BlueprintsByCategoryResponse getBlueprintsByCategory() throws IOException, NovuNetworkException {
2323
Response<BlueprintsByCategoryResponse> response = blueprintsApi.getBlueprintsByCategory().execute();
2424
return restHandler.extractResponse(response);
2525
}
2626

27-
public Blueprint getBlueprint(String templateId) throws IOException, NovuNetworkException {
27+
public Blueprint getBlueprint(final String templateId) throws IOException, NovuNetworkException {
2828
Response<Blueprint> response = blueprintsApi.getBlueprint(templateId).execute();
2929
return restHandler.extractResponse(response);
3030
}
31-
}
31+
}

src/main/java/co/novu/api/blueprints/pojos/Blueprint.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ public class Blueprint {
4040
@SerializedName("__v")
4141
private Long version;
4242
private NotificationGroup notificationGroup;
43-
}
43+
}

src/main/java/co/novu/api/blueprints/pojos/Content.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ public class Content {
77
private String type;
88
private String content;
99
private Styles styles;
10-
}
10+
}

src/main/java/co/novu/api/blueprints/pojos/Filters.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ public class Filters {
1010
private List<String> children;
1111
@SerializedName("_id")
1212
private String id;
13-
}
13+
}

src/main/java/co/novu/api/blueprints/pojos/General.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
public class General {
99
private String name;
1010
private List<Blueprint> blueprints;
11-
}
11+
}

src/main/java/co/novu/api/blueprints/pojos/Metadata.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
@Data
66
public class Metadata {
77
private Timed timed;
8-
}
8+
}

src/main/java/co/novu/api/blueprints/pojos/Popular.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
public class Popular {
99
private String name;
1010
private List<Blueprint> blueprints;
11-
}
11+
}

src/main/java/co/novu/api/blueprints/pojos/Styles.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
@Data
66
public class Styles {
77
private String textAlign;
8-
}
8+
}

src/main/java/co/novu/api/blueprints/pojos/Template.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ public class Template {
2929
private String updatedAt;
3030
@SerializedName("__v")
3131
private Long version;
32-
}
32+
}

src/main/java/co/novu/api/blueprints/pojos/Timed.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
public class Timed {
99
private List<String> weekDays;
1010
private List<String> monthDays;
11-
}
11+
}

src/main/java/co/novu/api/blueprints/pojos/Variables.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ public class Variables {
88
private String type;
99
private Boolean required;
1010
private String id;
11-
}
11+
}

src/main/java/co/novu/api/blueprints/responses/BlueprintsByCategoryResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
@Data
66
public class BlueprintsByCategoryResponse {
77
private BlueprintsResponseData data;
8-
}
8+
}

src/main/java/co/novu/api/blueprints/responses/BlueprintsResponseData.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package co.novu.api.blueprints.responses;
2+
23
import co.novu.api.blueprints.pojos.General;
34
import co.novu.api.blueprints.pojos.Popular;
45
import lombok.Data;
@@ -9,4 +10,4 @@
910
public class BlueprintsResponseData {
1011
private List<General> general;
1112
private Popular popular;
12-
}
13+
}

0 commit comments

Comments
 (0)