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}/resources/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 Only use blocks within control statements
180 <module name="AvoidNestedBlocks"/>
183 Require at least a comment within a block.
184 Note this will accept auto-generated // TODO comments,
185 (but they should be flagged up by the TodoComment rule)
187 <module name="EmptyBlock">
188 <property name="option" value="text"/>
192 Require braces round all code blocks within if/else/for/do/while
194 <module name="NeedBraces"/>
197 Disallow empty ';' statements
199 <module name="EmptyStatement"/>
202 Maximum number of return statements for a method
204 <module name="ReturnCount">
205 <property name="max" value="4"/>
209 Don't use modifiers in contexts where their value is not optional,
210 for example all interface methods are always public
211 see http://checkstyle.sourceforge.net/config_modifier.html#RedundantModifier
213 <module name="RedundantModifier"/>
216 Variables whose value is not modified should be declared final, both to show the
217 program's intent, and to allow compiler optimisation
218 ** currently suppressed in checkstyle-suppress.xml **
220 <module name="FinalLocalVariable">
221 <property name="tokens" value="VARIABLE_DEF" />
225 Disallows shorthand of assigning values within an expression
227 <module name="InnerAssignment"/>
230 Use Java style array declarations to assist in readability
232 <module name="ArrayTypeStyle"/>
235 Use L not l to define a long constant
237 <module name="UpperEll"/>
239 <!-- ****************************** -->
241 <!-- ****************************** -->
244 Maximum line count for methods
246 <module name="MethodLength">
247 <property name="tokens" value="METHOD_DEF"/>
248 <property name="max" value="50"/>
249 <property name="countEmpty" value="false"/>
253 Maximum statement count for methods, constructors,
254 instance initialisation and static initialisation blocks
256 <module name="ExecutableStatementCount">
257 <property name="max" value="30"/>
258 <property name="tokens" value="METHOD_DEF"/>
260 <module name="ExecutableStatementCount">
261 <property name="max" value="30"/>
262 <property name="tokens" value="CTOR_DEF"/>
264 <module name="ExecutableStatementCount">
265 <property name="max" value="4"/>
266 <property name="tokens" value="INSTANCE_INIT"/>
268 <module name="ExecutableStatementCount">
269 <property name="id" value="NoStaticInitialization"/>
270 <property name="max" value="0"/>
271 <property name="tokens" value="STATIC_INIT"/>
275 Maximum parameter count for methods
277 <module name="ParameterNumber">
278 <property name="max" value="5"/>
282 Maximum line length for anonymous inner classes
284 <module name="AnonInnerLength">
285 <property name="max" value="40"/>
288 <!-- ****************************** -->
290 <!-- ****************************** -->
293 Ensures that there are no redundant or unused imports.
294 Should be handled by Save actions if using Eclipse
296 <module name="RedundantImport"/>
297 <module name="UnusedImports"/>
300 Disallow * imports; may also be enforced by IDE Save Actions
302 <module name="AvoidStarImport"/>
305 Disallow import of sun.* packages as they are not portable
307 <module name="IllegalImport"/>
310 rules as to what packages each package may (not) import
311 see http://checkstyle.sourceforge.net/config_imports.html#ImportControl
313 <module name="ImportControl">
314 <property name="file" value="${basedir}/resources/checkstyle/import-control.xml"/>
315 <property name="severity" value="error"/>
318 <!-- ****************************** -->
319 <!-- CATCH and THROW -->
320 <!-- ****************************** -->
323 Disallow catch of Exception, RunTimeException or Error
325 <module name="IllegalCatch"/>
328 Disallow throw of Exception, RunTimeException or Error
330 <module name="IllegalThrows"/>
332 <!-- ****************************** -->
333 <!-- CODING CHECKS -->
334 <!-- ****************************** -->
337 Check for use of factory method rather than constructor for specified classes
339 <module name="IllegalInstantiation">
340 <property name="classes" value="java.lang.Boolean"/>
344 Check that "string".equals(value) is used rather than value.equals("string")
346 <module name="EqualsAvoidNull"/>
349 Check that equals() and hashCode() are always overridden together
351 <module name="EqualsHashCode"/>
354 Require switch statements to include a default
356 <module name="MissingSwitchDefault"/>
359 Check that switch default follows all case statements
361 <module name="DefaultComesLast">
362 <property name="severity" value="error"/>
366 Disallows fall-through in switch statements i.e. a case without a break, return, throw or continue
367 upgrade this to error once AnnotationRenderer is recoded!
369 <module name="FallThrough">
370 <property name="severity" value="warning"/>
374 Warn if boolean expressions can be simplified
376 <module name="SimplifyBooleanExpression"/>
379 Warn if boolean return expressions can be simplified
381 <module name="SimplifyBooleanReturn"/>
384 Classes with only private constructors should be declared final
386 <module name="FinalClass"/>
389 Classes with only static methods should not be instantiable,
390 so should declare a private default constructor.
392 <module name="HideUtilityClassConstructor"/>
395 An Interface should declare methods (do not use to define constants only)
397 <module name="InterfaceIsType"/>
400 Disallow public fields in classes (other than constants)
402 <module name="VisibilityModifier">
403 <property name="packageAllowed" value="true"/>
404 <property name="allowPublicImmutableFields" value="true"/>
408 Checks that a local variable or a parameter does not shadow a field that is defined in the same class.
409 Note this should also be configured as a compiler warning in the IDE.
411 <module name="HiddenField"/>
414 Check that proper logging is used and never printing to System.out.
415 This may be suppressed in the class that provides logging functions.
417 <module name="RegexpSinglelineJava">
418 <property name="format" value="System\.out\.println"/>
419 <property name="ignoreComments" value="true"/>
423 Checks that classes that define a covariant equals() method also override
424 method equals(java.lang.Object).
426 <module name="CovariantEquals"/>
429 Checks that there are no "magic numbers" (numeric literals)
431 <module name="MagicNumber">
432 <property name="ignoreNumbers" value="-1,0,1,2"/>
436 Check that loop control variables are not modified inside the for block
438 <module name="ModifiedControlVariable">
442 Checks that string literals are not used with == or !=.
444 <module name="StringLiteralEquality">
448 Checks that clone() invokes super.clone()
450 <module name="SuperClone"/>
453 Checks that finalize() invokes super.finalize()
455 <module name="SuperFinalize"/>
458 Disallow assignment of parameters.
460 <module name="ParameterAssignment"/>
463 Checks for multiple occurrences of the same string literal within a single file.
464 NB - does not check for the same string in different files.
466 <module name="MultipleStringLiterals">
467 <property name="allowedDuplicates" value="1"/>
471 Checks that exceptions are immutable (have only final fields)
473 <module name="MutableException"/>
475 <!-- ****************************** -->
477 <!-- ****************************** -->
480 Restrict the number of number of &&, ||, &, | and ^ in an expression.
481 Note that the operators & and | are not only integer bitwise operators, they are also the
482 non-shortcut versions of the boolean operators && and ||.
484 <module name="BooleanExpressionComplexity">
485 <property name="max" value="3"/>
489 This metric measures the number of instantiations of other classes within the given class.
490 The higher the DAC, the more complex the data structure of the system.
492 <module name="ClassDataAbstractionCoupling">
493 <property name="max" value="7"/>
497 The number of other classes a class relies on. A high number indicates over-complex
498 class interdependencies that might benefit from refactoring.
500 <module name="ClassFanOutComplexity">
501 <property name="max" value="10"/>
505 Checks cyclomatic complexity against a specified limit. The complexity is a measure
506 of the minimum number of possible paths through the source and therefore the number of required
507 tests. Consider re-factoring if at or above 10.
509 <module name="CyclomaticComplexity">
510 <property name="max" value="15"/>
514 The NPATH metric computes the number of possible execution paths through a function. It takes
515 into account the nesting of conditional statements and multi-part boolean expressions
516 (e.g., A && B, C || D, etc.).
518 <module name="NPathComplexity">
519 <property name="max" value="200"/>
523 Maximum number of throws statements in a method
525 <module name="ThrowsCount">
526 <property name="max" value="2"/>
530 Maximum if-else depth
532 <module name="NestedIfDepth">
533 <property name="max" value="4"/>
537 Restricts nested try blocks to a specified depth.
539 <module name="NestedTryDepth">
540 <property name="max" value="2"/>
543 <!-- ****************************** -->
545 <!-- ****************************** -->
548 Checks for uncommented main() methods (debugging leftovers)
550 <module name="UncommentedMain"/>
553 Check for TODO and similar comments
555 <module name="TodoComment">
556 <property name="format" value="(TODO)|(FIXME)|(DOCUMENT ME)"/>