1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
4 Jalview Checkstyle configuration file
6 <module name="Checker">
7 <!-- Default severity is warning -->
8 <property name="severity" value="warning"/>
9 <property name="fileExtensions" value="java,properties"/>
12 Add any metrics that you wish to suppress to the following file.
14 <module name="SuppressionFilter">
15 <property name="file" value="${basedir}/utils/checkstyle/checkstyle-suppress.xml"/>
19 Check language bundles have the same keys and no duplicates
20 (ensure Checkstyle is configured to scan non-source files)
22 <module name="Translation">
23 <property name="fileExtensions" value="properties"/>
24 <property name="baseName" value="^Messages.*$"/>
26 <module name="UniqueProperties">
27 <property name="fileExtensions" value="properties" />
28 <property name="severity" value="error"/>
32 Maximum line count for source files
33 (note this can't be inside TreeWalker)
35 <module name="FileLength">
36 <property name="max" value="1200"/>
37 <property name="fileExtensions" value="java"/>
40 <module name="TreeWalker">
42 <property name="tabWidth" value="4"/>
45 Allow suppression of rules by comments, e.g.:
46 // CHECKSTYLE.OFF: ParameterNumber
48 // CHECKSTYLE.ON: ParameterNumber
50 <module name="SuppressionCommentFilter">
51 <property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
52 <property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
53 <property name="checkFormat" value="$1"/>
56 <!-- ****************************** -->
57 <!-- NAMING STANDARDS -->
58 <!-- ****************************** -->
61 Naming convention for member fields. Start with (optional) underscore, then
62 lower case, then camel case; no internal underscores
64 <module name="MemberName">
65 <property name="format" value="^_?[a-z][a-zA-Z0-9]*$"/>
69 Naming convention for methods. Start with (optional) underscore, then
70 lower case, then camel case; no internal underscores
72 <module name="MethodName">
73 <property name="format" value="^_?[a-z]([a-zA-Z0-9]+)*$"/>
77 Name pattern for local final variables.
79 <module name="LocalFinalVariableName">
80 <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
84 Name pattern for local variables
86 <module name="LocalVariableName">
87 <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
91 Name pattern for constants (static final fields)
93 <module name="ConstantName">
94 <property name="format" value="^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
98 Name pattern for parameters (note no underscores allowed)
100 <module name="ParameterName">
101 <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
105 Name pattern for static (non-final) fields
107 <module name="StaticVariableName">
108 <property name="format" value="^[a-z][a-zA-Z0-9_]*$"/>
112 Name pattern for classes
114 <module name="TypeName">
115 <property name="format" value="[A-Z][a-zA-Z0-9]*$"/>
116 <property name="tokens" value="CLASS_DEF"/>
120 Name pattern for interfaces. All interfaces names must end with 'I'.
121 ** currently suppressed in checkstyle-suppress.xml **
123 <module name="TypeName">
124 <property name="id" value="InterfaceNaming"/>
125 <property name="format" value="^[A-Z][a-zA-Z0-9]*I$"/>
126 <property name="tokens" value="INTERFACE_DEF"/>
127 <message key="name.invalidPattern" value="Interface names should end in a I"/>
131 Java package name pattern
133 <module name="PackageName">
134 <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
137 <!-- ****************************** -->
138 <!-- LAYOUT AND STYLE -->
139 <!-- ****************************** -->
142 Only one top level type per source file
144 <module name="OuterTypeNumber"/>
147 Ensure a class has a package declaration
149 <module name="PackageDeclaration"/>
152 see http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141855.html#1852
153 1. Class (static) variables: public, protected, package, private
154 2. Instance variables: public, protected, package, private
158 <module name="DeclarationOrder"/>
161 Modifier order should conform to JLS
162 see http://checkstyle.sourceforge.net/config_modifier.html#ModifierOrder
163 public protected private abstract static final transient volatile synchronized native strictfp
165 <module name="ModifierOrder"/>
168 Declare variables in separate statements, for readability and bug avoidance
170 <module name="MultipleVariableDeclarations"/>
173 Don't have more than one statement on a line
174 (code formatting on save may enforce this anyway)
176 <module name="OneStatementPerLine"/>
179 Declare variables close to their point of first use
180 (doesn't handle variables used inside loops very well)
182 <module name="VariableDeclarationUsageDistance">
183 <property name="allowedDistance" value="5" />
184 <message key="variable.declaration.usage.distance.extend"
185 value="Distance between declaration of ''{0}'' and its first use is {1}, suggested maximum is {2}. Consider moving, or make final if it may not be modified." />
189 Only use blocks within control statements
191 <module name="AvoidNestedBlocks" />
194 Require at least a comment within a block.
195 Note this will accept auto-generated // TODO comments,
196 (but they should be flagged up by the TodoComment rule)
198 <module name="EmptyBlock">
199 <property name="option" value="text"/>
203 Require braces round all code blocks within if/else/for/do/while
205 <module name="NeedBraces"/>
208 Disallow empty ';' statements
210 <module name="EmptyStatement"/>
213 Maximum number of return statements for a method
215 <module name="ReturnCount">
216 <property name="max" value="4"/>
220 Don't use modifiers in contexts where their value is not optional,
221 for example all interface methods are always public
222 see http://checkstyle.sourceforge.net/config_modifier.html#RedundantModifier
224 <module name="RedundantModifier"/>
227 Variables whose value is not modified should be declared final, both to show the
228 program's intent, and to allow compiler optimisation
229 ** currently suppressed in checkstyle-suppress.xml **
231 <module name="FinalLocalVariable">
232 <property name="tokens" value="VARIABLE_DEF" />
236 Disallows shorthand of assigning values within an expression
238 <module name="InnerAssignment"/>
241 Use Java style array declarations to assist in readability
243 <module name="ArrayTypeStyle"/>
246 Use L not l to define a long constant
248 <module name="UpperEll"/>
250 <!-- ****************************** -->
252 <!-- ****************************** -->
255 Maximum line count for methods
257 <module name="MethodLength">
258 <property name="tokens" value="METHOD_DEF"/>
259 <property name="max" value="50"/>
260 <property name="countEmpty" value="false"/>
264 Maximum statement count for methods, constructors,
265 instance initialisation and static initialisation blocks
267 <module name="ExecutableStatementCount">
268 <property name="max" value="30"/>
269 <property name="tokens" value="METHOD_DEF"/>
271 <module name="ExecutableStatementCount">
272 <property name="max" value="30"/>
273 <property name="tokens" value="CTOR_DEF"/>
275 <module name="ExecutableStatementCount">
276 <property name="max" value="4"/>
277 <property name="tokens" value="INSTANCE_INIT"/>
279 <module name="ExecutableStatementCount">
280 <property name="id" value="NoStaticInitialization"/>
281 <property name="max" value="0"/>
282 <property name="tokens" value="STATIC_INIT"/>
286 Maximum parameter count for methods
288 <module name="ParameterNumber">
289 <property name="max" value="5"/>
293 Maximum line length for anonymous inner classes
295 <module name="AnonInnerLength">
296 <property name="max" value="40"/>
299 <!-- ****************************** -->
301 <!-- ****************************** -->
304 Ensures that there are no redundant or unused imports.
305 Should be handled by Save actions if using Eclipse
307 <module name="RedundantImport"/>
308 <module name="UnusedImports"/>
311 Disallow * imports; may also be enforced by IDE Save Actions
313 <module name="AvoidStarImport"/>
316 Disallow import of sun.* packages as they are not portable
318 <module name="IllegalImport"/>
321 rules as to what packages each package may (not) import
322 see http://checkstyle.sourceforge.net/config_imports.html#ImportControl
324 <module name="ImportControl">
325 <property name="file" value="${basedir}/utils/checkstyle/import-control.xml"/>
326 <property name="severity" value="error"/>
329 <!-- ****************************** -->
330 <!-- CATCH and THROW -->
331 <!-- ****************************** -->
334 Disallow catch of Exception, RunTimeException or Error
336 <module name="IllegalCatch"/>
339 Disallow throw of Exception, RunTimeException or Error
341 <module name="IllegalThrows"/>
343 <!-- ****************************** -->
344 <!-- CODING CHECKS -->
345 <!-- ****************************** -->
348 Check for use of factory method rather than constructor for specified classes
349 e.g. Boolean.valueOf(true) rather than new Boolean(true)
351 <module name="IllegalInstantiation">
352 <property name="classes" value="java.lang.Boolean"/>
356 Check that "string".equals(value) is used rather than value.equals("string")
358 <module name="EqualsAvoidNull"/>
361 Check that equals() and hashCode() are always overridden together
363 <module name="EqualsHashCode"/>
366 Require switch statements to include a default
368 <module name="MissingSwitchDefault"/>
371 Check that switch default follows all case statements
373 <module name="DefaultComesLast">
374 <property name="severity" value="error"/>
378 Disallows fall-through in switch statements
379 i.e. a case without a break, return, throw or continue
380 NB a comment with the words "fall[s] through" suppresses this message
382 <module name="FallThrough">
383 <property name="severity" value="error" />
387 Warn if boolean expressions can be simplified
389 <module name="SimplifyBooleanExpression"/>
392 Warn if boolean return expressions can be simplified
394 <module name="SimplifyBooleanReturn"/>
397 Classes with only private constructors should be declared final
399 <module name="FinalClass"/>
402 Classes with only static methods should not be instantiable,
403 so should declare a private default constructor.
405 <module name="HideUtilityClassConstructor"/>
408 An Interface should declare methods (do not use to define constants only)
410 <module name="InterfaceIsType"/>
413 Disallow public fields in classes (other than constants)
415 <module name="VisibilityModifier">
416 <property name="packageAllowed" value="true"/>
417 <property name="allowPublicImmutableFields" value="true"/>
421 Checks that a local variable or a parameter does not shadow a field that is defined in the same class.
422 Note this should also be configured as a compiler warning in the IDE.
424 <module name="HiddenField"/>
427 Check that proper logging is used.
428 This may be suppressed in the class that provides logging functions.
430 <module name="RegexpSinglelineJava">
431 <property name="id" value="NoSysout" />
432 <property name="format" value="System\.out\.println"/>
433 <property name="ignoreComments" value="true"/>
434 <message key="regexp.exceeded" value="Should use jalview.bin.Cache.log for logging"/>
436 <module name="RegexpSinglelineJava">
437 <property name="id" value="NoSyserr" />
438 <property name="format" value="System\.err\.println"/>
439 <property name="ignoreComments" value="true"/>
440 <message key="regexp.exceeded" value="Should use jalview.bin.Cache.log for logging"/>
444 Checks that classes that define a covariant equals() method also override
445 method equals(java.lang.Object).
447 <module name="CovariantEquals"/>
450 Checks that there are no "magic numbers" (numeric literals)
452 <module name="MagicNumber">
453 <property name="ignoreNumbers" value="-1,0,1,2"/>
457 Check that loop control variables are not modified inside the for block
459 <module name="ModifiedControlVariable">
463 Checks that string literals are not used with == or !=.
465 <module name="StringLiteralEquality">
469 Don't override clone - it never works!
471 <module name="NoClone"/>
474 Checks that clone() invokes super.clone()
475 (for classes that break the NoClone rule)
477 <module name="SuperClone"/>
480 Checks that finalize() invokes super.finalize()
482 <module name="SuperFinalize"/>
485 Disallow assignment of parameters.
487 <module name="ParameterAssignment"/>
490 Checks for multiple occurrences of the same string literal within a single file.
491 NB - does not check for the same string in different files.
493 <module name="MultipleStringLiterals">
494 <property name="allowedDuplicates" value="1"/>
498 Checks that exceptions are immutable (have only final fields)
500 <module name="MutableException"/>
503 A general rule to check for source text tokens that shouldn't be there
504 see http://checkstyle.sourceforge.net/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html
506 <module name="IllegalToken">
507 <property name="tokens" value="LITERAL_ASSERT"/>
510 <!-- ****************************** -->
512 <!-- ****************************** -->
515 Restrict the number of number of &&, ||, &, | and ^ in an expression.
516 Note that the operators & and | are not only integer bitwise operators, they are also the
517 non-shortcut versions of the boolean operators && and ||.
519 <module name="BooleanExpressionComplexity">
520 <property name="max" value="3"/>
524 This metric measures the number of instantiations of other classes within the given class.
525 The higher the DAC, the more complex the data structure of the system.
527 <module name="ClassDataAbstractionCoupling">
528 <property name="max" value="7"/>
532 The number of other classes a class relies on. A high number indicates over-complex
533 class interdependencies that might benefit from refactoring.
535 <module name="ClassFanOutComplexity">
536 <property name="max" value="10"/>
540 Checks cyclomatic complexity against a specified limit. The complexity is a measure
541 of the minimum number of possible paths through the source and therefore the number of required
542 tests. Consider re-factoring if at or above 10.
544 <module name="CyclomaticComplexity">
545 <property name="max" value="15"/>
549 The NPATH metric computes the number of possible execution paths through a function. It takes
550 into account the nesting of conditional statements and multi-part boolean expressions
551 (e.g., A && B, C || D, etc.).
553 <module name="NPathComplexity">
554 <property name="max" value="200"/>
558 Maximum number of throws statements in a method
560 <module name="ThrowsCount">
561 <property name="max" value="2"/>
565 Maximum if-else depth
567 <module name="NestedIfDepth">
568 <property name="max" value="4"/>
572 Restricts nested try blocks to a specified depth.
574 <module name="NestedTryDepth">
575 <property name="max" value="2"/>
578 <!-- ****************************** -->
580 <!-- ****************************** -->
583 Checks for uncommented main() methods (debugging leftovers)
585 <module name="UncommentedMain"/>
588 Check for TODO and similar comments
590 <module name="TodoComment">
591 <property name="format" value="(TODO)|(FIXME)"/>
592 <message key="todo.match" value="TODO or FIXME comment"/>
595 <module name="TodoComment">
596 <property name="format" value="DOCUMENT ME"/>
597 <message key="todo.match" value="Documentation incomplete"/>