• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0"?>
2<!--
3  ~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  ~
5  ~ Licensed under the Apache License, Version 2.0 (the "License").
6  ~ You may not use this file except in compliance with the License.
7  ~ A copy of the License is located at
8  ~
9  ~  http://aws.amazon.com/apache2.0
10  ~
11  ~ or in the "license" file accompanying this file. This file is distributed
12  ~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  ~ express or implied. See the License for the specific language governing
14  ~ permissions and limitations under the License.
15  -->
16
17<!DOCTYPE module PUBLIC
18        "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
19        "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
20<!--
21    Checkstyle configuration originally derived from the Google coding conventions from Google Java Style that can be
22    found at https://google.github.io/styleguide/javaguide.html. Deviations have been made where desired.
23 -->
24<module name="Checker">
25    <property name="charset" value="UTF-8"/>
26    <property name="severity" value="error"/>
27    <property name="fileExtensions" value="java"/>
28
29    <!-- Files must not contain tabs. -->
30    <module name="FileTabCharacter">
31        <property name="eachLine" value="true"/>
32    </module>
33
34    <!-- Files must contain a copyright header. -->
35    <module name="Header">
36        <property name="header"
37                  value="/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;).\n * You may not use this file except in compliance with the License.\n * A copy of the License is located at\n *\n *  http://aws.amazon.com/apache2.0\n *\n * or in the &quot;license&quot; file accompanying this file. This file is distributed\n * on an &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */"/>
38    </module>
39
40    <module name="SuppressionFilter">
41        <property name="file"
42                  value="${checkstyle.suppressions.file}"
43                  default="checkstyle-suppressions.xml"/>
44    </module>
45
46    <module name="TreeWalker">
47
48        <!-- Allow suppressing rules via comments. -->
49        <module name="SuppressionCommentFilter"/>
50
51        <!-- Class names must match the file name in which they are defined. -->
52        <module name="OuterTypeFilename"/>
53
54        <!-- Only one class may be defined per file. -->
55        <module name="OneTopLevelClass"/>
56
57        <!-- Special escape sequences like \n and \t must be used over the octal or unicode equivalent. -->
58        <module name="IllegalTokenText">
59            <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
60            <property name="format"
61                      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)"/>
62            <property name="message" value="Avoid using corresponding octal or Unicode escape."/>
63        </module>
64
65        <!-- Unicode escapes must not be used for printable characters. -->
66        <module name="AvoidEscapedUnicodeCharacters">
67            <property name="allowEscapesForControlCharacters" value="true"/>
68            <property name="allowByTailComment" value="true"/>
69            <property name="allowNonPrintableEscapes" value="true"/>
70        </module>
71
72        <!-- Stars must not be used in import statements. -->
73        <module name="AvoidStarImport"/>
74
75        <!-- Checks for unused imports. -->
76        <module name="UnusedImports"/>
77
78        <!-- Package name and imports must not be wrapped. -->
79        <module name="NoLineWrap"/>
80
81        <!-- Braces must be used for all blocks. -->
82        <module name="NeedBraces"/>
83
84        <!-- Braces must not be empty for most language constructs. -->
85        <module name="EmptyBlock">
86            <property name="option" value="TEXT"/>
87            <property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
88        </module>
89
90        <!-- For language constructs related to the previous statement (eg. "else" or "catch"), the keywords must
91             be defined on the same line as the right curly brace. -->
92        <module name="RightCurly">
93            <property name="id" value="RightCurlySame"/>
94            <property name="tokens"
95                      value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_DO"/>
96        </module>
97
98        <!-- For other language constructs, they must be defined on a separate line. -->
99        <module name="RightCurly">
100            <property name="id" value="RightCurlyAlone"/>
101            <property name="option" value="alone"/>
102            <property name="tokens"
103                      value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT, INSTANCE_INIT"/>
104        </module>
105
106        <!-- Language constructs like "if" and "while" must be followed by whitespace. -->
107        <module name="WhitespaceAfter"/>
108
109        <!-- Language constructs must be surrounded by whitespace. -->
110        <module name="WhitespaceAround">
111            <property name="allowEmptyConstructors" value="true"/>
112            <property name="allowEmptyMethods" value="true"/>
113            <property name="allowEmptyTypes" value="true"/>
114            <property name="allowEmptyLoops" value="true"/>
115            <message key="ws.notFollowed"
116                     value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement."/>
117            <message key="ws.notPreceded"
118                     value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
119        </module>
120
121        <!-- Only one statement per line is permitted. -->
122        <module name="OneStatementPerLine"/>
123
124        <!-- Variables must be defined on different lines. -->
125        <module name="MultipleVariableDeclarations"/>
126
127        <!-- No C-style array declarations are permitted (eg. String args[]). -->
128        <module name="ArrayTypeStyle"/>
129
130        <!-- Defaults must always be included for switch statements, even if they are empty. -->
131        <module name="MissingSwitchDefault"/>
132
133        <!-- Case blocks with statements on them must include a break, return, etc. or the comment "fall through". -->
134        <module name="FallThrough"/>
135
136        <!-- When defining long literals, an upper L must be used. -->
137        <module name="UpperEll"/>
138
139        <!-- Modifiers like public, abstract, static, etc. must follow a consistent order. -->
140        <module name="ModifierOrder"/>
141
142        <!-- Empty lines must separate methods and constructors. -->
143        <module name="EmptyLineSeparator">
144            <property name="allowNoEmptyLineBetweenFields" value="true"/>
145        </module>
146
147        <!-- New lines must happen before dots. -->
148        <module name="SeparatorWrap">
149            <property name="id" value="SeparatorWrapDot"/>
150            <property name="tokens" value="DOT"/>
151            <property name="option" value="nl"/>
152        </module>
153
154        <!-- New lines must happen after commas. -->
155        <module name="SeparatorWrap">
156            <property name="id" value="SeparatorWrapComma"/>
157            <property name="tokens" value="COMMA"/>
158            <property name="option" value="EOL"/>
159        </module>
160
161        <!-- Package names must follow a defined format. -->
162        <module name="PackageName">
163            <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
164            <message key="name.invalidPattern"
165                     value="Package name ''{0}'' must match pattern ''{1}''."/>
166        </module>
167
168        <!-- Type names must follow a defined format. -->
169        <module name="TypeName">
170            <message key="name.invalidPattern"
171                     value="Type name ''{0}'' must match pattern ''{1}''."/>
172        </module>
173
174        <!-- Non-constant fields must follow a defined format. -->
175        <module name="MemberName">
176            <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
177            <message key="name.invalidPattern"
178                     value="Member name ''{0}'' must match pattern ''{1}''."/>
179        </module>
180
181        <!-- Constant fields must follow a defined format. -->
182        <module name="ConstantName">
183            <property name="format" value="^log?|[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
184        </module>
185
186        <!-- Method and lambda parameters must follow a defined format. -->
187        <module name="ParameterName">
188            <property name="id" value="ParameterNameNonPublic"/>
189            <property name="format" value="^[a-z]([a-zA-Z0-9]*)?$"/>
190            <property name="accessModifiers" value="protected, package, private"/>
191            <message key="name.invalidPattern"
192                     value="Parameter name ''{0}'' must match pattern ''{1}''."/>
193        </module>
194        <module name="ParameterName">
195            <property name="id" value="ParameterNamePublic"/>
196            <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
197            <property name="accessModifiers" value="public"/>
198            <message key="name.invalidPattern"
199                     value="Parameter name ''{0}'' must match pattern ''{1}''."/>
200        </module>
201
202        <!-- Catch parameters must follow a defined format. -->
203        <module name="CatchParameterName">
204            <property name="format" value="^(e|t|[a-z][a-zA-Z0-9]*)$"/>
205            <message key="name.invalidPattern"
206                     value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
207        </module>
208
209        <!-- Local variables must follow a defined format. -->
210        <module name="LocalVariableName">
211            <property name="tokens" value="VARIABLE_DEF"/>
212            <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
213            <property name="allowOneCharVarInForLoop" value="true"/>
214            <message key="name.invalidPattern"
215                     value="Local variable name ''{0}'' must match pattern ''{1}''."/>
216        </module>
217
218        <!-- Type parameters must follow a defined format. -->
219        <module name="ClassTypeParameterName">
220            <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
221            <message key="name.invalidPattern"
222                     value="Class type name ''{0}'' must match pattern ''{1}''."/>
223        </module>
224        <module name="MethodTypeParameterName">
225            <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
226            <message key="name.invalidPattern"
227                     value="Method type name ''{0}'' must match pattern ''{1}''."/>
228        </module>
229        <module name="InterfaceTypeParameterName">
230            <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
231            <message key="name.invalidPattern"
232                     value="Interface type name ''{0}'' must match pattern ''{1}''."/>
233        </module>
234
235        <!-- Method names must follow a defined format. -->
236        <module name="MethodName">
237            <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
238            <message key="name.invalidPattern"
239                     value="Method name ''{0}'' must match pattern ''{1}''."/>
240        </module>
241
242        <!-- Should not use kotlin function name as public method name -->
243        <module name="software.amazon.awssdk.buildtools.checkstyle.SdkPublicMethodNameCheck">
244            <property name="format" value="^(?!(?:apply|let|run|also|with)$).*$"/>
245            <message key="name.invalidPattern"
246                     value="Method name ''{0}'' conflicts with kotlin function name"/>
247        </module>
248
249        <!-- Finalizers must not be overridden. -->
250        <module name="NoFinalizer"/>
251
252        <!-- Whitespace around generics must follow a defined format. -->
253        <module name="GenericWhitespace">
254            <message key="ws.followed"
255                     value="GenericWhitespace ''{0}'' is followed by whitespace."/>
256            <message key="ws.preceded"
257                     value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
258            <message key="ws.illegalFollow"
259                     value="GenericWhitespace ''{0}'' should be followed by whitespace."/>
260            <message key="ws.notPreceded"
261                     value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
262        </module>
263
264        <!-- File indentation must follow a convention of 4 spaces (8 for throws statements). -->
265        <module name="Indentation">
266            <property name="throwsIndent" value="8"/>
267            <property name="arrayInitIndent" value="8"/>
268        </module>
269
270        <!-- Abbreviations must follow the same conventions as any other word (eg. use Aws, not AWS). -->
271        <module name="AbbreviationAsWordInName">
272            <property name="ignoreFinal" value="false"/>
273            <property name="allowedAbbreviationLength" value="1"/>
274            <property name="severity" value="warning"/>
275        </module>
276
277        <!-- Class contents must be defined in the order suggested by Sun/Oracle:
278             http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141855.html#1852 -->
279        <module name="DeclarationOrder"/>
280
281        <!--&lt;!&ndash; Overloaded methods and constructors must be defined together. &ndash;&gt;-->
282        <!--<module name="OverloadMethodsDeclarationOrder">-->
283        <!--<property name="severity" value="warning"/> &lt;!&ndash; TODO: Make error. &ndash;&gt;-->
284        <!--</module>-->
285
286        <!-- Variables must be declared near where they are used. -->
287        <module name="VariableDeclarationUsageDistance">
288            <property name="allowedDistance" value="10"/>
289        </module>
290
291        <!-- Static imports must occur before external package imports. -->
292        <module name="CustomImportOrder">
293            <property name="sortImportsInGroupAlphabetically" value="true"/>
294            <property name="separateLineBetweenGroups" value="true"/>
295            <property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
296        </module>
297
298        <!-- Method names must be specified on the same line as their parameter list. -->
299        <module name="MethodParamPad"/>
300
301        <!-- There must be no space between a method name and its parameter list. -->
302        <module name="ParenPad"/>
303
304        <!-- Non-field annotations must be on separate lines, or in the case of single parameterless annotation can be
305             placed on the same line as the signature. -->
306        <module name="AnnotationLocation">
307            <property name="id" value="AnnotationLocationMostCases"/>
308            <property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
309        </module>
310
311        <!-- Fields can have multiple annotations applied on the same line. -->
312        <module name="AnnotationLocation">
313            <property name="id" value="AnnotationLocationVariables"/>
314            <property name="tokens" value="VARIABLE_DEF"/>
315            <property name="allowSamelineMultipleAnnotations" value="true"/>
316        </module>
317
318        <!-- Catch blocks must not be empty without a comment. -->
319        <module name="EmptyCatchBlock"/>
320
321        <!-- Comments must be placed at the same indentation level as the surrounding code. -->
322        <module name="CommentsIndentation"/>
323
324        <!-- Checks for imports of certain packages           -->
325        <!-- See http://checkstyle.sf.net/config_imports.html -->
326        <module name="IllegalImport">
327            <property name="illegalPkgs" value="org.apache.http.annotation,javax.annotation.Generated"/>
328        </module>
329
330        <!-- Checks that the override annotation is specified when using @inheritDoc javadoc. -->
331        <module name="MissingOverride"/>
332
333        <!-- Do not allow assignment in subexpressions (except in some cases in loop conditions). -->
334        <module name="InnerAssignment"/>
335
336        <!-- Checks that we don't use System.out.print -->
337        <module name="Regexp">
338          <property name="format" value="System\s*\.\s*(out|err)\s*(\.|::)\s*print"/>
339          <property name="illegalPattern" value="true"/>
340          <property name="message" value="Don't use System console for logging, use a logger instead"/>
341          <property name="ignoreComments" value="true"/>
342        </module>
343
344        <!-- Checks that we don't use System.getenv or System.getProperty -->
345        <module name="Regexp">
346          <property name="format" value="System\s*(\.|::)\s*(getenv|getProperty)"/>
347          <property name="illegalPattern" value="true"/>
348          <property name="message" value="NEVER use System.getenv or System.getProperty. Create and use a
349          SystemSetting, instead."/>
350          <property name="ignoreComments" value="true"/>
351        </module>
352
353        <module name="Regexp">
354            <property name="format" value="SystemSetting\s*(\.|::)\s*getStringValueFromEnvironmentVariable"/>
355            <property name="illegalPattern" value="true"/>
356            <property name="message" value="Are you being naughty and not creating a SystemSetting? Don't you know that
357            your customers want both system properties AND environment variables? Are you REALLY sure you want to use
358            this and not support a system property?"/>
359            <property name="ignoreComments" value="true"/>
360        </module>
361
362        <!-- Checks that we don't implement AutoCloseable/Closeable -->
363        <module name="Regexp">
364            <property name="format" value="(class|interface).*(implements|extends).*[^\w](Closeable|AutoCloseable)[^\w]"/>
365            <property name="illegalPattern" value="true"/>
366            <property name="message" value="Use SdkAutoCloseable instead of Closeable/AutoCloseable"/>
367            <property name="ignoreComments" value="true"/>
368        </module>
369
370        <!-- Checks that we don't use Objects.hash. Objects.hashCode is preferred-->
371        <module name="Regexp">
372            <property name="format" value="\bObjects.hash\b"/>
373            <property name="illegalPattern" value="true"/>
374            <property name="message" value="Don't use Objects.hash, use Objects.hashCode instead"/>
375            <property name="ignoreComments" value="true"/>
376        </module>
377
378        <!-- Checks that we don't use sslContext.newHandler directly -->
379        <module name="Regexp">
380            <property name="format" value="\sslContext.newHandler\b"/>
381            <property name="illegalPattern" value="true"/>
382            <property name="message"
383                      value="Don't use sslContext.newHandler directly, use NettyUtils.newSslHandler instead"/>
384            <property name="ignoreComments" value="true"/>
385        </module>
386
387        <!-- Checks that we don't use AttributeKey.newInstance directly -->
388        <module name="Regexp">
389            <property name="format" value="AttributeKey\.newInstance"/>
390            <property name="illegalPattern" value="true"/>
391            <property name="message" value="Use NettyUtils.getOrCreateAttributeKey to safely declare AttributeKeys"/>
392            <property name="ignoreComments" value="true"/>
393        </module>
394
395        <!-- Checks that we don't use Thread.currentThread().getContextClassLoader() directly -->
396        <module name="Regexp">
397            <property name="format" value="Thread\s*\.\s*currentThread\s*\(\s*\)\s*(\.|::)\s*getContextClassLoader"/>
398            <property name="illegalPattern" value="true"/>
399            <property name="message" value="Use software.amazon.awssdk.core.internal.util.ClassLoaderHelper Class to load the class."/>
400            <property name="ignoreComments" value="true"/>
401        </module>
402
403        <!-- Checks that we don't use the @Ignore annotation on tests -->
404        <module name="software.amazon.awssdk.buildtools.checkstyle.NoIgnoreAnnotationsCheck">
405        </module>
406
407        <!-- Checks that we don't use plural enum names -->
408        <module name="software.amazon.awssdk.buildtools.checkstyle.PluralEnumNames"/>
409
410        <!-- Checks for redundant public modifier on interfaces and other redundant modifiers -->
411        <module name="RedundantModifier" />
412
413        <!-- Checks for utility and constants classes to have private constructor-->
414        <module name="HideUtilityClassConstructor"/>
415
416        <!-- Checks that every class is marked with Sdk Annotation -->
417        <module name="software.amazon.awssdk.buildtools.checkstyle.MissingSdkAnnotationCheck" />
418
419        <!-- Checks that no 'final' are added on local variables -->
420        <module name="software.amazon.awssdk.buildtools.checkstyle.UnnecessaryFinalOnLocalVariableCheck" />
421
422        <module name="software.amazon.awssdk.buildtools.checkstyle.SdkIllegalImportCheck">
423            <property name="classNameToCheck" value="StaticTableSchema"/>
424            <property name="illegalPkgs" value="java.lang.reflect.*"/>
425        </module>
426
427        <module name="software.amazon.awssdk.buildtools.checkstyle.SdkIllegalImportCheck">
428            <property name="classNameToCheck" value="StaticImmutableTableSchema"/>
429            <property name="illegalPkgs" value="java.lang.reflect.*"/>
430        </module>
431
432        <module name="software.amazon.awssdk.buildtools.checkstyle.SdkIllegalImportCheck">
433            <property name="classNameToCheck" value=".*"/>
434            <property name="packageToCheck" value="software.amazon.awssdk.http.nio.netty" />
435            <property name="illegalPkgs" value="software.amazon.awssdk.utils.Logger,org.slf4j.Logger"/>
436        </module>
437
438        <module name="software.amazon.awssdk.buildtools.checkstyle.NonJavaBaseModuleCheck">
439            <!--
440            codegen: Allowed to use classes from java.compiler, because poet requires them.
441            aws-query-protocol: Allowed to use classes from java.xml for XML parsing.
442            protocol-tests-core: Allows to use classes from java.xml for XML assertions.
443            dynamodb-enhanced: Allowed to use classes from java.beans for bean processing.
444            release-scripts: Allowed to use classes from java.xml for XML writing.
445            sdk-benchmarks: Allowed to use classes from javax.servlet.http for benchmark servlets.
446            -->
447            <property name="legalPackages" value="software.amazon.awssdk.codegen:javax.lang.model, software.amazon.awssdk.codegen:javax.lang.model.element, software.amazon.awssdk.codegen:javax.lang.model.type, software.amazon.awssdk.protocols.query:javax.xml.stream, software.amazon.awssdk.protocols.query:javax.xml.stream.events, software.amazon.awssdk.protocol.asserts.marshalling:javax.xml, software.amazon.awssdk.protocol.asserts.marshalling:javax.xml.parsers, software.amazon.awssdk.protocol.asserts.marshalling:javax.xml.transform, software.amazon.awssdk.protocol.asserts.marshalling:javax.xml.transform.dom, software.amazon.awssdk.protocol.asserts.marshalling:javax.xml.transform.stream, software.amazon.awssdk.enhanced.dynamodb:java.beans, software.amazon.awssdk.release:javax.xml, software.amazon.awssdk.release:javax.xml.parsers, software.amazon.awssdk.release:javax.xml.transform, software.amazon.awssdk.release:javax.xml.xpath, software.amazon.awssdk.release:javax.xml.transform.dom, software.amazon.awssdk.release:javax.xml.transform.stream, software.amazon.awssdk.benchmark:javax.servlet.http"/>
448        </module>
449    </module>
450
451        <!-- Enforce maximum line lengths. -->
452    <module name="LineLength">
453        <property name="max" value="130"/>
454        <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
455    </module>
456
457</module>
458