forked from linkedin/dr-elephant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkstyle-config.xml
364 lines (337 loc) · 16.1 KB
/
checkstyle-config.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2016 LinkedIn Corp.
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
-->
<!DOCTYPE module PUBLIC "-//Source Forge//DTD Check Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<!-- *********************** Configurations *********************** -->
<!-- Filter out non Java files -->
<property name="fileExtensions" value="java"/>
<!-- Allow suppression using @SuppressWarnings annotation -->
<module name="SuppressWarningsFilter" />
<!-- Read checker suppressions from a file -->
<module name="SuppressionFilter">
<property name="file" value="project/checkstyle-suppressions.xml"/>
</module>
<!-- Allow Checkstyle warnings to be suppressed using trailing comments -->
<module name="SuppressWithNearbyCommentFilter"/>
<!-- Allow Checkstyle warnings to be suppressed using block comments -->
<module name="SuppressionCommentFilter"/>
<!-- *********************** Issues which will be treated as errors hence enforced *********************** -->
<!-- FILE HEADER as per format given in the header file configured below -->
<module name="RegexpHeader">
<property name="headerFile" value="project/checkstyle-java.header"/>
<property name="fileExtensions" value="java"/>
</module>
<!-- Desired file length is upto 2000 lines -->
<module name="FileLength"/>
<!-- Do not allow tab characters in source files -->
<module name="FileTabCharacter"/>
<!-- JAVADOC RELATED -->
<!-- Ensure parameter and exception names are present on @param and @throws tags -->
<module name="RegexpSingleline">
<property name="id" value="missingJavadocParamOrException"/>
<property name="format" value="\*[\s]*@(throws|param)[\s]*$"/>
<property name="message" value="Missing parameter or exception name"/>
</module>
<!-- Detect commonly misspelled Javadoc tags -->
<module name="RegexpSingleline">
<property name="id" value="misspelledJavadoc"/>
<property name="format" value="\*[\s]*@(params|throw|returns)[\s]+"/>
<property name="message" value="Correct misspelled Javadoc tag"/>
</module>
<!-- IDE generated code must be reviewed by developer -->
<module name="RegexpSingleline">
<property name="id" value="autoGeneratedCode"/>
<property name="format" value="\/\/[\s]*TODO[\s]+Auto-generated"/>
<property name="message" value="Replace IDE generated code with real implementation"/>
</module>
<module name="TreeWalker">
<!-- Used in conjunction with SuppressWarningsFilter -->
<module name="SuppressWarningsHolder"/>
<module name="FileContentsHolder"/>
<!-- *********************** Issues (inside TreeWalker) which will be treated as errors hence enforced *********************** -->
<!-- Errors would lead to a build failure. Errors which you think are not relevant would have to be suppressed
either by adding checkstyle-suppressions.xml or by using relevant annotations/comments -->
<!-- BLOCKS -->
<module name="EmptyBlock">
<!-- Empty blocks for which are not allowed -->
<property name="tokens" value="LITERAL_CASE,ARRAY_INIT,STATIC_INIT,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_IF,LITERAL_FOR,LITERAL_TRY,LITERAL_WHILE"/>
</module>
<!-- There should not be an empty catch block unless there is a comment inside -->
<module name="EmptyCatchBlock"/>
<!-- Block opening brace on same line -->
<module name="LeftCurly">
<property name="option" value="eol"/>
</module>
<!-- Block closing brace for else, catch, finally on same line -->
<module name="RightCurly">
<property name="option" value="same"/>
</module>
<!-- Always use braces even if optional -->
<module name="NeedBraces"/>
<!-- CLASS DESIGN -->
<module name="VisibilityModifier"/>
<!-- LENGTHS -->
<!-- Desired line length is upto 120 characters -->
<module name="LineLength">
<property name="max" value="120"/>
<message key="maxLineLen" value="Line is longer than {0,number,integer} characters (found {1,number,integer})."/>
</module>
<!-- Desired method length is upto 150 lines -->
<module name="MethodLength"/>
<!-- Desired number of params passed to a method is upto 7 parameters -->
<module name="ParameterNumber"/>
<!-- MISCELLANEOUS -->
<!-- Indentation should be 2 spaces -->
<module name="Indentation">
<property name="basicOffset" value="2"/>
<property name="caseIndent" value="0"/>
<property name="braceAdjustment" value="0"/>
<property name="throwsIndent" value="2"/>
</module>
<!-- Use Java style array declarations (e.g. String[] names), not C style (e.g. String names[]) -->
<module name="ArrayTypeStyle"/>
<!-- CODING -->
<!-- If covariant equals defined, standard equals must also be defined -->
<module name="CovariantEquals"/>
<!-- Override equals and hashCode together -->
<module name="EqualsHashCode"/>
<!-- Do not use '==' to compare string against a literal; use 'equals' -->
<module name="StringLiteralEquality"/>
<!-- Switch 'default' case must appear last -->
<module name="DefaultComesLast"/>
<!-- Switch statements must have a 'default' case and it should be last case -->
<module name="MissingSwitchDefault"/>
<!-- No fall through in switch cases, even the last one -->
<module name="FallThrough">
<property name="checkLastCaseGroup" value="true"/>
</module>
<!-- Do not perform assignments embedded within expressions -->
<module name="InnerAssignment"/>
<!-- Do not modify the 'for' loop control variable -->
<module name="ModifiedControlVariable"/>
<!-- Local variable or a parameter should not hide a field that is defined in the same class -->
<module name="HiddenField">
<property name="ignoreSetter" value="true"/>
<property name="setterCanReturnItsClass" value="true"/>
<property name="ignoreConstructorParameter" value="true"/>
</module>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format" value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message" value="Avoid using corresponding octal or Unicode escape."/>
</module>
<module name="NoFinalizer"/>
<!-- IMPORTS -->
<!-- Do not duplicate import statements -->
<module name="RedundantImport"/>
<!-- Eliminate unused imports -->
<module name="UnusedImports"/>
<!-- JAVADOC COMMENTS -->
<!-- If you have a Javadoc comment, make sure it is properly formed -->
<module name="JavadocStyle">
<property name="checkFirstSentence" value="false"/>
</module>
<!-- Protected and public methods should have javadoc and allow RuntimeException,
even if not declared to be documented -->
<module name="JavadocMethod">
<property name="scope" value="protected"/>
<property name="allowUndeclaredRTE" value="true"/>
</module>
<!-- NAMING CONVENTIONS -->
<!-- Constants must be all uppercase letters separated by underscores -->
<module name="ConstantName">
<property name="format" value="^(_?log)|([A-Z][A-Z0-9]*(_[A-Z0-9]+)*)$"/>
</module>
<!-- Generic parameters for a class must be uppercase letters (e.g. <T>, <OLD>) -->
<module name="ClassTypeParameterName">
<property name="format" value="^[A-Z]+$"/>
</module>
<!-- Local variables must be camel case starting with lowercase letter -->
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<!-- Member variables must be camel case starting with lowercase letter or underscore -->
<module name="MemberName">
<property name="format" value="^[_a-z][a-zA-Z0-9]*$"/>
</module>
<!-- Method name must be camel case starting with a lowercase letter -->
<module name="MethodName"/>
<!-- Generic parameters for a method must be uppercase letters separated by underscore (e.g. <V>, <NEW>) -->
<module name="MethodTypeParameterName">
<property name="format" value="^[A-Z]+(_[A-Z]+)*$"/>
</module>
<!-- Package name must be all lowercase letters separated by periods -->
<module name="PackageName">
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
</module>
<!-- Parameters must be camel case starting with a lowercase letter -->
<module name="ParameterName"/>
<!-- Static variables must be camel case starting with lowercase letter or underscore -->
<module name="StaticVariableName">
<property name="format" value="^[_a-z][a-zA-Z0-9]*$"/>
</module>
<!-- Type names must be camel case starting with an uppercase letter -->
<module name="TypeName"/>
<!-- METRICS -->
<!-- Cyclomatic complexity should not be more than 15 -->
<module name="CyclomaticComplexity">
<property name="max" value="15"/>
</module>
<!-- REGEXP -->
<!-- Do not allow meaningless, IDE generated parameter names -->
<module name="RegexpSinglelineJava">
<property name="id" value="autoGeneratedParamName"/>
<property name="format" value="[\s]+arg[\d]+[,\)]"/>
<property name="message" value="Replace argN with a meaningful parameter name"/>
</module>
<!-- Do not allow System.out or System.err println and printf methods -->
<module name="RegexpSinglelineJava">
<property name="id" value="println"/>
<property name="format" value="^System\.(out|err)\.print(ln|f){0,1}\(.*\)"/>
<property name="message" value="Replace System.out or System.err println or printf methods with logs"/>
</module>
<!-- Avoid throwing error in Dr.Elephant code -->
<module name="RegexpSinglelineJava">
<property name="id" value="throwError"/>
<property name="format" value="throw new \w+Error\("/>
<property name="message" value="Avoid throwing error."/>
</module>
<!-- ************************** Issues (inside TreeWalker) which will be treated as warnings *************************** -->
<!-- Warnings would not lead to a build failure but committers should check these warnings to determine
if they need to be fixed or not by comparing results before and after the code in PR -->
<!-- ANNOTATIONS -->
<!-- No trailing empty parenthesis or commas -->
<module name="AnnotationUseStyle">
<property name="severity" value="warning"/>
<property name="elementStyle" value="ignore"/>
</module>
<!-- Package level annotations belong in package-info.java -->
<module name="PackageAnnotation">
<property name="severity" value="warning"/>
</module>
<!-- CODING -->
<!-- Do not test boolean expressions against the values true or false -->
<module name="SimplifyBooleanExpression">
<property name="severity" value="warning"/>
</module>
<!-- Do not test for boolean conditions and return the values true or false -->
<module name="SimplifyBooleanReturn">
<property name="severity" value="warning"/>
</module>
<!-- Each variable delcaration must be on a separate line -->
<module name="MultipleVariableDeclarations">
<property name="severity" value="warning"/>
</module>
<!-- Each statement (i.e. code terminated by a semicolon) must be on a separate line -->
<module name="OneStatementPerLine">
<property name="severity" value="warning"/>
</module>
<!-- Classes must have an explicit package declaration -->
<module name="PackageDeclaration">
<property name="severity" value="warning"/>
</module>
<!-- Use 'L' with long literals -->
<module name="UpperEll">
<property name="severity" value="warning"/>
</module>
<!-- Avoid using magic numbers -->
<module name="MagicNumber">
<property name="severity" value="warning"/>
</module>
<!-- Distance between declaration of variable and its first usage -->
<module name="VariableDeclarationUsageDistance">
<property name="severity" value="warning"/>
<property name="allowedDistance" value="5"/>
</module>
<!-- Use constants instead of multiple string literals. As there can be multiple unnecessary issues
reported, keeping it at warning severity. Committers though should pay attention to this issue
and ask contributors to fix wherever they deem fit -->
<module name="MultipleStringLiterals">
<property name="severity" value="warning"/>
<property name="allowedDuplicates" value="2"/>
</module>
<!-- Clones are hard to get right -->
<module name="NoClone">
<property name="severity" value="warning"/>
</module>
<!-- IMPORTS -->
<!-- Do not import 'sun' packages -->
<module name="IllegalImport">
<property name="severity" value="warning"/>
</module>
<!-- WHITESPACE -->
<!-- Whitespace around generics -->
<module name="GenericWhitespace">
<property name="severity" value="warning"/>
</module>
<module name="NoWhitespaceAfter">
<property name="severity" value="warning"/>
<property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS"/>
</module>
<module name="NoWhitespaceBefore">
<property name="severity" value="warning"/>
</module>
<module name="WhitespaceAfter">
<property name="severity" value="warning"/>
</module>
<module name="WhitespaceAround">
<property name="severity" value="warning"/>
</module>
<!-- Whether to have space between parentheses for method parameters -->
<module name="MethodParamPad">
<property name="severity" value="warning"/>
</module>
<module name="ParenPad">
<property name="severity" value="warning"/>
</module>
<module name="TypecastParenPad">
<property name="severity" value="warning"/>
<property name="tokens" value="RPAREN,TYPECAST"/>
</module>
<!-- METRICS -->
<!-- No more than 5 boolean operations in an expression -->
<module name="BooleanExpressionComplexity">
<property name="severity" value="warning"/>
<property name="max" value="5"/>
</module>
<!-- Class fan out complexity i.e. number of other classes a given class relies on should not be more than 20 -->
<module name="ClassFanOutComplexity">
<property name="severity" value="warning"/>
</module>
<!-- NPath complexity should not be more than 200 -->
<module name="NPathComplexity">
<property name="severity" value="warning"/>
</module>
<!-- *********************** Ignored for now (inside TreeWalker) *********************** -->
<!-- We will revisit these issues later because of low signal to noise ratio -->
<!-- Ensure @Override is present when {@inheritDoc} Javadoc tag is present
Ignored because it likely causes inconsistent use of @Override (some methods have it while other methods don't)-->
<!-- <module name="MissingOverride"/> -->
<!-- CLASS DESIGN -->
<!-- Classes containing only static methods should not have a public constructor -->
<!-- ignored due to relatively low signal to noise ratio -->
<!-- <module name="HideUtilityClassConstructor"/> -->
<!-- No imports statements using '*' notation except static imports -->
<!-- ignored due to low signal to noise
<module name="AvoidStarImport">
<property name="allowStaticMemberImports" value="true"/>
</module>
-->
<!-- the list of tokens is nearly the same as the checkstyle default.
Ignore because it shows a lot of false positives
The code looks cleaner if ceratain operators remain in the same line
<module name="OperatorWrap"/> -->
<!-- Ignoring including package-info.java at package level for now
<module name="JavadocPackage"/> -->
</module>
</module>