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 Allow suppression of rules by comments, e.g.:
20 // CHECKSTYLE.OFF: ParameterNumber
22 // CHECKSTYLE.ON: ParameterNumber
24 <module name="SuppressionCommentFilter">
25 <property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
26 <property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
27 <property name="checkFormat" value="$1"/>
31 Maximum line count for source files
33 <module name="FileLength">
34 <property name="max" value="1200"/>
35 <property name="fileExtensions" value="java"/>
39 Check language bundles have the same keys and no duplicates
40 (ensure Checkstyle is configured to scan non-source files)
42 <module name="Translation">
43 <property name="fileExtensions" value="properties"/>
44 <property name="baseName" value="^Messages.*$"/>
46 <module name="UniqueProperties">
47 <property name="fileExtensions" value="properties" />
48 <property name="severity" value="error"/>
51 <module name="TreeWalker">
53 <property name="tabWidth" value="4"/>
56 Enables parsing of suppressions comments
57 see http://checkstyle.sourceforge.net/config_filters.html#SuppressionCommentFilter
59 <module name="FileContentsHolder"/>
61 <!-- ****************************** -->
62 <!-- NAMING STANDARDS -->
63 <!-- ****************************** -->
66 Naming convention for member fields. Start with (optional) underscore, then
67 lower case, then camel case; no internal underscores
69 <module name="MemberName">
70 <property name="format" value="^_?[a-z][a-zA-Z0-9]*$"/>
74 Naming convention for methods. Start with (optional) underscore, then
75 lower case, then camel case; no internal underscores
77 <module name="MethodName">
78 <property name="format" value="^_?[a-z]([a-zA-Z0-9]+)*$"/>
82 Name pattern for local final variables.
84 <module name="LocalFinalVariableName">
85 <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
89 Name pattern for local variables
91 <module name="LocalVariableName">
92 <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
96 Name pattern for constants (static final fields)
98 <module name="ConstantName">
99 <property name="format" value="^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
103 Name pattern for parameters (note no underscores allowed)
105 <module name="ParameterName">
106 <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
110 Name pattern for static (non-final) fields
112 <module name="StaticVariableName">
113 <property name="format" value="^[a-z][a-zA-Z0-9_]*$"/>
117 Name pattern for classes
119 <module name="TypeName">
120 <property name="format" value="[A-Z][a-zA-Z0-9]*$"/>
121 <property name="tokens" value="CLASS_DEF"/>
125 Name pattern for interfaces. All interfaces names must end with 'I'.
126 ** currently suppressed in checkstyle-suppress.xml **
128 <module name="TypeName">
129 <property name="id" value="InterfaceNaming"/>
130 <property name="format" value="^[A-Z][a-zA-Z0-9]*I$"/>
131 <property name="tokens" value="INTERFACE_DEF"/>
132 <message key="name.invalidPattern" value="Interface names should end in a I"/>
136 Java package name pattern
138 <module name="PackageName">
139 <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
142 <!-- ****************************** -->
143 <!-- LAYOUT AND STYLE -->
144 <!-- ****************************** -->
147 Only one top level type per source file
149 <module name="OuterTypeNumber"/>
152 Ensure a class has a package declaration
154 <module name="PackageDeclaration"/>
157 see http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141855.html#1852
158 1. Class (static) variables: public, protected, package, private
159 2. Instance variables: public, protected, package, private
163 <module name="DeclarationOrder"/>
166 Modifier order should conform to JLS
167 see http://checkstyle.sourceforge.net/config_modifier.html#ModifierOrder
168 public protected private abstract static final transient volatile synchronized native strictfp
170 <module name="ModifierOrder"/>
173 Declare variables in separate statements, for readability and bug avoidance
175 <module name="MultipleVariableDeclarations"/>
178 Don't have more than one statement on a line
179 (code formatting on save may enforce this anyway)
181 <module name="OneStatementPerLine"/>
184 Declare variables close to their point of first use
185 (doesn't handle variables used inside loops very well)
187 <module name="VariableDeclarationUsageDistance">
188 <property name="allowedDistance" value="5" />
189 <message key="variable.declaration.usage.distance.extend"
190 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." />
194 Only use blocks within control statements
196 <module name="AvoidNestedBlocks" />
199 Require at least a comment within a block.
200 Note this will accept auto-generated // TODO comments,
201 (but they should be flagged up by the TodoComment rule)
203 <module name="EmptyBlock">
204 <property name="option" value="text"/>
208 Require braces round all code blocks within if/else/for/do/while
210 <module name="NeedBraces"/>
213 Disallow empty ';' statements
215 <module name="EmptyStatement"/>
218 Maximum number of return statements for a method
220 <module name="ReturnCount">
221 <property name="max" value="4"/>
225 Don't use modifiers in contexts where their value is not optional,
226 for example all interface methods are always public
227 see http://checkstyle.sourceforge.net/config_modifier.html#RedundantModifier
229 <module name="RedundantModifier"/>
232 Variables whose value is not modified should be declared final, both to show the
233 program's intent, and to allow compiler optimisation
234 ** currently suppressed in checkstyle-suppress.xml **
236 <module name="FinalLocalVariable">
237 <property name="tokens" value="VARIABLE_DEF" />
241 Disallows shorthand of assigning values within an expression
243 <module name="InnerAssignment"/>
246 Use Java style array declarations to assist in readability
248 <module name="ArrayTypeStyle"/>
251 Use L not l to define a long constant
253 <module name="UpperEll"/>
255 <!-- ****************************** -->
257 <!-- ****************************** -->
260 Maximum line count for methods
262 <module name="MethodLength">
263 <property name="tokens" value="METHOD_DEF"/>
264 <property name="max" value="50"/>
265 <property name="countEmpty" value="false"/>
269 Maximum statement count for methods, constructors,
270 instance initialisation and static initialisation blocks
272 <module name="ExecutableStatementCount">
273 <property name="max" value="30"/>
274 <property name="tokens" value="METHOD_DEF"/>
276 <module name="ExecutableStatementCount">
277 <property name="max" value="30"/>
278 <property name="tokens" value="CTOR_DEF"/>
280 <module name="ExecutableStatementCount">
281 <property name="max" value="4"/>
282 <property name="tokens" value="INSTANCE_INIT"/>
284 <module name="ExecutableStatementCount">
285 <property name="id" value="NoStaticInitialization"/>
286 <property name="max" value="0"/>
287 <property name="tokens" value="STATIC_INIT"/>
291 Maximum parameter count for methods
293 <module name="ParameterNumber">
294 <property name="max" value="5"/>
298 Maximum line length for anonymous inner classes
300 <module name="AnonInnerLength">
301 <property name="max" value="40"/>
304 <!-- ****************************** -->
306 <!-- ****************************** -->
309 Ensures that there are no redundant or unused imports.
310 Should be handled by Save actions if using Eclipse
312 <module name="RedundantImport"/>
313 <module name="UnusedImports"/>
316 Disallow * imports; may also be enforced by IDE Save Actions
318 <module name="AvoidStarImport"/>
321 Disallow import of sun.* packages as they are not portable
323 <module name="IllegalImport"/>
326 rules as to what packages each package may (not) import
327 see http://checkstyle.sourceforge.net/config_imports.html#ImportControl
329 <module name="ImportControl">
330 <property name="file" value="${basedir}/utils/checkstyle/import-control.xml"/>
331 <property name="severity" value="error"/>
334 <!-- ****************************** -->
335 <!-- CATCH and THROW -->
336 <!-- ****************************** -->
339 Disallow catch of Exception, RunTimeException or Error
341 <module name="IllegalCatch"/>
344 Disallow throw of Exception, RunTimeException or Error
346 <module name="IllegalThrows"/>
348 <!-- ****************************** -->
349 <!-- CODING CHECKS -->
350 <!-- ****************************** -->
353 Check for use of factory method rather than constructor for specified classes
354 e.g. Boolean.valueOf(true) rather than new Boolean(true)
356 <module name="IllegalInstantiation">
357 <property name="classes" value="java.lang.Boolean"/>
361 Check that "string".equals(value) is used rather than value.equals("string")
363 <module name="EqualsAvoidNull"/>
366 Check that equals() and hashCode() are always overridden together
368 <module name="EqualsHashCode"/>
371 Require switch statements to include a default
373 <module name="MissingSwitchDefault"/>
376 Check that switch default follows all case statements
378 <module name="DefaultComesLast">
379 <property name="severity" value="error"/>
383 Disallows fall-through in switch statements
384 i.e. a case without a break, return, throw or continue
385 NB a comment with the words "fall[s] through" suppresses this message
387 <module name="FallThrough">
388 <property name="severity" value="error" />
392 Warn if boolean expressions can be simplified
394 <module name="SimplifyBooleanExpression"/>
397 Warn if boolean return expressions can be simplified
399 <module name="SimplifyBooleanReturn"/>
402 Classes with only private constructors should be declared final
404 <module name="FinalClass"/>
407 Classes with only static methods should not be instantiable,
408 so should declare a private default constructor.
410 <module name="HideUtilityClassConstructor"/>
413 An Interface should declare methods (do not use to define constants only)
415 <module name="InterfaceIsType"/>
418 Disallow public fields in classes (other than constants)
420 <module name="VisibilityModifier">
421 <property name="packageAllowed" value="true"/>
422 <property name="allowPublicImmutableFields" value="true"/>
426 Checks that a local variable or a parameter does not shadow a field that is defined in the same class.
427 Note this should also be configured as a compiler warning in the IDE.
429 <module name="HiddenField"/>
432 Check that proper logging is used and never printing to System.out.
433 This may be suppressed in the class that provides logging functions.
435 <module name="RegexpSinglelineJava">
436 <property name="format" value="System\.out\.println"/>
437 <property name="ignoreComments" value="true"/>
441 Checks that classes that define a covariant equals() method also override
442 method equals(java.lang.Object).
444 <module name="CovariantEquals"/>
447 Checks that there are no "magic numbers" (numeric literals)
449 <module name="MagicNumber">
450 <property name="ignoreNumbers" value="-1,0,1,2"/>
454 Check that loop control variables are not modified inside the for block
456 <module name="ModifiedControlVariable">
460 Checks that string literals are not used with == or !=.
462 <module name="StringLiteralEquality">
466 Don't override clone - it never works!
468 <module name="NoClone"/>
471 Checks that clone() invokes super.clone()
472 (for classes that break the NoClone rule)
474 <module name="SuperClone"/>
477 Checks that finalize() invokes super.finalize()
479 <module name="SuperFinalize"/>
482 Disallow assignment of parameters.
484 <module name="ParameterAssignment"/>
487 Checks for multiple occurrences of the same string literal within a single file.
488 NB - does not check for the same string in different files.
490 <module name="MultipleStringLiterals">
491 <property name="allowedDuplicates" value="1"/>
495 Checks that exceptions are immutable (have only final fields)
497 <module name="MutableException"/>
500 A general rule to check for source text tokens that shouldn't be there
501 see http://checkstyle.sourceforge.net/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html
503 <module name="IllegalToken">
504 <property name="tokens" value="LITERAL_ASSERT"/>
507 <!-- ****************************** -->
509 <!-- ****************************** -->
512 Restrict the number of number of &&, ||, &, | and ^ in an expression.
513 Note that the operators & and | are not only integer bitwise operators, they are also the
514 non-shortcut versions of the boolean operators && and ||.
516 <module name="BooleanExpressionComplexity">
517 <property name="max" value="3"/>
521 This metric measures the number of instantiations of other classes within the given class.
522 The higher the DAC, the more complex the data structure of the system.
524 <module name="ClassDataAbstractionCoupling">
525 <property name="max" value="7"/>
529 The number of other classes a class relies on. A high number indicates over-complex
530 class interdependencies that might benefit from refactoring.
532 <module name="ClassFanOutComplexity">
533 <property name="max" value="10"/>
537 Checks cyclomatic complexity against a specified limit. The complexity is a measure
538 of the minimum number of possible paths through the source and therefore the number of required
539 tests. Consider re-factoring if at or above 10.
541 <module name="CyclomaticComplexity">
542 <property name="max" value="15"/>
546 The NPATH metric computes the number of possible execution paths through a function. It takes
547 into account the nesting of conditional statements and multi-part boolean expressions
548 (e.g., A && B, C || D, etc.).
550 <module name="NPathComplexity">
551 <property name="max" value="200"/>
555 Maximum number of throws statements in a method
557 <module name="ThrowsCount">
558 <property name="max" value="2"/>
562 Maximum if-else depth
564 <module name="NestedIfDepth">
565 <property name="max" value="4"/>
569 Restricts nested try blocks to a specified depth.
571 <module name="NestedTryDepth">
572 <property name="max" value="2"/>
575 <!-- ****************************** -->
577 <!-- ****************************** -->
580 Checks for uncommented main() methods (debugging leftovers)
582 <module name="UncommentedMain"/>
585 Check for TODO and similar comments
587 <module name="TodoComment">
588 <property name="format" value="(TODO)|(FIXME)|(DOCUMENT ME)"/>