JAL-1854 initial checkstyle config
[jalview.git] / resources / checkstyle / checkstyle.xml
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">
3 <!--
4         Jalview Checkstyle configuration file
5 -->
6 <module name="Checker">
7         <!-- Default severity is warning -->
8         <property name="severity" value="warning"/>
9         <property name="fileExtensions" value="java,properties"/>
10
11         <!-- 
12                 Add any metrics that you wish to suppress to the following file.
13         -->
14         <module name="SuppressionFilter">
15                 <property name="file" value="${basedir}/resources/checkstyle/checkstyle-suppress.xml"/>
16         </module>
17
18         <!-- 
19                 Allow suppression of rules by comments, e.g.:
20                 // CHECKSTYLE.OFF: ParameterNumber
21                 ..method declaration
22                 // CHECKSTYLE.ON: ParameterNumber
23         -->
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"/>
28         </module>
29
30         <!--
31                 Maximum line count for source files
32         -->
33         <module name="FileLength">
34                 <property name="max" value="1200"/>
35                 <property name="fileExtensions" value="java"/>
36         </module>
37
38         <!-- 
39                 Check language bundles have the same keys and no duplicates
40                 (ensure Checkstyle is configured to scan non-source files)
41          -->
42         <module name="Translation">
43                 <property name="fileExtensions" value="properties"/>
44                 <property name="baseName" value="^Messages.*$"/>
45         </module>
46         <module name="UniqueProperties">
47             <property name="fileExtensions" value="properties" />
48                 <property name="severity" value="error"/>
49         </module>
50         
51         <module name="TreeWalker">
52
53                 <property name="tabWidth" value="4"/>
54
55                 <!-- 
56                         Enables parsing of suppressions comments
57                         see http://checkstyle.sourceforge.net/config_filters.html#SuppressionCommentFilter 
58                 -->
59                 <module name="FileContentsHolder"/>
60
61         <!-- ****************************** -->
62         <!--         NAMING STANDARDS       -->
63         <!-- ****************************** -->
64                 
65                 <!--
66                         Naming convention for member fields. Start with (optional) underscore, then
67                         lower case, then camel case; no internal underscores
68                 -->
69                 <module name="MemberName">
70                         <property name="format" value="^_?[a-z][a-zA-Z0-9]*$"/>
71                 </module>
72
73                 <!-- 
74                         Naming convention for methods. Start with (optional) underscore, then
75                         lower case, then camel case; no internal underscores
76                 -->
77                 <module name="MethodName">
78                         <property name="format" value="^_?[a-z]([a-zA-Z0-9]+)*$"/>
79                 </module>
80
81                 <!--
82                         Name pattern for local final variables.
83                 -->
84                 <module name="LocalFinalVariableName">
85                         <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
86                 </module>
87
88                 <!--
89                         Name pattern for local variables
90                 -->
91                 <module name="LocalVariableName">
92                         <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
93                 </module>
94                 
95                 <!--
96                         Name pattern for constants (static final fields)
97                 -->
98                 <module name="ConstantName">
99                         <property name="format" value="^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
100                 </module>
101
102                 <!--
103                         Name pattern for parameters (note no underscores allowed)
104                 -->
105                 <module name="ParameterName">
106                         <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
107                 </module>
108                 
109                 <!--
110                         Name pattern for static (non-final) fields
111                 -->
112                 <module name="StaticVariableName">
113                         <property name="format" value="^[a-z][a-zA-Z0-9_]*$"/>
114                 </module>
115                 
116                 <!--
117                         Name pattern for classes
118                 -->
119                 <module name="TypeName">
120                         <property name="format" value="[A-Z][a-zA-Z0-9]*$"/>
121                         <property name="tokens" value="CLASS_DEF"/>
122                 </module>
123                 
124                 <!--
125                         Name pattern for interfaces. All interfaces names must end with 'I'.
126                         ** currently suppressed in checkstyle-suppress.xml **
127                 -->
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"/>
133                 </module>
134
135                 <!--
136                         Java package name pattern 
137                 -->
138                 <module name="PackageName">
139                         <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
140                 </module>
141
142         <!-- ****************************** -->
143         <!--         LAYOUT AND STYLE       -->
144         <!-- ****************************** -->
145
146                 <!-- 
147                         Only one top level type per source file
148                 -->
149                 <module name="OuterTypeNumber"/>
150                 
151                 <!-- 
152                         Ensure a class has a package declaration
153                  -->
154                 <module name="PackageDeclaration"/>
155                 
156                 <!--
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
160                         3. Constructors
161                         4. Methods
162                  -->
163                 <module name="DeclarationOrder"/>
164                 
165                 <!-- 
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          
169                 -->
170                 <module name="ModifierOrder"/>
171                 
172                 <!-- 
173                         Declare variables in separate statements, for readability and bug avoidance
174                  -->
175                 <module name="MultipleVariableDeclarations"/>
176                 
177                 <!-- 
178                         Only use blocks within control statements 
179                 -->
180                 <module name="AvoidNestedBlocks"/>
181                 
182                 <!-- 
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)
186                 -->
187                 <module name="EmptyBlock">
188                         <property name="option" value="text"/>
189                 </module>
190                 
191                 <!-- 
192                         Require braces round all code blocks within if/else/for/do/while 
193                 -->
194                 <module name="NeedBraces"/>
195                 
196                 <!--
197                         Disallow empty ';' statements
198                 -->
199                 <module name="EmptyStatement"/>
200
201                 <!-- 
202                         Maximum number of return statements for a method
203                 -->
204                 <module name="ReturnCount">
205                         <property name="max" value="4"/>
206                 </module>
207
208                 <!-- 
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
212                 -->
213                 <module name="RedundantModifier"/>
214                 
215                 <!-- 
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 **
219                  -->            
220                 <module name="FinalLocalVariable">
221                         <property name="tokens" value="VARIABLE_DEF" />
222                 </module>
223
224                 <!-- 
225                         Disallows shorthand of assigning values within an expression 
226                 -->
227                 <module name="InnerAssignment"/>
228
229                 <!-- 
230                         Use Java style array declarations to assist in readability 
231                 -->
232                 <module name="ArrayTypeStyle"/>
233
234                 <!-- 
235                         Use L not l to define a long constant 
236                 -->
237                 <module name="UpperEll"/>
238
239         <!-- ****************************** -->
240         <!--           SIZE LIMITS          -->
241         <!-- ****************************** -->
242
243                 <!--
244                         Maximum line count for methods
245                 -->
246                 <module name="MethodLength">
247                         <property name="tokens" value="METHOD_DEF"/>
248                         <property name="max" value="50"/>
249                         <property name="countEmpty" value="false"/>
250                 </module>
251
252                 <!--
253                         Maximum statement count for methods, constructors,
254                         instance initialisation and static initialisation blocks
255                 -->
256                 <module name="ExecutableStatementCount">
257                         <property name="max" value="30"/>
258                         <property name="tokens" value="METHOD_DEF"/>
259                 </module>
260                 <module name="ExecutableStatementCount">
261                         <property name="max" value="30"/>
262                         <property name="tokens" value="CTOR_DEF"/>
263                 </module>
264                 <module name="ExecutableStatementCount">
265                         <property name="max" value="4"/>
266                         <property name="tokens" value="INSTANCE_INIT"/>
267                 </module>
268                 <module name="ExecutableStatementCount">
269                         <property name="id" value="NoStaticInitialization"/>
270                         <property name="max" value="0"/>
271                         <property name="tokens" value="STATIC_INIT"/>
272                 </module>
273
274                 <!--
275                         Maximum parameter count for methods 
276                 -->
277                 <module name="ParameterNumber">
278                         <property name="max" value="5"/>
279                 </module>
280
281                 <!--
282                         Maximum line length for anonymous inner classes
283                 -->
284                 <module name="AnonInnerLength">
285                         <property name="max" value="40"/>
286                 </module>
287
288         <!-- ****************************** -->
289         <!--            IMPORTS             -->
290         <!-- ****************************** -->
291
292                 <!-- 
293                         Ensures that there are no redundant or unused imports.
294                      Should be handled by Save actions if using Eclipse 
295                 -->
296                 <module name="RedundantImport"/>
297                 <module name="UnusedImports"/>
298
299                 <!--
300                         Disallow * imports; may also be enforced by IDE Save Actions
301                 -->
302                 <module name="AvoidStarImport"/>
303
304                 <!-- 
305                         Disallow import of sun.* packages as they are not portable 
306                 -->
307                 <module name="IllegalImport"/>
308
309                 <!--
310                         rules as to what packages each package may (not) import
311                         see http://checkstyle.sourceforge.net/config_imports.html#ImportControl 
312                 -->
313                 <module name="ImportControl">
314                     <property name="file" value="${basedir}/resources/checkstyle/import-control.xml"/>
315                         <property name="severity" value="error"/>
316                 </module>
317                 
318         <!-- ****************************** -->
319         <!--         CATCH and THROW        -->
320         <!-- ****************************** -->
321
322                 <!-- 
323                         Disallow catch of Exception, RunTimeException or Error 
324                 -->
325                 <module name="IllegalCatch"/>
326
327                 <!-- 
328                         Disallow throw of Exception, RunTimeException or Error 
329                 -->
330                 <module name="IllegalThrows"/>
331
332         <!-- ****************************** -->
333         <!--          CODING CHECKS         -->
334         <!-- ****************************** -->
335
336                 <!-- 
337                         Check for use of factory method rather than constructor for specified classes 
338                 -->
339                 <module name="IllegalInstantiation">
340                         <property name="classes" value="java.lang.Boolean"/>
341                 </module>
342                 
343                 <!--
344                         Check that "string".equals(value) is used rather than value.equals("string")
345                 -->
346                 <module name="EqualsAvoidNull"/>
347
348                 <!--
349                         Check that equals() and hashCode() are always overridden together
350                 -->
351                 <module name="EqualsHashCode"/>
352                 
353                 <!-- 
354                         Require switch statements to include a default 
355                 -->
356                 <module name="MissingSwitchDefault"/>
357                 
358                 <!-- 
359                         Check that switch default follows all case statements
360                  -->
361                 <module name="DefaultComesLast">
362                         <property name="severity" value="error"/>
363                 </module>
364                 
365                 <!-- 
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!
368                  -->
369                 <module name="FallThrough">
370                         <property name="severity" value="warning"/>
371                 </module>
372                 
373                 <!-- 
374                         Warn if boolean expressions can be simplified 
375                 -->
376                 <module name="SimplifyBooleanExpression"/>
377
378                 <!-- 
379                         Warn if boolean return expressions can be simplified 
380                 -->
381                 <module name="SimplifyBooleanReturn"/>
382
383                 <!--
384                         Classes with only private constructors should be declared final
385                 -->
386                 <module name="FinalClass"/>
387                 
388                 <!-- 
389                         Classes with only static methods should not be instantiable,
390                         so should declare a private default constructor.
391                 -->
392                 <module name="HideUtilityClassConstructor"/>
393                 
394                 <!-- 
395                         An Interface should declare methods (do not use to define constants only) 
396                 -->
397                 <module name="InterfaceIsType"/>
398                 
399                 <!-- 
400                         Disallow public fields in classes (other than constants) 
401                 -->
402                 <module name="VisibilityModifier">
403                         <property name="packageAllowed" value="true"/>
404                         <property name="allowPublicImmutableFields" value="true"/>
405                 </module>
406                 
407                 <!-- 
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. 
410                 -->
411                 <module name="HiddenField"/> 
412
413                 <!-- 
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.
416                 -->
417                 <module name="RegexpSinglelineJava">
418                         <property name="format" value="System\.out\.println"/>
419                         <property name="ignoreComments" value="true"/>
420                 </module>
421
422                 <!--
423                         Checks that classes that define a covariant equals() method also override 
424                         method equals(java.lang.Object).
425                  -->
426                 <module name="CovariantEquals"/>
427                 
428                 <!-- 
429                         Checks that there are no "magic numbers" (numeric literals) 
430                 -->
431                 <module name="MagicNumber">
432                         <property name="ignoreNumbers" value="-1,0,1,2"/>
433                 </module>
434                 
435                 <!-- 
436                         Check that  loop control variables are not modified inside the for block
437                  -->
438                 <module name="ModifiedControlVariable">
439                 </module>
440                 
441                 <!-- 
442                         Checks that string literals are not used with == or !=.
443                  -->
444                 <module name="StringLiteralEquality">
445                 </module>
446                 
447                 <!-- 
448                         Checks that clone() invokes super.clone() 
449                  -->
450                 <module name="SuperClone"/>
451                 
452                 <!-- 
453                         Checks that finalize() invokes super.finalize()
454                  -->
455                 <module name="SuperFinalize"/>
456                 
457                 <!-- 
458                         Disallow assignment of parameters.
459                  -->
460                 <module name="ParameterAssignment"/>
461
462                 <!-- 
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.
465                  -->
466                 <module name="MultipleStringLiterals">
467                         <property name="allowedDuplicates" value="1"/>
468                 </module>
469                 
470                 <!-- 
471                         Checks that exceptions are immutable (have only final fields)
472                  -->
473                 <module name="MutableException"/>
474
475         <!-- ****************************** -->
476         <!--           COMPLEXITY           -->
477         <!-- ****************************** -->
478                 
479                 <!-- 
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 ||.
483                  -->
484                 <module name="BooleanExpressionComplexity">
485                         <property name="max" value="3"/>
486                 </module>
487                 
488                 <!-- 
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.
491                  -->
492                 <module name="ClassDataAbstractionCoupling">
493                         <property name="max" value="7"/>
494                 </module>
495                 
496                 <!-- 
497                         The number of other classes a class relies on. A high number indicates over-complex
498                         class interdependencies that might benefit from refactoring.
499                  -->
500                 <module name="ClassFanOutComplexity">
501                 <property name="max" value="10"/>
502         </module>
503                 
504                 <!-- 
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.
508                  -->
509                 <module name="CyclomaticComplexity">
510                         <property name="max" value="15"/>
511                 </module>
512                 
513                 <!-- 
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.).
517                  -->
518                 <module name="NPathComplexity">
519                         <property name="max" value="200"/>
520                 </module>
521
522                 <!-- 
523                         Maximum number of throws statements in a method
524                  -->
525                 <module name="ThrowsCount">
526                         <property name="max" value="2"/>
527                 </module>
528                 
529                 <!-- 
530                         Maximum if-else depth
531                  -->
532                 <module name="NestedIfDepth">
533                         <property name="max" value="4"/>
534                 </module>
535
536                 <!-- 
537                         Restricts nested try blocks to a specified depth. 
538                  -->
539                 <module name="NestedTryDepth">
540                         <property name="max" value="2"/>
541                 </module>
542
543         <!-- ****************************** -->
544         <!--              TODO              -->
545         <!-- ****************************** -->
546
547                 <!-- 
548                         Checks for uncommented main() methods (debugging leftovers)
549                  -->
550                 <module name="UncommentedMain"/>
551
552                 <!-- 
553                         Check for TODO and similar comments 
554                 -->
555                 <module name="TodoComment">
556                         <property name="format" value="(TODO)|(FIXME)|(DOCUMENT ME)"/>
557                 </module>
558
559         </module>
560 </module>