Skip to content

Commit 487b36f

Browse files
committed
Add a checkstyle check in the build
1 parent 85d2965 commit 487b36f

File tree

5 files changed

+198
-2
lines changed

5 files changed

+198
-2
lines changed

build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1+
/*
2+
3+
Copyright (c) 2021-2025, C. Amengual.
4+
5+
Licensed under a BSD-style License. You can find the license here:
6+
https://css4j.github.io/LICENSE.txt
7+
8+
*/
9+
10+
// SPDX-License-Identifier: BSD-3-Clause
11+
112
plugins {
213
id 'java-library'
314
id 'maven-publish'
15+
id 'checkstyle'
416
id 'org.gradlex.extra-java-module-info' version '1.12'
517
}
618

@@ -62,6 +74,10 @@ extraJavaModuleInfo {
6274
automaticModule('htmlparser-1.4.16.jar', 'htmlparser')
6375
}
6476

77+
checkstyle {
78+
toolVersion = '10.24.0'
79+
}
80+
6581
repositories {
6682
maven {
6783
url = uri('https://repo.maven.apache.org/maven2/')

config/checkstyle/checkstyle.xml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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="SuppressionFilter">
32+
<property name="file" value="${config_loc}/suppressions.xml"/>
33+
</module>
34+
35+
<module name="TreeWalker">
36+
37+
<module name="OuterTypeFilename"/>
38+
39+
<!-- Enforce the use of tabs for indentation in Java files -->
40+
<module name="RegexpSinglelineJava">
41+
<property name="format" value="^\t* [^/]"/>
42+
<property name="message" value="Indent must use tab characters"/>
43+
<property name="ignoreComments" value="true"/>
44+
</module>
45+
46+
<!-- Use Java-style array declarations -->
47+
<module name="ArrayTypeStyle"/>
48+
49+
<module name="AvoidStarImport">
50+
<property name="severity" value="error"/>
51+
</module>
52+
53+
<!-- Check for a common mistake overriding equals() -->
54+
<module name="CovariantEquals"/>
55+
56+
<module name="EmptyBlock">
57+
<property name="tokens" value="LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_TRY,STATIC_INIT"/>
58+
<property name="option" value="text"/>
59+
</module>
60+
61+
<!-- Detect standalone ";" semicolon -->
62+
<module name="EmptyStatement"/>
63+
64+
<!-- Checks the whitespace around "<" and ">" -->
65+
<module name="GenericWhitespace"/>
66+
67+
<!-- <module name="HideUtilityClassConstructor"/> -->
68+
69+
<!-- Do not import sun.* packages -->
70+
<module name="IllegalImport"/>
71+
72+
<module name="IllegalInstantiation"/>
73+
74+
<module name="LeftCurly"/>
75+
76+
<!-- Checks that local variable names conform to a specified pattern -->
77+
<module name="LocalVariableName">
78+
<property name="format" value="[a-z](_?[a-zA-Z0-9]+)*$"/>
79+
</module>
80+
81+
<!-- Enforce that instance variable names conform to a specified pattern -->
82+
<module name="MemberName">
83+
<property name="format" value="[a-z](_?[a-zA-Z0-9]+)*$"/>
84+
<property name="applyToPrivate" value="false"/>
85+
</module>
86+
87+
<!-- Verify that method names conform to a specified pattern -->
88+
<module name="MethodName">
89+
<property name="format" value="^[a-z](_?[a-zA-Z0-9]+)*$"/>
90+
</module>
91+
92+
<module name="MethodParamPad"/>
93+
94+
<!-- Checks that there is no method finalize with zero parameters -->
95+
<module name="NoFinalizer"/>
96+
97+
<!-- Checks that there is no whitespace after a token -->
98+
<module name="NoWhitespaceAfter">
99+
<property name="allowLineBreaks" value="false"/>
100+
<property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS"/>
101+
</module>
102+
103+
<module name="WhitespaceAround">
104+
<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"/>
105+
<property name="ignoreEnhancedForColon" value="false"/>
106+
</module>
107+
108+
<module name="OneStatementPerLine"/>
109+
110+
<!-- Checks that package names conform to a pattern -->
111+
<module name="PackageName"/>
112+
113+
<module name="ParameterName">
114+
<!-- For readability, names starting with '_' are not allowed -->
115+
<property name="format" value="^[a-z](_?[a-zA-Z0-9]+)*$"/>
116+
</module>
117+
118+
<!-- Verify the padding of parentheses -->
119+
<module name="ParenPad"/>
120+
121+
<!-- Look for redundant imports -->
122+
<module name="RedundantImport"/>
123+
124+
<!-- Checks for redundant modifiers (e.g. 'public' in interface methods) -->
125+
<module name="RedundantModifier">
126+
<property name="tokens" value="INTERFACE_DEF,ENUM_DEF"/>
127+
</module>
128+
129+
<module name="RightCurly">
130+
<property name="tokens" value="LITERAL_ELSE,LITERAL_FOR,LITERAL_WHILE,LITERAL_DO,METHOD_DEF,STATIC_INIT,INTERFACE_DEF,RECORD_DEF,LITERAL_SWITCH"/>
131+
</module>
132+
133+
<!-- Checks for over-complicated boolean expressions -->
134+
<module name="SimplifyBooleanExpression"/>
135+
136+
<module name="SimplifyBooleanReturn"/>
137+
138+
<module name="SingleSpaceSeparator"/>
139+
140+
<!-- Checks that static, non-final variable names conform to a pattern -->
141+
<!-- <module name="StaticVariableName"/> -->
142+
143+
<module name="SuppressionCommentFilter">
144+
<property name="offCommentFormat" value="CSOFF\: ([\w\|]+)"/>
145+
<property name="onCommentFormat" value="CSON\: ([\w\|]+)"/>
146+
<property name="checkFormat" value="$1"/>
147+
</module>
148+
149+
<!-- parentheses for typecasts -->
150+
<module name="TypecastParenPad">
151+
<property name="tokens" value="RPAREN,TYPECAST"/>
152+
</module>
153+
154+
<module name="TypeName">
155+
<property name="format" value="^[A-Z](_?[a-zA-Z0-9]+)*$"/>
156+
</module>
157+
158+
<module name="UnusedImports">
159+
<property name="processJavadoc" value="true"/>
160+
</module>
161+
162+
<!-- Checks that long constants are defined with an 'L' -->
163+
<module name="UpperEll"/>
164+
165+
</module>
166+
167+
</module>

config/checkstyle/suppressions.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">
3+
<suppressions>
4+
<!-- Line length -->
5+
<suppress files="[\\/]PseudoClassTest\.java$" checks="LineLength"/>
6+
<suppress files="[\\/]XHTMLDocumentTest\.java$" checks="LineLength"/>
7+
8+
<!-- Disable other checks in tests -->
9+
<suppress files="Test[0-9]?\.java$" checks="LeftCurly"/>
10+
<suppress files="Test[0-9]?\.java$" checks="MethodName"/>
11+
<suppress files="[\\/]junit[\\/]" checks="SimplifyBooleanReturn"/>
12+
<suppress files="Test[0-9]?\.java$" checks="WhitespaceAround"/>
13+
</suppressions>

junit/io/sf/carte/doc/dom4j/XHTMLDocumentFactoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void testMockDocumentFactory() throws Exception {
7878
assertNotNull(is);
7979
InputStreamReader re = new InputStreamReader(is, StandardCharsets.UTF_8);
8080
StringWriter sw = new StringWriter(100);
81-
char b[] = new char[3000];
81+
char[] b = new char[3000];
8282
int n;
8383
while ((n = re.read(b)) != -1) {
8484
sw.write(b, 0, n);

src/io/sf/carte/doc/dom4j/DOM4JUserAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public XHTMLDocument readURL(URL url) throws IOException, io.sf.carte.doc.Docume
130130
String metaDefStyle = element.getAttributeValue("content");
131131
if (metaDefStyle.length() != 0) {
132132
// Per HTML4 spec § 14.3.2:
133-
// "If two or more META declarations or HTTP headers specify
133+
// "If two or more META declarations or HTTP headers specify
134134
// the preferred style sheet, the last one takes precedence."
135135
defStyle = metaDefStyle;
136136
}

0 commit comments

Comments
 (0)