JAL-1854 checkstyle relocated to /utils, newlines to Unix (?)
[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                 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                         Don't have more than one statement on a line
179                         (code formatting on save may enforce this anyway)
180                  -->
181                 <module name="OneStatementPerLine"/>
182
183                 <!-- 
184                         Declare variables close to their point of first use 
185                         (doesn't handle variables used inside loops very well) 
186                 -->
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." />
191                 </module>
192         
193                 <!-- 
194                         Only use blocks within control statements 
195                 -->
196                 <module name="AvoidNestedBlocks" />
197
198                 <!-- 
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) 
202                 -->
203                 <module name="EmptyBlock">
204                         <property name="option" value="text"/>
205                 </module>
206                 
207                 <!-- 
208                         Require braces round all code blocks within if/else/for/do/while 
209                 -->
210                 <module name="NeedBraces"/>
211                 
212                 <!--
213                         Disallow empty ';' statements
214                 -->
215                 <module name="EmptyStatement"/>
216
217                 <!-- 
218                         Maximum number of return statements for a method
219                 -->
220                 <module name="ReturnCount">
221                         <property name="max" value="4"/>
222                 </module>
223
224                 <!-- 
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
228                 -->
229                 <module name="RedundantModifier"/>
230                 
231                 <!-- 
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 **
235                  -->            
236                 <module name="FinalLocalVariable">
237                         <property name="tokens" value="VARIABLE_DEF" />
238                 </module>
239
240                 <!-- 
241                         Disallows shorthand of assigning values within an expression 
242                 -->
243                 <module name="InnerAssignment"/>
244
245                 <!-- 
246                         Use Java style array declarations to assist in readability 
247                 -->
248                 <module name="ArrayTypeStyle"/>
249
250                 <!-- 
251                         Use L not l to define a long constant 
252                 -->
253                 <module name="UpperEll"/>
254
255         <!-- ****************************** -->
256         <!--           SIZE LIMITS          -->
257         <!-- ****************************** -->
258
259                 <!--
260                         Maximum line count for methods
261                 -->
262                 <module name="MethodLength">
263                         <property name="tokens" value="METHOD_DEF"/>
264                         <property name="max" value="50"/>
265                         <property name="countEmpty" value="false"/>
266                 </module>
267
268                 <!--
269                         Maximum statement count for methods, constructors,
270                         instance initialisation and static initialisation blocks
271                 -->
272                 <module name="ExecutableStatementCount">
273                         <property name="max" value="30"/>
274                         <property name="tokens" value="METHOD_DEF"/>
275                 </module>
276                 <module name="ExecutableStatementCount">
277                         <property name="max" value="30"/>
278                         <property name="tokens" value="CTOR_DEF"/>
279                 </module>
280                 <module name="ExecutableStatementCount">
281                         <property name="max" value="4"/>
282                         <property name="tokens" value="INSTANCE_INIT"/>
283                 </module>
284                 <module name="ExecutableStatementCount">
285                         <property name="id" value="NoStaticInitialization"/>
286                         <property name="max" value="0"/>
287                         <property name="tokens" value="STATIC_INIT"/>
288                 </module>
289
290                 <!--
291                         Maximum parameter count for methods 
292                 -->
293                 <module name="ParameterNumber">
294                         <property name="max" value="5"/>
295                 </module>
296
297                 <!--
298                         Maximum line length for anonymous inner classes
299                 -->
300                 <module name="AnonInnerLength">
301                         <property name="max" value="40"/>
302                 </module>
303
304         <!-- ****************************** -->
305         <!--            IMPORTS             -->
306         <!-- ****************************** -->
307
308                 <!-- 
309                         Ensures that there are no redundant or unused imports.
310                      Should be handled by Save actions if using Eclipse 
311                 -->
312                 <module name="RedundantImport"/>
313                 <module name="UnusedImports"/>
314
315                 <!--
316                         Disallow * imports; may also be enforced by IDE Save Actions
317                 -->
318                 <module name="AvoidStarImport"/>
319
320                 <!-- 
321                         Disallow import of sun.* packages as they are not portable 
322                 -->
323                 <module name="IllegalImport"/>
324
325                 <!--
326                         rules as to what packages each package may (not) import
327                         see http://checkstyle.sourceforge.net/config_imports.html#ImportControl 
328                 -->
329                 <module name="ImportControl">
330                     <property name="file" value="${basedir}/utils/checkstyle/import-control.xml"/>
331                         <property name="severity" value="error"/>
332                 </module>
333                 
334         <!-- ****************************** -->
335         <!--         CATCH and THROW        -->
336         <!-- ****************************** -->
337
338                 <!-- 
339                         Disallow catch of Exception, RunTimeException or Error 
340                 -->
341                 <module name="IllegalCatch"/>
342
343                 <!-- 
344                         Disallow throw of Exception, RunTimeException or Error 
345                 -->
346                 <module name="IllegalThrows"/>
347
348         <!-- ****************************** -->
349         <!--          CODING CHECKS         -->
350         <!-- ****************************** -->
351
352                 <!-- 
353                         Check for use of factory method rather than constructor for specified classes
354                         e.g. Boolean.valueOf(true) rather than new Boolean(true)
355                 -->
356                 <module name="IllegalInstantiation">
357                         <property name="classes" value="java.lang.Boolean"/>
358                 </module>
359                 
360                 <!--
361                         Check that "string".equals(value) is used rather than value.equals("string")
362                 -->
363                 <module name="EqualsAvoidNull"/>
364
365                 <!--
366                         Check that equals() and hashCode() are always overridden together
367                 -->
368                 <module name="EqualsHashCode"/>
369                 
370                 <!-- 
371                         Require switch statements to include a default 
372                 -->
373                 <module name="MissingSwitchDefault"/>
374                 
375                 <!-- 
376                         Check that switch default follows all case statements
377                  -->
378                 <module name="DefaultComesLast">
379                         <property name="severity" value="error"/>
380                 </module>
381                 
382                 <!-- 
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
386                  -->
387                 <module name="FallThrough">
388                         <property name="severity" value="error" />
389                 </module>
390                 
391                 <!-- 
392                         Warn if boolean expressions can be simplified 
393                 -->
394                 <module name="SimplifyBooleanExpression"/>
395
396                 <!-- 
397                         Warn if boolean return expressions can be simplified 
398                 -->
399                 <module name="SimplifyBooleanReturn"/>
400
401                 <!--
402                         Classes with only private constructors should be declared final
403                 -->
404                 <module name="FinalClass"/>
405                 
406                 <!-- 
407                         Classes with only static methods should not be instantiable,
408                         so should declare a private default constructor.
409                 -->
410                 <module name="HideUtilityClassConstructor"/>
411                 
412                 <!-- 
413                         An Interface should declare methods (do not use to define constants only) 
414                 -->
415                 <module name="InterfaceIsType"/>
416                 
417                 <!-- 
418                         Disallow public fields in classes (other than constants) 
419                 -->
420                 <module name="VisibilityModifier">
421                         <property name="packageAllowed" value="true"/>
422                         <property name="allowPublicImmutableFields" value="true"/>
423                 </module>
424                 
425                 <!-- 
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. 
428                 -->
429                 <module name="HiddenField"/> 
430
431                 <!-- 
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.
434                 -->
435                 <module name="RegexpSinglelineJava">
436                         <property name="format" value="System\.out\.println"/>
437                         <property name="ignoreComments" value="true"/>
438                 </module>
439
440                 <!--
441                         Checks that classes that define a covariant equals() method also override 
442                         method equals(java.lang.Object).
443                  -->
444                 <module name="CovariantEquals"/>
445                 
446                 <!-- 
447                         Checks that there are no "magic numbers" (numeric literals) 
448                 -->
449                 <module name="MagicNumber">
450                         <property name="ignoreNumbers" value="-1,0,1,2"/>
451                 </module>
452                 
453                 <!-- 
454                         Check that  loop control variables are not modified inside the for block
455                  -->
456                 <module name="ModifiedControlVariable">
457                 </module>
458                 
459                 <!-- 
460                         Checks that string literals are not used with == or !=.
461                  -->
462                 <module name="StringLiteralEquality">
463                 </module>
464                 
465                 <!-- 
466                         Don't override clone - it never works! 
467                  -->
468                 <module name="NoClone"/>
469                 
470                 <!-- 
471                         Checks that clone() invokes super.clone()
472                         (for classes that break the NoClone rule)
473                  -->
474                 <module name="SuperClone"/>
475                 
476                 <!-- 
477                         Checks that finalize() invokes super.finalize()
478                  -->
479                 <module name="SuperFinalize"/>
480                 
481                 <!-- 
482                         Disallow assignment of parameters.
483                  -->
484                 <module name="ParameterAssignment"/>
485
486                 <!-- 
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.
489                  -->
490                 <module name="MultipleStringLiterals">
491                         <property name="allowedDuplicates" value="1"/>
492                 </module>
493                 
494                 <!-- 
495                         Checks that exceptions are immutable (have only final fields)
496                  -->
497                 <module name="MutableException"/>
498                 
499                 <!-- 
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
502                  -->
503                 <module name="IllegalToken">
504                    <property name="tokens" value="LITERAL_ASSERT"/>
505                 </module>
506
507         <!-- ****************************** -->
508         <!--           COMPLEXITY           -->
509         <!-- ****************************** -->
510                 
511                 <!-- 
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 ||.
515                  -->
516                 <module name="BooleanExpressionComplexity">
517                         <property name="max" value="3"/>
518                 </module>
519                 
520                 <!-- 
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.
523                  -->
524                 <module name="ClassDataAbstractionCoupling">
525                         <property name="max" value="7"/>
526                 </module>
527                 
528                 <!-- 
529                         The number of other classes a class relies on. A high number indicates over-complex
530                         class interdependencies that might benefit from refactoring.
531                  -->
532                 <module name="ClassFanOutComplexity">
533                 <property name="max" value="10"/>
534         </module>
535                 
536                 <!-- 
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.
540                  -->
541                 <module name="CyclomaticComplexity">
542                         <property name="max" value="15"/>
543                 </module>
544                 
545                 <!-- 
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.).
549                  -->
550                 <module name="NPathComplexity">
551                         <property name="max" value="200"/>
552                 </module>
553
554                 <!-- 
555                         Maximum number of throws statements in a method
556                  -->
557                 <module name="ThrowsCount">
558                         <property name="max" value="2"/>
559                 </module>
560                 
561                 <!-- 
562                         Maximum if-else depth
563                  -->
564                 <module name="NestedIfDepth">
565                         <property name="max" value="4"/>
566                 </module>
567
568                 <!-- 
569                         Restricts nested try blocks to a specified depth. 
570                  -->
571                 <module name="NestedTryDepth">
572                         <property name="max" value="2"/>
573                 </module>
574
575         <!-- ****************************** -->
576         <!--              TODO              -->
577         <!-- ****************************** -->
578
579                 <!-- 
580                         Checks for uncommented main() methods (debugging leftovers)
581                  -->
582                 <module name="UncommentedMain"/>
583
584                 <!-- 
585                         Check for TODO and similar comments 
586                 -->
587                 <module name="TodoComment">
588                         <property name="format" value="(TODO)|(FIXME)|(DOCUMENT ME)"/>
589                 </module>
590
591         </module>
592 </module>