1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3    Copyright (C) 2015 The Android Open Source Project
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    You may obtain a copy of the License at
8
9         http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
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<!-- This is a checkstyle configuration file. For descriptions of
22what the following rules do, please see the checkstyle configuration
23page at http://checkstyle.sourceforge.net/config.html -->
24
25<!-- Checks with numbered comments refer to recommendations made
26by Joshua Bloch in his book Effective Java -->
27
28<module name="Checker">
29  <property name="charset" value="UTF-8"/>
30  <module name="SuppressionCommentFilter"/>
31  <module name="SuppressionCommentFilter">
32    <property name="offCommentFormat" value="__Generated_"/>
33    <property name="onCommentFormat" value="END GENERATED CODE"/>
34  </module>
35  <module name="FileTabCharacter">
36    <!-- Checks that there are no tab characters in the file.
37    -->
38  </module>
39
40  <module name="RegexpSingleline">
41    <!-- Checks that FIXME is not used in comments.  TODO is preferred.
42    -->
43    <property name="format" value="((//.*)|(\*.*))FIXME" />
44    <property name="message" value='TODO is preferred to FIXME.  e.g. "TODO(johndoe): Refactor when v2 is released."' />
45  </module>
46
47  <module name="RegexpSingleline">
48    <!-- Checks that TODOs are properly formatted.
49
50         The (?&lt;!TODO\(.{0,100}) makes the regex ignore any secondary TODO's on the line
51         so that things like //TODO(bob): remove this TODO on 1/1/2020 don't trigger a warning
52         because of the second TODO.  (The {0,100} is because java doesn't recoginize arbitrary
53         length look backs, but we know each java line should be < 100 chars.)
54    -->
55    <property name="format" value="((//.*)|(\*.*))(?&lt;!TODO\(.{0,100})(TODO[^(])|(TODO\([^)]*$)" />
56    <property name="message" value='All TODOs should be named.  e.g. "TODO(johndoe): Refactor when v2 is released."' />
57  </module>
58
59
60  <!-- All Java AST specific tests live under TreeWalker module. -->
61  <module name="TreeWalker">
62    <module name="FileContentsHolder"/>
63    <!--module name="SuppressWarningsFilter" /-->
64    <!--module name="SuppressWarningsHolder" /-->
65    <!--
66
67    IMPORT CHECKS
68
69    -->
70
71    <module name="RedundantImport">
72      <property name="severity" value="error"/>
73    </module>
74
75    <module name="AvoidStarImport">
76      <property name="severity" value="error"/>
77    </module>
78
79    <module name="UnusedImports">
80      <!-- DPL is a notable violator of this rule. -->
81      <property name="severity" value="error"/>
82      <!-- Imports used only in Javadoc are tolerated. See http://b/838496 -->
83      <property name="processJavadoc" value="true"/>
84      <message
85          key="import.unused"
86          value="Unused import: {0}." />
87    </module>
88
89    <module name="checkstyle.patches.checks.imports.ImportOrder">
90      <!-- Checks for out of order import statements. -->
91
92      <metadata name="altname" value="ImportOrder"/>
93      <property name="severity" value="warning"/>
94      <property name="groups" value="android,com.android,com.google,*,java,javax"/>
95      <!-- This ensures that static imports go first. -->
96      <property name="option" value="top"/>
97      <property name="tokens" value="STATIC_IMPORT, IMPORT"/>
98      <message
99          key="import.ordering"
100          value="Wrong order for {0} import." />
101    </module>
102
103    <!-- Checks that nested classes are not statically imported. -->
104    <module name="com.google.devtools.checkstyle.checks.imports.StaticImportNestedClassCheck">
105      <metadata name="altname" value="StaticImportNestedClass"/>
106      <property name="severity" value="warning"/>
107      <message key="import.staticNestedClass"
108               value="Use of static import for nested classes is disallowed."/>
109    </module>
110
111    <!--
112
113    JAVADOC CHECKS
114
115    -->
116
117    <module name="com.google.devtools.checkstyle.checks.javadoc.GoogleJavadocTypeCheck">
118      <!-- Item 28 - Write doc comments for all exposed API elements. -->
119      <!-- Ensure all classes with visability greater than or equal to
120        protected have class level documentation. -->
121      <property name="scope" value="protected"/>
122      <property name="severity" value="ignore"/>
123      <!-- Style guide doesn't prohibit custom tags. Typos will be caught by other tools. -->
124      <property name="allowUnknownTags" value="true"/>
125      <property name="allowMissingParamTags" value="true"/>
126    </module>
127
128    <!--
129
130    NAMING CHECKS
131
132    -->
133
134    <!-- Item 38 - Adhere to generally accepted naming conventions -->
135
136    <module name="PackageName">
137      <!-- Validates identifiers for package names against the
138        supplied expression. -->
139      <!-- Here the default checkstyle rule restricts package name parts to
140        seven characters, this is not in line with common practice at Google.
141      -->
142      <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,})*$"/>
143      <property name="severity" value="warning"/>
144    </module>
145
146    <module name="TypeNameCheck">
147      <!-- Validates static, final fields against the
148      expression "^[A-Z][a-zA-Z0-9]*$". -->
149      <metadata name="altname" value="TypeName"/>
150      <property name="severity" value="warning"/>
151    </module>
152
153    <module name="com.google.devtools.checkstyle.checks.coding.ConstantNameCheck">
154      <!-- Validates that constant fields are named in ALL_CAPS. -->
155      <metadata name="altname" value="ConstantName"/>
156      <property name="applyToPublic" value="true"/>
157      <property name="applyToProtected" value="true"/>
158      <property name="applyToPackage" value="true"/>
159      <property name="applyToPrivate" value="true"/>
160      <property name="format" value="^_?[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
161      <message key="name.invalidPattern"
162               value="Variable ''{0}'' is a constant and thus should be in ALL_CAPS."/>
163      <property name="severity" value="ignore"/>
164    </module>
165
166    <module name="StaticVariableNameCheck">
167      <!-- Validates static, non-final fields against the supplied
168      expression "^[a-z][a-zA-Z0-9]*_?$". -->
169      <metadata name="altname" value="StaticVariableName"/>
170      <property name="applyToPublic" value="true"/>
171      <property name="applyToProtected" value="true"/>
172      <property name="applyToPackage" value="true"/>
173      <property name="applyToPrivate" value="true"/>
174      <property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
175      <property name="severity" value="ignore"/>
176    </module>
177
178    <module name="MemberNameCheck">
179      <!-- Validates non-static members against the supplied expression. -->
180      <metadata name="altname" value="MemberName"/>
181      <property name="applyToPublic" value="true"/>
182      <property name="applyToProtected" value="true"/>
183      <property name="applyToPackage" value="true"/>
184      <property name="applyToPrivate" value="true"/>
185      <!-- allows for googles deprecated foo_ member naming scheme -->
186      <property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
187      <property name="severity" value="ignore"/>
188    </module>
189
190    <module name="MethodNameCheck">
191      <!-- Validates identifiers for method names. -->
192      <metadata name="altname" value="MethodName"/>
193      <property name="format" value="^[a-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$"/>
194      <property name="severity" value="warning"/>
195    </module>
196
197    <module name="ParameterName">
198      <!-- Validates identifiers for method parameters against the
199        expression "^[a-z][a-zA-Z0-9]*$". -->
200      <property name="severity" value="warning"/>
201    </module>
202
203    <module name="LocalFinalVariableName">
204      <!-- Validates identifiers for local final variables against the
205        expression "^[a-z][a-zA-Z0-9]*$". -->
206      <property name="severity" value="warning"/>
207    </module>
208
209    <module name="LocalVariableName">
210      <!-- Validates identifiers for local variables against the
211        expression "^[a-z][a-zA-Z0-9]*$". -->
212      <property name="severity" value="warning"/>
213    </module>
214
215
216    <!--
217
218    LENGTH and CODING CHECKS
219
220    -->
221
222    <module name="LineLength">
223      <!-- Checks if a line is too long. -->
224      <property name="max" value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.max}" default="100"/>
225      <property name="severity" value="error"/>
226
227      <!--
228        The default ignore pattern exempts the following elements:
229          - import statements
230          - long URLs inside comments
231          - certain JSNI method signatures used in GWT, see http://wiki/Nonconf/GwtInGoogle3Faq#JsniLineBreaks.
232      -->
233
234      <!--
235           The JSNI/GWT exemption only is for the JNI-style signature, that cannot be split across multiple lines.
236           Both the instance expression and the parameter list may and must go on separate lines.
237
238           These examples are exempt:
239           <pre>
240             private native void foo() /*-{
241               // Method call, signature as the only long line (> 100 chars)
242               this.
243                 @com.google.gwt.foo.bar.baz.ClassUsingJsni::someMethod(Lcom/google/gwt/foo/bar/baz/ParameterType;)
244                 (param);
245
246               // Static method call, signature as the only long line (> 100 chars)
247               @com.google.gwt.foo.bar.baz.ClassUsingJsni::staticMethod(Lcom/google/gwt/foo/bar/baz/ParameterType;)
248                 (param);
249
250               // Method reference in dictionary, signature as the only long line
251               var dict = {
252                key:
253                  @com.google.gwt.foo.bar.baz.ClassUsingJsni::otherMethod(Lcom/google/gwt/foo/bar/baz/ParameterType;Z),
254                }
255            }-*/;
256           </pre>
257
258           These exampls are NOT exempt, as the line can be broken further:
259           <pre>
260             private native void foo() /*-{
261               // Instance expression on same line
262               this.@com.google.gwt.foo.bar.baz.ClassUsingJsni::someMethod(Lcom/google/gwt/foo/bar/baz/ParameterType;)
263                 (param);
264
265               // Parameters on same line
266               this.
267                 @com.google.gwt.foo.bar.baz.ClassUsingJsni::someMethod(Lcom/google/gwt/foo/bar/baz/ParameterType;)(param);
268
269               // All on one line
270               this.@com.google.gwt.foo.bar.baz.ClassUsingJsni::someMethod(Lcom/google/gwt/foo/bar/baz/ParameterType;)(param);
271            }-*/;
272           </pre>
273      -->
274      <property name="ignorePattern"
275          value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.ignorePattern}"
276          default="^(package .*;\s*)|(import .*;\s*)|( *\* *https?://.*)|(\s*@[\w\.\$]+::\w+(?:\([^\(]*\)|\(\)\(\))?[,;]?)|(\s+\* \{@(link|see) [^\s][^\}]*\}[\.,;]?)$"/>
277    </module>
278
279    <module name="LeftCurly">
280      <!-- Checks for placement of the left curly brace ('{'). -->
281      <property name="severity" value="warning"/>
282    </module>
283
284    <module name="RightCurly">
285      <!-- Checks right curlies on CATCH, ELSE, and TRY blocks are on
286      the same line. e.g., the following example is fine:
287      <pre>
288        if {
289          ...
290        } else
291      </pre>
292      -->
293      <!-- This next example is not fine:
294      <pre>
295        if {
296          ...
297        }
298        else
299      </pre>
300      -->
301      <property name="option" value="same"/>
302      <property name="severity" value="warning"/>
303    </module>
304
305    <!-- Checks for braces around if and else blocks -->
306    <module name="NeedBraces">
307      <property name="severity" value="warning"/>
308      <property name="tokens" value="LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
309    </module>
310
311    <!-- Checks for empty catch blocks in non-test files. -->
312    <module name="com.google.devtools.checkstyle.checks.blocks.EmptyCatchBlockCheck">
313      <metadata name="altname" value="EmptyCatchBlock"/>
314      <property name="severity" value="error"/>
315    </module>
316
317    <module name="UpperEll">
318      <!-- Checks that long constants are defined with an upper ell.-->
319      <property name="severity" value="error"/>
320    </module>
321
322    <module name="FallThrough">
323      <!-- Warn about falling through to the next case statement.  Similar to
324      javac -Xlint:fallthrough, but the check is suppressed if there is a single-line comment
325      on the last non-blank line preceding the fallen-into case.
326      -->
327      <property name="reliefPattern"
328       value=".*"/>
329      <property name="severity" value="error"/>
330    </module>
331
332
333    <!--
334
335    MODIFIERS CHECKS
336
337    -->
338
339    <module name="ModifierOrder">
340      <!-- Warn if modifier order is inconsistent with JLS3 8.1.1, 8.3.1, and
341           8.4.3.  The prescribed order is:
342           public, protected, private, abstract, static, final, transient, volatile,
343           synchronized, native, strictfp
344        -->
345    </module>
346
347
348    <!--
349
350    WHITESPACE CHECKS
351
352    -->
353
354    <module name="WhitespaceAround">
355      <!-- Checks that various tokens are surrounded by whitespace.
356           This includes most binary operators and keywords followed
357           by regular or curly braces.
358      -->
359      <property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR,
360        BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN,
361        EQUAL, GE, GT, LAND, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
362        LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
363        LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
364        MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION,
365        SL, SL_ASSIGN, SR_ASSIGN, STAR, STAR_ASSIGN"/>
366      <property name="severity" value="error"/>
367      <property name="ignoreEnhancedForColon" value="false"/>
368    </module>
369
370    <module name="WhitespaceAfter">
371      <!-- Checks that commas, semicolons and typecasts are followed by
372           whitespace.
373      -->
374      <property name="tokens" value="COMMA, SEMI, TYPECAST"/>
375    </module>
376
377    <module name="NoWhitespaceAfter">
378      <!-- Checks that there is no whitespace after various unary operators.
379           Linebreaks are allowed.
380      -->
381      <property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS,
382        UNARY_PLUS"/>
383      <property name="allowLineBreaks" value="true"/>
384      <property name="severity" value="error"/>
385    </module>
386
387    <module name="NoWhitespaceBefore">
388      <!-- Checks that there is no whitespace before various unary operators.
389           Linebreaks are allowed.
390      -->
391      <property name="tokens" value="SEMI, DOT, POST_DEC, POST_INC"/>
392      <property name="allowLineBreaks" value="true"/>
393      <property name="severity" value="error"/>
394    </module>
395
396    <module name="ParenPad">
397      <!-- Checks that there is no whitespace before close parens or after
398           open parens.
399      -->
400      <property name="severity" value="warning"/>
401    </module>
402
403    <!--
404
405    MISC CHECKS
406
407    -->
408
409  </module>
410</module>
411
412