-
Notifications
You must be signed in to change notification settings - Fork 2k
/
checkstyle.xml
executable file
·419 lines (359 loc) · 18.6 KB
/
checkstyle.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<!-- This is a checkstyle configuration file. For descriptions of
what the following rules do, please see the checkstyle configuration
page at http://checkstyle.sourceforge.net/config.html -->
<module name="Checker">
<property name="haltOnException" value="false" />
<!-- Exclude module-info.java from checks, as CheckStyle does not presently support it -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
<!-- Custom filter for Azure SDKs. -->
<module name="com.azure.tools.checkstyle.filters.AzureSdkFilter"/>
<module name="SuppressionFilter">
<property name="file" value="${samedir}/checkstyle-suppressions.xml"/>
<property name="optional" value="true"/>
</module>
<module name="Header">
<property name="header"
value="// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT License."/>
<property name="fileExtensions" value="java"/>
</module>
<!-- Checks that there are no tab characters in the file. -->
<module name="FileTabCharacter" />
<module name="NewlineAtEndOfFile" />
<module name="RegexpSingleline">
<!-- Checks that FIXME is not used in comments. TODO is preferred. -->
<property name="format" value="((//.*)|(\*.*))FIXME"/>
<property name="message" value='TODO is preferred to FIXME. e.g. "TODO(johndoe): Refactor when v2 is released."'/>
</module>
<module name="RegexpSingleline">
<!-- Checks that TODOs are named. (Actually, just that they are followed by an open paren. -->
<property name="format" value="((//.*)|(\*.*))TODO [^(]"/>
<property name="message" value='All TODOs should be named. e.g. "TODO (johndoe): Refactor when v2 is released."'/>
</module>
<!-- Checks that a package-info.java file exists for each package. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
<module name="JavadocPackage"/>
<!-- Enforce line length to 120 char -->
<module name="LineLength">
<property name="max" value="120"/>
<!-- Allow codeSnippet to override max line length -->
<!-- Allow comment with single word to override max line length -->
<property name="ignorePattern" value=".*(\{@codesnippet.*\}|<a href)|^ *\* *[^ ]+$||http://|https://|^ *\* *[^ ]+$"/>
</module>
<!-- All Java AST specific tests live under TreeWalker module. -->
<module name="TreeWalker">
<!-- IMPORT CHECKS -->
<!-- See http://checkstyle.sf.net/config_import.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport">
<property name="regexp" value="true"/>
<property name="illegalPkgs" value="^(com\.)?sun\.\w*, ^io.opentelemetry"/>
</module>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<!-- NAMING CHECKS -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName">
<!-- Use default MethodName but block the use of 'builder' as method name -->
<property name="format" value="(?=^[a-z][a-zA-Z0-9]*$)(?!^(?i)builder$)"/>
<!-- allow the name on private methods -->
<property name="applyToPrivate" value="false"/>
</module>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<module name="TypeNameCheck">
<!-- Validates static, final fields against the
expression "^[A-Z][a-zA-Z0-9]*$". -->
<metadata name="altname" value="TypeName"/>
<property name="severity" value="warning"/>
</module>
<module name="ConstantNameCheck">
<!-- Validates non-private, static, final fields against the supplied
public/package final fields "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$". -->
<metadata name="altname" value="ConstantName"/>
<property name="applyToPublic" value="true"/>
<property name="applyToProtected" value="true"/>
<property name="applyToPackage" value="true"/>
<property name="applyToPrivate" value="false"/>
<property name="format" value="^([A-Z][A-Z0-9]*(_[A-Z0-9]+)*|FLAG_.*)$"/>
<message key="name.invalidPattern"
value="Variable ''{0}'' should be in ALL_CAPS (if it is a constant) or be private (otherwise)."/>
<property name="severity" value="warning"/>
</module>
<module name="MissingDeprecated"/>
<module name="StaticVariableNameCheck">
<!-- Validates static, non-final fields against the supplied
expression "^[a-z][a-zA-Z0-9]*_?$". -->
<metadata name="altname" value="StaticVariableName"/>
<property name="applyToPublic" value="true"/>
<property name="applyToProtected" value="true"/>
<property name="applyToPackage" value="true"/>
<property name="applyToPrivate" value="true"/>
<property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
<property name="severity" value="warning"/>
</module>
<module name="MemberNameCheck">
<!-- Validates non-static members against the supplied expression. -->
<metadata name="altname" value="MemberName"/>
<property name="applyToPublic" value="true"/>
<property name="applyToProtected" value="true"/>
<property name="applyToPackage" value="true"/>
<property name="applyToPrivate" value="true"/>
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
<property name="severity" value="warning"/>
</module>
<module name="EqualsAvoidNullCheck"/>
<module name="MethodNameCheck">
<!-- Validates identifiers for method names. -->
<metadata name="altname" value="MethodName"/>
<property name="format" value="^[a-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$"/>
<property name="severity" value="warning"/>
</module>
<module name="ParameterName">
<!-- Validates identifiers for method parameters against the
expression "^[a-z][a-zA-Z0-9]*$". -->
<property name="severity" value="warning"/>
</module>
<module name="LocalFinalVariableName">
<!-- Validates identifiers for local final variables against the
expression "^[a-z][a-zA-Z0-9]*$". -->
<property name="severity" value="warning"/>
</module>
<module name="LocalVariableName">
<!-- Validates identifiers for local variables against the
expression "^[a-z][a-zA-Z0-9]*$". -->
<property name="severity" value="warning"/>
</module>
<!-- LENGTH and CODING CHECKS -->
<module name="LeftCurly">
<!-- Checks for placement of the left curly brace ('{'). -->
<property name="severity" value="warning"/>
</module>
<module name="RightCurly">
<!-- Checks right curlies on CATCH, ELSE, and TRY blocks are on
the same line. e.g., the following example is fine:
<pre>
if {
...
} else
</pre>
-->
<!-- This next example is not fine:
<pre>
if {
...
}
else
</pre>
-->
<property name="option" value="same"/>
<property name="severity" value="warning"/>
</module>
<!-- Checks for braces around if and else blocks -->
<module name="NeedBraces">
<property name="tokens" value="LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
</module>
<module name="UpperEll">
<!-- Checks that long constants are defined with an upper ell.-->
<property name="severity" value="error"/>
</module>
<module name="FallThrough">
<!-- Warn about falling through to the next case statement. Similar to
javac -Xlint:fallthrough, but the check is suppressed if a single-line comment
on the last non-blank line preceding the fallen-into case contains 'fall through' (or
some other variants which we don't publicized to promote consistency).
-->
<property name="reliefPattern"
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
<property name="severity" value="error"/>
</module>
<!-- WHITESPACE CHECKS -->
<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="4"/>
<property name="throwsIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="arrayInitIndent" value="4"/>
</module>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="EmptyForIteratorPad"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter">
<property name="tokens" value="INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,ARRAY_DECLARATOR,INDEX_OP"/>
</module>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround">
<!-- Common for Autorest to generate empty constructors, methods, and types. -->
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLambdas" value="true"/>
</module>
<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<!-- Updated on 03/17/2014: -->
<!-- Added ignore. Code is generated so magic numbers are not a largish issue. -->
<!-- <module name="MagicNumber" /> -->
<module name="MissingSwitchDefault"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<!-- Checks for class design -->
<!-- See http://checkstyle.sf.net/config_design.html -->
<module name="FinalClass"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier">
<property name="protectedAllowed" value="true"/>
<property name="packageAllowed" value="true"/>
</module>
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="ArrayTypeStyle"/>
<!--Checks for package naming and name length limit. Package names have to starting with either-->
<!--'com.microsoft.azure', 'com.azure', or 'io.clientcore' and then the extension names start with-->
<!--characters 'a' to 'z' and only contains 'a' to 'z' or '0' to '9' with no more than 32 characters-->
<!--and the package names should be no more than 80 characters.-->
<module name="PackageName">
<property name="format" value="^(?=.{9,80}$)((com.microsoft|com.azure|io.clientcore)(\.[a-z][a-z0-9]{1,31})*)+$"/>
</module>
<!-- Javadoc checks -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<module name="JavadocMethod">
<property name="accessModifiers" value="public, protected"/>
</module>
<module name="MissingJavadocMethod"/>
<module name="MissingJavadocType"/>
<module name="MissingJavadocPackage"/>
<!-- Verifies that all throws in the public API have JavaDocs explaining why and when they are thrown. -->
<!-- The check verifies both checked (in the throws clause) and unchecked throws -->
<module name="com.azure.tools.checkstyle.checks.JavadocThrowsChecks"/>
<!-- CUSTOM CHECKS -->
<!-- Checks for the public API that should
1) not return classes in the implementation package
2) no class of implementation package as method's parameters -->
<module name="com.azure.tools.checkstyle.checks.NoImplInPublicAPI"/>
<!-- CUSTOM CHECKS -->
<!-- Verify the classes with annotation @ServiceClient should have following rules:
1) No public or protected constructors
2) No public static method named 'builder'
3) Since these classes are supposed to be immutable, all fields in the service client classes should be final.
Also, verify all methods that have a @ServiceMethod annotation in a class annotated with @ServiceClient should
follow below rules:
1) Follows method naming pattern. Refer to Java Spec.
2) Methods should not have "Async" added to the method name
3) The return type of async and sync clients should be as per guidelines:
3.1) The return type for async collection should be of type? extends PagedFlux
3.2) The return type for async single value should be of type? extends Mono
3.3) The return type for sync collection should be of type? extends PagedIterable
3.4) The return type for sync single value should be of type? extends Response -->
<module name="com.azure.tools.checkstyle.checks.ServiceClientCheck"/>
<!-- CUSTOM CHECKS -->
<!-- Checks for no external dependency exposed in the public API.
We should only return types, and accept argument types, that are from the com.azure namespace.
All other types should have suppression added if required. -->
<module name="com.azure.tools.checkstyle.checks.ExternalDependencyExposedCheck"/>
<!-- CUSTOM CHECKS -->
<!-- The @ServiceClientBuilder class should have the following rules:
1) All service client builder should be named <ServiceName>ClientBuilder and annotated with @ServiceClientBuilder.
2) Has a method 'buildClient()' to build a synchronous client,
3) Has a method 'buildAsyncClient()' to build an asynchronous client -->
<module name="com.azure.tools.checkstyle.checks.ServiceClientBuilderCheck"/>
<!-- CUSTOM CHECKS -->
<!-- The @ServiceInterface class should have the following rules:
1) The annotation property 'name' should be non-empty
2) The length of value of property 'name' should be less than 20 characters and without space -->
<module name="com.azure.tools.checkstyle.checks.ServiceInterfaceCheck"/>
<!-- CUSTOM CHECKS -->
<!-- The @Immutable class should have the following rules: -->
<!-- 1) All public and protected fields must be final -->
<!-- 2) No public or protected setters -->
<module name="com.azure.tools.checkstyle.checks.ImmutableClassCheck"/>
<!-- CUSTOM CHECKS -->
<!-- Verify the whenever a field is assigned just once in constructor to be final -->
<module name="com.azure.tools.checkstyle.checks.EnforceFinalFieldsCheck"/>
<!-- CUSTOM CHECKS -->
<!-- Javadoc format: 'param / return / throws' descriptions text should only have one space character after the
parameter name or return -->
<module name="com.azure.tools.checkstyle.checks.JavaDocFormatting"/>
<!-- CUSTOM CHECKS -->
<!-- Must use 'logger.logAndThrow' but not directly calling 'throw exception' -->
<module name="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck"/>
<!-- CUSTOM CHECKS -->
<!-- Any class that implements the HttpPipelinePolicy interface should:
1) Must be a public class.
2) Not in an implementation package or sub-package. -->
<module name="com.azure.tools.checkstyle.checks.HttpPipelinePolicyCheck"/>
<!-- CUSTOM CHECKS -->
<!-- Javadoc inline check should:
1) Use {@codesnippet ...} instead of '<code>', '<pre>', or '{@code ...}' if these tags span multiple lines.
Inline code sample are fine as-is.
2) No check on class-level Javadoc. -->
<!-- This check was removed as it causes more noise than fixes. The purpose of this check was to move away from -->
<!-- using <code>, <pre>, and {@code} tags while we were on-boarding codesnippets. These tags have since been -->
<!-- removed and codesnippets are expected. -->
<!-- <module name="com.azure.tools.checkstyle.checks.JavadocInlineTagCheck"/> -->
<!-- CUSTOM CHECKS -->
<!-- {@codesnippet ...} description should match naming pattern requirement below:
1) Package, class and method names should be concatenated by dot '.'. Ex. packageName.className.methodName
2) Methods arguments should be concatenated by dash '-'. Ex. string-string for methodName(String s, String s2)
3) Use '#' to concatenate 1) and 2), ex packageName.className.methodName#string-string -->
<module name="com.azure.tools.checkstyle.checks.JavadocCodeSnippetCheck"/>
<!--CUSTOM CHECKS-->
<!-- Good Logging Practice
1) ClientLogger in public API should all named 'logger', public API classes are those classes that are declared
as public and that do not exist in an implementation package or subpackage.
2) ClientLogger should be non-static instance logger
3) Should not use any external logger class, only use ClientLogger. No slf4j, log4j, or other logging imports are allowed.
'System.out' and 'System.err' is not allowed as well.
4) All classes should use ClientLogger as logger only but except ClientLogger itself -->
<module name="com.azure.tools.checkstyle.checks.GoodLoggingCheck"/>
<!-- CUSTOM CHECKS -->
<!-- Public API classes should follow Camelcase rules: -->
<!-- 1. ClassName -->
<!-- 2. methodName -->
<!-- 3. variableName -->
<!-- 4. longerVariableOrMethodName -->
<module name="com.azure.tools.checkstyle.checks.DenyListedWordsCheck">
<property name="denyListedWords" value="URL, HTTP, XML, JSON, SAS, CPK, API" />
</module>
<!-- CUSTOM CHECKS -->
<!-- Fluent method checks:
(1) A method returns an instance of the class, and that have one parameter,
(2) should not start with the words in the avoidStartWords list.-->
<!-- <module name="com.azure.tools.checkstyle.checks.FluentMethodNameCheck">-->
<!-- <property name="avoidStartWords" value="with,set"/>-->
<!-- </module>-->
<!-- CUSTOM CHECKS -->
<!-- Ensures caught exceptions are included as exception cause in subsequently thrown exception -->
<module name="com.azure.tools.checkstyle.checks.UseCaughtExceptionCauseCheck"/>
<module name="com.azure.tools.checkstyle.checks.StepVerifierCheck"/>
</module>
</module>