Skip to content

Commit 60ae17a

Browse files
committed
Add a checkstyle check in the build
1 parent 409ed07 commit 60ae17a

File tree

3 files changed

+176
-2
lines changed

3 files changed

+176
-2
lines changed

buildSrc/src/main/groovy/cssom-apis.java-conventions.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2021-2024, Carlos Amengual.
3+
* Copyright (c) 2021-2025, Carlos Amengual.
44
*
55
* Licensed under a BSD-style License. You can find the license here:
66
* https://css4j.github.io/LICENSE.txt
@@ -13,6 +13,13 @@
1313
plugins {
1414
id 'java-library'
1515
id 'maven-publish'
16+
id 'checkstyle'
17+
}
18+
19+
repositories {
20+
maven {
21+
url = uri('https://repo.maven.apache.org/maven2/')
22+
}
1623
}
1724

1825
group = 'io.sf.w3'
@@ -113,6 +120,10 @@ tasks.withType(AbstractArchiveTask).configureEach {
113120
}
114121
}
115122

123+
checkstyle {
124+
toolVersion = '10.24.0'
125+
}
126+
116127
publishing {
117128
publications {
118129
maven(MavenPublication) {

config/checkstyle/checkstyle.xml

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
3+
<module name="Checker">
4+
<property name="severity" value="warning"/>
5+
<property name="tabWidth" value="4"/>
6+
<property name="fileExtensions" value="java"/>
7+
8+
<module name="BeforeExecutionExclusionFileFilter">
9+
<property name="fileNamePattern" value="module\-info\.java$"/>
10+
</module>
11+
12+
<module name="LineLength">
13+
<!--
14+
Recommended line length is up to 120 characters, but only 130 are enforced.
15+
In the end, readability is more important than arbitrary limits; if you
16+
believe that some file should be allowed more, please use the suppressions
17+
configuration file (under the 'Line length' comment).
18+
-->
19+
<property name="max" value="130"/>
20+
<property name="ignorePattern" value="^\t(?:public |protected |private )?static final"/>
21+
</module>
22+
23+
<!-- Look for trailing whitespace except in single-line comments,
24+
yet allow one if it comes after an asterisk or a javadoc @throws
25+
(the latter is commonly found in tests) -->
26+
<module name="RegexpSingleline">
27+
<property name="format" value="^[^/](?! \* @throws [a-zA-Z]+).*(?:[^*]\s+|\*\s{2,})$"/>
28+
<property name="message" value="Line has trailing spaces."/>
29+
</module>
30+
31+
<module name="TreeWalker">
32+
33+
<module name="OuterTypeFilename"/>
34+
35+
<!-- Enforce the use of tabs for indentation in Java files -->
36+
<module name="RegexpSinglelineJava">
37+
<property name="format" value="^\t* [^/]"/>
38+
<property name="message" value="Indent must use tab characters"/>
39+
<property name="ignoreComments" value="true"/>
40+
</module>
41+
42+
<!-- Use Java-style array declarations -->
43+
<module name="ArrayTypeStyle"/>
44+
45+
<module name="AvoidStarImport">
46+
<property name="severity" value="error"/>
47+
</module>
48+
49+
<!-- Check for a common mistake overriding equals() -->
50+
<module name="CovariantEquals"/>
51+
52+
<module name="EmptyBlock">
53+
<property name="tokens" value="LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_TRY,STATIC_INIT"/>
54+
<property name="option" value="text"/>
55+
</module>
56+
57+
<!-- Detect standalone ";" semicolon -->
58+
<module name="EmptyStatement"/>
59+
60+
<!-- Checks the whitespace around "<" and ">" -->
61+
<module name="GenericWhitespace"/>
62+
63+
<!-- <module name="HideUtilityClassConstructor"/> -->
64+
65+
<!-- Do not import sun.* packages -->
66+
<module name="IllegalImport"/>
67+
68+
<module name="IllegalInstantiation"/>
69+
70+
<module name="LeftCurly"/>
71+
72+
<!-- Checks that local variable names conform to a specified pattern -->
73+
<module name="LocalVariableName">
74+
<property name="format" value="[a-z](_?[a-zA-Z0-9]+)*$"/>
75+
</module>
76+
77+
<!-- Enforce that instance variable names conform to a specified pattern -->
78+
<module name="MemberName">
79+
<property name="format" value="[a-z](_?[a-zA-Z0-9]+)*$"/>
80+
<property name="applyToPrivate" value="false"/>
81+
</module>
82+
83+
<!-- Verify that method names conform to a specified pattern -->
84+
<module name="MethodName">
85+
<property name="format" value="^[a-z](_?[a-zA-Z0-9]+)*$"/>
86+
</module>
87+
88+
<module name="MethodParamPad"/>
89+
90+
<!-- Checks that there is no method finalize with zero parameters -->
91+
<module name="NoFinalizer"/>
92+
93+
<!-- Checks that there is no whitespace after a token -->
94+
<module name="NoWhitespaceAfter">
95+
<property name="allowLineBreaks" value="false"/>
96+
<property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS"/>
97+
</module>
98+
99+
<module name="WhitespaceAround">
100+
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LCURLY,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,TYPE_EXTENSION_AND"/>
101+
<property name="ignoreEnhancedForColon" value="false"/>
102+
</module>
103+
104+
<module name="OneStatementPerLine"/>
105+
106+
<!-- Checks that package names conform to a pattern -->
107+
<module name="PackageName"/>
108+
109+
<module name="ParameterName">
110+
<!-- For readability, names starting with '_' are not allowed -->
111+
<property name="format" value="^[a-z](_?[a-zA-Z0-9]+)*$"/>
112+
</module>
113+
114+
<!-- Verify the padding of parentheses -->
115+
<module name="ParenPad"/>
116+
117+
<!-- Look for redundant imports -->
118+
<module name="RedundantImport"/>
119+
120+
<!-- Checks for redundant modifiers (e.g. 'public' in interface methods) -->
121+
<module name="RedundantModifier">
122+
<property name="tokens" value="INTERFACE_DEF,ENUM_DEF"/>
123+
</module>
124+
125+
<module name="RightCurly">
126+
<property name="tokens" value="LITERAL_ELSE,LITERAL_FOR,LITERAL_WHILE,LITERAL_DO,METHOD_DEF,STATIC_INIT,INTERFACE_DEF,RECORD_DEF,LITERAL_SWITCH"/>
127+
</module>
128+
129+
<!-- Checks for over-complicated boolean expressions -->
130+
<module name="SimplifyBooleanExpression"/>
131+
132+
<module name="SimplifyBooleanReturn"/>
133+
134+
<module name="SingleSpaceSeparator"/>
135+
136+
<!-- Checks that static, non-final variable names conform to a pattern -->
137+
<!-- <module name="StaticVariableName"/> -->
138+
139+
<module name="SuppressionCommentFilter">
140+
<property name="offCommentFormat" value="CSOFF\: ([\w\|]+)"/>
141+
<property name="onCommentFormat" value="CSON\: ([\w\|]+)"/>
142+
<property name="checkFormat" value="$1"/>
143+
</module>
144+
145+
<!-- parentheses for typecasts -->
146+
<module name="TypecastParenPad">
147+
<property name="tokens" value="RPAREN,TYPECAST"/>
148+
</module>
149+
150+
<module name="TypeName">
151+
<property name="format" value="^[A-Z](_?[a-zA-Z0-9]+)*$"/>
152+
</module>
153+
154+
<module name="UnusedImports">
155+
<property name="processJavadoc" value="true"/>
156+
</module>
157+
158+
<!-- Checks that long constants are defined with an 'L' -->
159+
<module name="UpperEll"/>
160+
161+
</module>
162+
163+
</module>

cssom-api/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2021-2024, Carlos Amengual.
3+
* Copyright (c) 2021-2025, Carlos Amengual.
44
*
55
* Licensed under a BSD-style License. You can find the license here:
66
* https://css4j.github.io/LICENSE.txt

0 commit comments

Comments
 (0)