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