· 6 years ago · Sep 19, 2019, 09:18 PM
1<?xml version="1.0"?>
2<!DOCTYPE module PUBLIC
3 "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4 "http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">
5
6<!--
7
8 Checkstyle configuration that checks a subset of coding conventions from:
9
10 - Google coding conventions from Google Java Style
11 that can be found at https://google.github.io/styleguide/javaguide.html.
12
13 - the Java Language Specification at
14 http://java.sun.com/docs/books/jls/second_edition/html/index.html
15
16 - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
17
18 - the Javadoc guidelines at
19 http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
20
21 - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
22
23 - some best practices
24
25 Checkstyle is very configurable. Be sure to read the documentation at
26 http://checkstyle.sf.net (or in your downloaded distribution).
27
28 Most Checks are configurable, be sure to consult the documentation.
29
30 To completely disable a check, just comment it out or delete it from the file.
31
32 Finally, it is worth reading the documentation.
33
34 Author: J.D. DeVaughn-Brown
35
36-->
37
38<module name="Checker">
39 <!--
40 If you set the basedir property below, then all reported file
41 names will be relative to the specified directory. See
42 http://checkstyle.sourceforge.net/5.x/config.html#Checker
43
44 <property name="basedir" value="${basedir}"/>
45 -->
46
47 <!-- =========================================================================== -->
48 <!-- =========================================================================== -->
49 <!-- CHECKS THAT DO NOT REQUIRE WALKING THE PARSE TREE -->
50 <!-- =========================================================================== -->
51 <!-- =========================================================================== -->
52
53 <property name="fileExtensions" value="java, properties, xml"/>
54
55 <!-- Checks that a package-info.java file exists for each package. -->
56 <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
57 <!-- <module name="JavadocPackage"/> -->
58
59 <!-- Checks whether files end with a new line. -->
60 <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
61 <module name="NewlineAtEndOfFile"/>
62
63 <!-- Checks that property files contain the same keys. -->
64 <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
65 <module name="Translation"/>
66
67 <!-- Checks for Size Violations. -->
68 <!-- See http://checkstyle.sf.net/config_sizes.html -->
69 <!-- Checks that no file is more than 1500 lines long. -->
70 <module name="FileLength">
71 <property name="max" value="1500"/>
72 </module>
73
74 <!-- Checks for whitespace -->
75 <!-- See http://checkstyle.sf.net/config_whitespace.html -->
76 <!-- Checks that no tab characters in the source code; report only first instance. -->
77 <module name="FileTabCharacter">
78 <property name="fileExtensions" value="java, toy, txt"/>
79 <property name="eachLine" value="false"/>
80 <message key="containsTab" value="Line contains a tab character. Configure your editor to replace tabs with spaces."/>
81 <message key="file.containsTab" value="File contains tab characters (this is the first occurrence). Configure your editor to replace tabs with spaces."/>
82 </module>
83
84 <!-- Miscellaneous other checks. -->
85 <!-- See http://checkstyle.sf.net/config_misc.html -->
86 <module name="RegexpSingleline">
87 <property name="format" value="\s+$"/>
88 <property name="minimum" value="0"/>
89 <property name="maximum" value="0"/>
90 <property name="message" value="Line has trailing spaces."/>
91 </module>
92
93 <!-- Checks for Headers -->
94 <!-- See http://checkstyle.sf.net/config_header.html -->
95 <!-- <module name="Header"> -->
96 <!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
97 <!-- <property name="fileExtensions" value="java"/> -->
98 <!-- </module> -->
99
100 <!-- =========================================================================== -->
101 <!-- =========================================================================== -->
102 <!-- CHECKS THAT REQUIRE WALKING THE PARSE TREE -->
103 <!-- =========================================================================== -->
104 <!-- =========================================================================== -->
105
106 <module name="TreeWalker">
107 <property name="tabWidth" value="4"/>
108
109 <!-- Checks for Javadoc comments. -->
110 <!-- See http://checkstyle.sf.net/config_javadoc.html-->
111 <module name="JavadocStyle"/>
112 <module name="NonEmptyAtclauseDescription"/>
113 <module name="AtclauseOrder"/>
114 <module name="JavadocType"/>
115 <module name="JavadocMethod"/>
116 <module name="JavadocVariable"/>
117 <module name="WriteTag"/>
118 <module name="SummaryJavadoc"/>
119 <module name="JavadocParagraph"/>
120 <module name="SingleLineJavadoc"/>
121
122 <!-- Checks for Naming Conventions. -->
123 <!-- See http://checkstyle.sf.net/config_naming.html -->
124 <!-- static final field -->
125 <module name="ConstantName">
126 <message key="name.invalidPattern" value="The constant ''{0}'' must be ALL_UPPERCASE, with words separated by underscores."/>
127 </module>
128 <!-- includes catch parameters -->
129 <module name="LocalFinalVariableName">
130 <property name="format" value="^([a-z][a-zA-Z0-9]*|[A-Z][A-Z_0-9]*)$"/>
131 <message key="name.invalidPattern" value="The local final variable ''{0}'' must start with a lowercase letter and use camelCase (or be ALL_UPPERCASE if it is a constant)."/>
132 </module>
133 <!-- local variables, allow camelCase or ALL_UPPERCASE of two or more characters -->
134 <module name="LocalVariableName">
135 <!-- <property name="format" value="^([a-z][a-zA-Z0-9]*|[A-Z][A-Z_0-9]+|G|[A-Z])$"/> -->
136 <property name="format" value="^([a-z][a-zA-Z0-9]*|[A-Z][A-Z_0-9]+|G)$"/>
137 <message key="name.invalidPattern" value="The local variable ''{0}'' must start with a lowercase letter and use camelCase."/>
138 </module>
139 <!-- instance variables must be camelCase or G -->
140 <module name="MemberName">
141 <property name="format" value="^([a-z][a-zA-Z0-9]*|G)$"/>
142 <message key="name.invalidPattern" value="The instance variable ''{0}'' must start with a lowercase letter and use camelCase."/>
143 </module>
144 <!-- method name -->
145 <!-- ^[a-z][a-zA-Z0-9]*$ -->
146 <module name="MethodName">
147 <message key="name.invalidPattern" value="The method ''{0}'' must start with a lowercase letter and use camelCase."/>
148 <message key="method.name.equals.class.name" value="The method name ''{0}'' must not be identical to the class name. Remove the return type if you intended to define a constructor instead of a method."/>
149 </module>
150 <module name="PackageName">
151 <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
152 <message key="name.invalidPattern" value="The package ''{0}'' must be lowercase, with package components separated by dots."/>
153 </module>
154 <!-- allows single letter uppercase parameter variable names in code -->
155 <module name="ParameterName">
156 <property name="format" value="^([a-z][a-zA-Z0-9]*|G|[A-Z])$"/>
157 <message key="name.invalidPattern" value="The parameter variable ''{0}'' must start with a lowercase letter and use camelCase."/>
158 </module>
159 <!-- static non-final field -->
160 <!-- ^[a-z][a-zA-Z0-9]*$ -->
161 <module name="StaticVariableName">
162 <message key="name.invalidPattern" value="The static variable ''{0}'' must start with a lowercase letter and use camelCase. If you intended ''{0}'' to be a constant, add the modifier ''final'' immediately after ''static'' and use ALL_UPPERCASE."/>
163 </module>
164 <!-- type name -->
165 <!-- ^[A-Z][a-zA-Z0-9]*$ -->
166 <module name="TypeName">
167 <message key="name.invalidPattern" value="The class ''{0}'' must start with an uppercase letter and use CamelCase."/>
168 </module>
169
170 <module name="ClassTypeParameterName">
171 <property name="format" value="^[A-Z][a-zA-Z0-9]*$"/>
172 <message key="name.invalidPattern" value="The type parameter ''{0}'' must either be a single uppercase letter or start with an uppercase letter and use CamelCase."/>
173 </module>
174
175 <module name="MethodTypeParameterName">
176 <property name="format" value="^[A-Z][a-zA-Z0-9]*$"/>
177 <message key="name.invalidPattern" value="The type parameter ''{0}'' must either be a single uppercase letter or start with an uppercase letter and use CamelCase."/>
178 </module>
179
180 <module name="InterfaceTypeParameterName">
181 <property name="format" value="^[A-Z][a-zA-Z0-9]*$"/>
182 <message key="name.invalidPattern" value="The type parameter ''{0}'' must either be a single uppercase letter or start with an uppercase letter and use CamelCase."/>
183 </module>
184
185 <!-- Checks for imports -->
186 <!-- See http://checkstyle.sf.net/config_import.html -->
187 <module name="AvoidStarImport">
188 <message key="import.avoidStar" value="Do not use .* in import statements."/>
189 </module>
190 <module name="AvoidStaticImport">
191 <message key="import.avoidStatic" value="Do not use static imports."/>
192 </module>
193 <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
194 <module name="RedundantImport">
195 <message key="import.same" value="Unnecessary import statement for ''{0}'' becaue it is in the same package as this class."/>
196 <message key="import.lang" value="Unnecessary import statement for ''{0}'' because it is from the package ''java.lang''."/>
197 <message key="import.duplicate" value="Duplicate import statement for ''{1}''."/>
198 </module>
199 <module name="UnusedImports">
200 <message key="import.unused" value="Unused import statement for ''{0}''."/>
201 </module>
202
203 <!-- =========================================================================== -->
204 <!-- Modifiers -->
205 <!-- http://checkstyle.sourceforge.net/config_modifier.html -->
206 <!-- =========================================================================== -->
207
208 <module name="ModifierOrder">
209 <message key = "mod.order" value = "The modifier ''{0}'' is out of order. The preferred order is [''public'', ''protected'', ''private'', ''abstract'', ''static'', ''final'', ''transient'', ''volatile'', ''synchronized'', ''native'', and ''strictfp'']."/>
210 </module>
211
212 <!-- removed CTOR_DEF for public constructors in private nested classes -->
213 <module name="RedundantModifier">
214 <property name="tokens" value="METHOD_DEF,VARIABLE_DEF,ANNOTATION_FIELD_DEF,
215 INTERFACE_DEF,CLASS_DEF,ENUM_DEF"/>
216 </module>
217
218 <!-- Checks for blocks. You know, those {}'s -->
219 <!-- See http://checkstyle.sf.net/config_blocks.html -->
220 <module name="AvoidNestedBlocks">
221 <message key="block.nested" value="Avoid nested blocks: the curly braces serve no purpose."/>
222 </module>
223 <module name="EmptyBlock"/>
224 <module name="LeftCurly"/>
225 <module name="NeedBraces">
226 <property name="tokens" value="LITERAL_DO"/>
227 </module>
228 <module name="RightCurly"/>
229
230 <!-- Checks for common coding problems -->
231 <!-- See http://checkstyle.sf.net/config_coding.html -->
232 <module name="CovariantEquals">
233 <message key="covariant.equals" value="The type of the parameter variable for the ''equals()'' method must be ''Object''."/>
234 </module>
235 <module name="AvoidInlineConditionals"/>
236 <module name="EmptyStatement">
237 <message key="empty.statement" value="Are you sure you want an empty statement here? An empty statement might indicate a superfluous semicolon."/>
238 </module>
239 <module name="EqualsHashCode"/>
240 <module name="HiddenField" >
241 <property name="ignoreSetter" value="true" />
242 <property name="ignoreConstructorParameter" value="true" />
243 </module>
244 <module name="ModifiedControlVariable">
245 <message key="modified.control.variable" value="Control variable ''{0}'' is modified inside loop."/>
246 </module>
247 <module name="IllegalInstantiation"/>
248 <module name="InnerAssignment"/>
249 <module name="MagicNumber">
250 <property name="tokens" value="NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG"/>
251 <property name="ignoreNumbers" value="-256, -128, -100, -64, -32, -16, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, -0.5, -0.25, 0, 0.25, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 32, 64, 100, 128, 256, 512, 1024, 32768"/>
252 <message key="magic.number" value="''{0}'' looks like a hard-coded value. This should be made a constant variable with a symbolic name (such as AVOGADROS_NUMBER)."/>
253 </module>
254 <module name="MissingSwitchDefault">
255 <message key="missing.switch.default" value="A switch statement must contain a ''default'' clause."/>
256 </module>
257 <module name="SimplifyBooleanExpression">
258 <message key="simplify.expression" value="Boolean expression can be simplified, e.g., use ''if (!isEmpty)'' instead of ''if (isEmpty == false)''."/>
259 </module>
260 <module name="SimplifyBooleanReturn">
261 <message key="simplify.boolreturn" value="Conditional logic can be removed in return statement, e.g., use ''return x >= 0'' instead of ''if (x >= 0) return true; else return false;''."/>
262 </module>
263 <module name="StringLiteralEquality">
264 <message key="string.literal.equality" value="Compare string literals using ''equals()'', not ''{0}''."/>
265 </module>
266
267 <module name="NestedForDepth">
268 <property name="max" value="4"/>
269 </module>
270 <module name="NestedIfDepth">
271 <property name="max" value="3"/>
272 </module>
273 <module name="NestedTryDepth">
274 <property name="max" value="1"/>
275 </module>
276 <module name="NoClone"/>
277 <module name="NoFinalizer"/>
278 <module name="SuperClone"/>
279 <module name="SuperFinalize"/>
280
281 <!-- Checks for class design -->
282 <!-- See http://checkstyle.sf.net/config_design.html -->
283 <!-- <module name="DesignForExtension"/> -->
284 <module name="DeclarationOrder">
285 <message key="declaration.order.constructor" value="Define constructors after static and instance variables but before methods."/>
286 <message key="declaration.order.method" value="Define methods after static variables, instance variables, and constructors."/>
287 <message key="declaration.order.instance" value="Declare instance variables after static variables but before constructors and methods."/>
288 <message key="declaration.order.access" value="Declare static and instance variables in order of their access modifiers: public, protected, package, and private."/>
289 <message key="declaration.order.static" value="Declare static variables before instance variables, constructors, and methods."/>
290 </module>
291 <!-- <module name="FinalClass"/>
292 <module name="HideUtilityClassConstructor"/> -->
293 <module name="InterfaceIsType">
294 <message key="interface.type" value="An interface must describe a type (and have methods)."/>
295 </module>
296 <module name="VisibilityModifier">
297 <property name="protectedAllowed" value="true"/>
298 </module>
299 <module name="OneTopLevelClass">
300 <message key="one.top.level.class" value="The .java file must have exactly one top-level class."/>
301 </module>
302
303
304
305 <!-- Miscellaneous other checks. -->
306 <!-- See http://checkstyle.sf.net/config_misc.html -->
307 <module name="ArrayTypeStyle">
308 <message key="array.type.style" value="To specify an array type, put the square brackets before the variable name, e.g., ''String[] args'' instead of ''String args[]''."/>
309 </module>
310 <module name="ParameterAssignment">
311 <message key="parameter.assignment" value="Changing the value of the parameter variable ''{0}'' suggests poor design. Instead, define a local variable."/>
312 </module>
313 <module name="TodoComment"/>
314 <module name="UpperEll">
315 <message key="upperEll" value="Use an uppercase ''L'' instead of a lowercase ''l'' to specify a literal of type long."/>
316 </module>
317
318 <module name="DescendantToken">
319 <property name="tokens" value="LITERAL_ASSERT"/>
320 <property name="limitedTokens" value="ASSIGN,DEC,INC,POST_DEC,
321 POST_INC,PLUS_ASSIGN,MINUS_ASSIGN,STAR_ASSIGN,DIV_ASSIGN,MOD_ASSIGN,
322 BSR_ASSIGN,SR_ASSIGN,SL_ASSIGN,BAND_ASSIGN,BXOR_ASSIGN,BOR_ASSIGN"/>
323 <property name="maximumNumber" value="0"/>
324 <property name="maximumMessage" value="Assert statements must not produce side effects."/>
325 </module>
326
327 <module name="DescendantToken">
328 <property name="tokens" value="EQUAL,NOT_EQUAL"/>
329 <property name="limitedTokens" value="LITERAL_THIS,LITERAL_NULL"/>
330 <property name="maximumNumber" value="1"/>
331 <property name="maximumDepth" value="1"/>
332 <property name="sumTokenCounts" value="true"/>
333 <property name="maximumMessage" value="Do not compare ''this'' with ''null''; it is never null."/>
334 </module>
335
336 <module name="DefaultComesLast"/>
337 <module name="FallThrough"/>
338
339 <module name="OneStatementPerLine">
340 <message key="multiple.statements.line" value="Do not put multiple statements on the same line."/>
341 </module>
342
343 <module name="IllegalToken">
344 <property name="tokens" value="LITERAL_FLOAT"/>
345 <message key="illegal.token" value="Use the primitive type ''double'' instead of the primitive type ''float''."/>
346 </module>
347
348 <!-- <module name="IllegalTokenText">
349 <property name="tokens" value="NUM_FLOAT"/>
350 <property name="format" value="^.*f$"/>
351 <message key="illegal.token.text" value="Use a ''double'' literal instead of a ''float'' literal."/>
352 </module> -->
353
354 <module name="IllegalTokenText">
355 <property name="tokens" value="NUM_FLOAT, NUM_DOUBLE"/>
356 <property name="format" value="^\..*"/>
357 <message key="illegal.token.text" value="Use at least one digit to the left of the decimal point. For example, use the literal ''0.5'' instead of ''.5''."/>
358 </module>
359
360 <module name="IllegalTokenText">
361 <property name="tokens" value="NUM_INT,NUM_LONG"/>
362 <property name="format" value="^0[^lxb]"/>
363 <property name="ignoreCase" value="true"/>
364 <message key="illegal.token.text" value="A leading 0 in an integer literal signifies that it is an octal (base-8) integer."/>
365 </module>
366
367 <module name="IllegalTokenText">
368 <property name="tokens" value="NUM_INT,NUM_LONG"/>
369 <property name="format" value="^2147483647L?$"/>
370 <message key="illegal.token.text" value="Use the named constant ''Integer.MAX_VALUE'' instead of ''2147483647''."/>
371 </module>
372
373 <module name="IllegalTokenText">
374 <property name="tokens" value="NUM_INT,NUM_LONG"/>
375 <property name="format" value="^2147483648L?$"/>
376 <message key="illegal.token.text" value="Use the named constant ''Integer.MIN_VALUE'' instead of ''-2147483648''."/>
377 </module>
378
379 <module name="IllegalTokenText">
380 <property name="tokens" value="NUM_LONG"/>
381 <property name="format" value="^9223372036854775807L$"/>
382 <message key="illegal.token.text" value="Use the named constant ''Long.MAX_VALUE'' instead of ''9223372036854775807L''."/>
383 </module>
384
385 <module name="IllegalTokenText">
386 <property name="tokens" value="NUM_LONG"/>
387 <property name="format" value="^9223372036854775808L$"/>
388 <message key="illegal.token.text" value="Use the named constant ''Long.MIN_VALUE'' instead of ''-9223372036854775808L''."/>
389 </module>
390
391 <!-- Checks that // and /* comments are followed by whitespace. -->
392 <module name="IllegalTokenText">
393 <property name="tokens" value="COMMENT_CONTENT"/>
394 <property name="format" value="^[\*/]*[A-Za-z0-9]"/>
395 <message key="illegal.token.text" value="''//'' or ''/*'' is not followed by whitespace."/>
396 </module>
397
398 <!-- Checks that comments are not empty. -->
399 <module name="IllegalTokenText">
400 <property name="tokens" value="COMMENT_CONTENT"/>
401 <property name="format" value="^\s*$"/>
402 <message key="illegal.token.text" value="The comment is empty."/>
403 </module>
404
405 <!-- Do not name a variable 'l'. -->
406 <module name="IllegalTokenText">
407 <property name="tokens" value="IDENT"/>
408 <property name="format" value="^l$"/>
409 <message key="illegal.token.text" value="Do not use the letter ''l'' as a variable name (or other identifier). It is hard to distinguish from the number ''1''."/>
410 </module>
411
412 <!-- Do not name a variable 'o'. -->
413 <module name="IllegalTokenText">
414 <property name="tokens" value="IDENT"/>
415 <property name="format" value="^[oO]$"/>
416 <message key="illegal.token.text" value="Do not use the letter ''o'' or ''O'' as a variable name (or other identifier). It is hard to distinguish from the number ''0''."/>
417 </module>
418
419 <!-- Do not name a variable 'one', 'two', 'three', and so forth -->
420 <module name="IllegalTokenText">
421 <property name="tokens" value="IDENT"/>
422 <property name="format" value="^(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)$"/>
423 <property name="ignoreCase" value="true"/>
424 <message key="illegal.token.text" value="Do not use the name of a number (such as ''ten'') as a variable name (or other identifier)."/>
425 </module>
426
427 <!-- =========================================================================== -->
428 <!-- Regexp -->
429 <!-- http://checkstyle.sourceforge.net/config_regexp.html -->
430 <!-- =========================================================================== -->
431
432
433 <!-- check for Math.pow(*, 3) and Math.pow(*, 0.5) -->
434 <module name="RegexpSinglelineJava">
435 <property name="format" value="\bMath\.pow\([^,]*, *3(\.0?)?\)"/>
436 <property name="ignoreComments" value="true"/>
437 <property name="message" value="''Math.pow(x, 3)'' is slow. Use ''x*x*x'' instead."/>
438 </module>
439
440 <module name="RegexpSinglelineJava">
441 <property name="format" value="\bMath\.pow\([^,]*, *0?\.5\)"/>
442 <property name="ignoreComments" value="true"/>
443 <property name="message" value="Use ''Math.sqrt(x)'' instead of ''Math.pow(x, 0.5)''."/>
444 </module>
445
446 <!-- Checks for Size Violations. -->
447 <!-- See http://checkstyle.sf.net/config_sizes.html -->
448 <module name="MethodLength">
449 <property name="tokens" value="METHOD_DEF"/>
450 <property name="max" value="60"/>
451 <property name="countEmpty" value="false"/>
452 </module>
453 <module name="ParameterNumber"/>
454
455 <module name="OuterTypeNumber">
456 <message key="maxOuterTypes" value="Your program defines {0,number,integer} outer types, but there should be only 1."/>
457 </module>
458
459 <module name="MethodCount"/>
460
461 <!-- Checks for whitespace -->
462 <!-- See http://checkstyle.sf.net/config_whitespace.html -->
463 <module name="EmptyForIteratorPad"/>
464 <module name="GenericWhitespace"/>
465 <module name="MethodParamPad"/>
466 <module name="NoWhitespaceAfter"/>
467 <module name="NoWhitespaceBefore"/>
468 <module name="OperatorWrap"/>
469 <module name="ParenPad"/>
470 <module name="TypecastParenPad"/>
471 <module name="WhitespaceAfter">
472 <message key="ws.typeCast" value="Typecast is not followed by whitespace."/>
473 </module>
474 <module name="WhitespaceAround"/>
475
476 </module>
477
478 <module name="LineLength">
479 <property name="max" value="125"/>
480 <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
481 </module>
482</module>