checkstyle-strict.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!DOCTYPE module PUBLIC
  17. "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
  18. "https://checkstyle.org/dtds/configuration_1_3.dtd">
  19. <!-- This is a checkstyle configuration file. For descriptions of
  20. what the following rules do, please see the checkstyle configuration
  21. page at https://checkstyle.sourceforge.io/config.html -->
  22. <module name="Checker">
  23. <module name="FileTabCharacter">
  24. <!-- Checks that there are no tab characters in the file. -->
  25. </module>
  26. <module name="RegexpSingleline">
  27. <!-- Checks that TODOs don't have stuff in parenthesis, e.g., username. -->
  28. <property name="format" value="((//.*)|(\*.*))TODO\(" />
  29. <property name="message" value="TODO comments must not include usernames." />
  30. <property name="severity" value="error" />
  31. </module>
  32. <module name="RegexpSingleline">
  33. <property name="format" value="\s+$"/>
  34. <property name="message" value="Trailing whitespace"/>
  35. <property name="severity" value="error"/>
  36. </module>
  37. <module name="RegexpSingleline">
  38. <property name="format" value="Throwables.propagate\("/>
  39. <property name="message" value="Throwables.propagate is deprecated"/>
  40. <property name="severity" value="error"/>
  41. </module>
  42. <!-- Prevent *Tests.java as tools may not pick them up -->
  43. <module name="RegexpOnFilename">
  44. <property name="fileNamePattern" value=".*Tests\.java$" />
  45. </module>
  46. <module name="SuppressionFilter">
  47. <property name="file" value="${checkstyle.suppressions.file}" default="suppressions.xml" />
  48. </module>
  49. <!-- All Java AST specific tests live under TreeWalker module. -->
  50. <module name="TreeWalker">
  51. <!-- Allow use of comment to suppress javadocstyle -->
  52. <module name="SuppressionCommentFilter">
  53. <property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
  54. <property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
  55. <property name="checkFormat" value="$1"/>
  56. </module>
  57. <module name="TodoComment">
  58. <!-- Checks that disallowed strings are not used in comments. -->
  59. <property name="format" value="(FIXME)|(XXX)|(@author)" />
  60. </module>
  61. <!--
  62. IMPORT CHECKS
  63. -->
  64. <module name="RedundantImport">
  65. <!-- Checks for redundant import statements. -->
  66. <property name="severity" value="error"/>
  67. <message key="import.redundancy"
  68. value="Redundant import {0}."/>
  69. </module>
  70. <module name="ImportOrder">
  71. <property name="severity" value="error"/>
  72. <!-- This ensures that static imports go first. -->
  73. <property name="option" value="top"/>
  74. <property name="sortStaticImportsAlphabetically" value="true"/>
  75. <property name="tokens" value="STATIC_IMPORT, IMPORT"/>
  76. <message key="import.ordering"
  77. value="Import {0} appears after other imports that it should precede"/>
  78. </module>
  79. <module name="AvoidStarImport">
  80. <property name="severity" value="error"/>
  81. </module>
  82. <module name="IllegalImport">
  83. <property name="illegalPkgs" value="autovalue.shaded, avro.shaded, bk-shade, com.google.api.client.repackaged, com.google.appengine.repackaged, io.netty.util.internal"/>
  84. </module>
  85. <module name="RedundantModifier">
  86. <!-- Checks for redundant modifiers on various symbol definitions.
  87. See: http://checkstyle.sourceforge.net/config_modifier.html#RedundantModifier
  88. -->
  89. <property name="tokens" value="METHOD_DEF, VARIABLE_DEF, ANNOTATION_FIELD_DEF, INTERFACE_DEF, CLASS_DEF, ENUM_DEF"/>
  90. </module>
  91. <!--
  92. IllegalImport cannot blacklist classes, and c.g.api.client.util is used for some shaded
  93. code and some useful code. So we need to fall back to Regexp.
  94. -->
  95. <module name="RegexpSinglelineJava">
  96. <property name="format" value="com\.google\.api\.client\.util\.(ByteStreams|Charsets|Collections2|Joiner|Lists|Maps|Objects|Preconditions|Sets|Strings|Throwables)"/>
  97. </module>
  98. <!--
  99. Require static importing from Preconditions.
  100. -->
  101. <module name="RegexpSinglelineJava">
  102. <property name="format" value="^import com.google.common.base.Preconditions;$"/>
  103. <property name="message" value="Static import functions from Guava Preconditions"/>
  104. </module>
  105. <module name="UnusedImports">
  106. <property name="severity" value="error"/>
  107. <property name="processJavadoc" value="true"/>
  108. <message key="import.unused"
  109. value="Unused import: {0}."/>
  110. </module>
  111. <!--
  112. JAVADOC CHECKS
  113. -->
  114. <!-- Checks for Javadoc comments. -->
  115. <!-- See https://checkstyle.sourceforge.io/config_javadoc.html -->
  116. <module name="JavadocMethod">
  117. <property name="scope" value="protected"/>
  118. <property name="severity" value="error"/>
  119. <property name="allowMissingParamTags" value="true"/>
  120. <property name="allowMissingReturnTag" value="true"/>
  121. </module>
  122. <!-- Check that paragraph tags are used correctly in Javadoc. -->
  123. <module name="JavadocParagraph"/>
  124. <module name="JavadocType">
  125. <property name="scope" value="protected"/>
  126. <property name="severity" value="error"/>
  127. <property name="allowMissingParamTags" value="true"/>
  128. </module>
  129. <module name="JavadocStyle">
  130. <property name="severity" value="error"/>
  131. <property name="checkHtml" value="true"/>
  132. </module>
  133. <!--
  134. NAMING CHECKS
  135. -->
  136. <!-- Item 38 - Adhere to generally accepted naming conventions -->
  137. <module name="PackageName">
  138. <!-- Validates identifiers for package names against the
  139. supplied expression. -->
  140. <!-- Here the default checkstyle rule restricts package name parts to
  141. seven characters, this is not in line with common practice at Google.
  142. -->
  143. <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,})*$"/>
  144. <property name="severity" value="error"/>
  145. </module>
  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="error"/>
  151. </module>
  152. <module name="ConstantNameCheck">
  153. <!-- Validates non-private, static, final fields against the supplied
  154. public/package final fields "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$". -->
  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="false"/>
  160. <property name="format" value="^([A-Z][A-Za-z0-9_]*|FLAG_.*)$"/>
  161. <message key="name.invalidPattern"
  162. value="Variable ''{0}'' should be in ALL_CAPS (if it is a constant) or be private (otherwise)."/>
  163. <property name="severity" value="error"/>
  164. </module>
  165. <module name="StaticVariableNameCheck">
  166. <!-- Validates static, non-final fields against the supplied
  167. expression "^[a-z][a-zA-Z0-9]*_?$". -->
  168. <metadata name="altname" value="StaticVariableName"/>
  169. <property name="applyToPublic" value="true"/>
  170. <property name="applyToProtected" value="true"/>
  171. <property name="applyToPackage" value="true"/>
  172. <property name="applyToPrivate" value="true"/>
  173. <property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
  174. <property name="severity" value="error"/>
  175. </module>
  176. <module name="MemberNameCheck">
  177. <!-- Validates non-static members against the supplied expression. -->
  178. <metadata name="altname" value="MemberName"/>
  179. <property name="applyToPublic" value="true"/>
  180. <property name="applyToProtected" value="true"/>
  181. <property name="applyToPackage" value="true"/>
  182. <property name="applyToPrivate" value="true"/>
  183. <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
  184. <property name="severity" value="error"/>
  185. </module>
  186. <module name="MethodNameCheck">
  187. <!-- Validates identifiers for method names. -->
  188. <metadata name="altname" value="MethodName"/>
  189. <property name="format" value="(^[a-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$|Void)"/>
  190. <property name="severity" value="error"/>
  191. </module>
  192. <module name="ParameterName">
  193. <!-- Validates identifiers for method parameters against the
  194. expression "^[a-z][a-zA-Z0-9]*$". -->
  195. <property name="severity" value="error"/>
  196. </module>
  197. <module name="LocalFinalVariableName">
  198. <!-- Validates identifiers for local final variables against the
  199. expression "^[a-z][a-zA-Z0-9]*$". -->
  200. <property name="severity" value="error"/>
  201. </module>
  202. <module name="LocalVariableName">
  203. <!-- Validates identifiers for local variables against the
  204. expression "^[a-z][a-zA-Z0-9]*$". -->
  205. <property name="severity" value="error"/>
  206. </module>
  207. <!-- Type parameters must be either one of the four blessed letters
  208. T, K, V, W, X or else be capital-case terminated with a T,
  209. such as MyGenericParameterT -->
  210. <module name="ClassTypeParameterName">
  211. <property name="format" value="^(((T|K|V|W|X|R)[0-9]*)|([A-Z][a-z][a-zA-Z]*))$"/>
  212. <property name="severity" value="error"/>
  213. </module>
  214. <module name="MethodTypeParameterName">
  215. <property name="format" value="^(((T|K|V|W|X|R)[0-9]*)|([A-Z][a-z][a-zA-Z]*T))$"/>
  216. <property name="severity" value="error"/>
  217. </module>
  218. <module name="InterfaceTypeParameterName">
  219. <property name="format" value="^(((T|K|V|W|X|R)[0-9]*)|([A-Z][a-z][a-zA-Z]*T))$"/>
  220. <property name="severity" value="error"/>
  221. </module>
  222. <module name="LeftCurly">
  223. <!-- Checks for placement of the left curly brace ('{'). -->
  224. <property name="severity" value="error"/>
  225. </module>
  226. <module name="RightCurly">
  227. <!-- Checks right curlies on CATCH, ELSE, and TRY blocks are on
  228. the same line. e.g., the following example is fine:
  229. <pre>
  230. if {
  231. ...
  232. } else
  233. </pre>
  234. -->
  235. <!-- This next example is not fine:
  236. <pre>
  237. if {
  238. ...
  239. }
  240. else
  241. </pre>
  242. -->
  243. <property name="option" value="same"/>
  244. <property name="severity" value="error"/>
  245. </module>
  246. <!-- Checks for braces around if and else blocks -->
  247. <module name="NeedBraces">
  248. <property name="severity" value="error"/>
  249. <property name="tokens" value="LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
  250. </module>
  251. <module name="UpperEll">
  252. <!-- Checks that long constants are defined with an upper ell.-->
  253. <property name="severity" value="error"/>
  254. </module>
  255. <module name="FallThrough">
  256. <!-- Warn about falling through to the next case statement. Similar to
  257. javac -Xlint:fallthrough, but the check is suppressed if a single-line comment
  258. on the last non-blank line preceding the fallen-into case contains 'fall through' (or
  259. some other variants that we don't publicized to promote consistency).
  260. -->
  261. <property name="reliefPattern"
  262. value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
  263. <property name="severity" value="error"/>
  264. </module>
  265. <!-- Checks for over-complicated boolean expressions. -->
  266. <module name="SimplifyBooleanExpression"/>
  267. <!-- Detects empty statements (standalone ";" semicolon). -->
  268. <module name="EmptyStatement"/>
  269. <!--
  270. MODIFIERS CHECKS
  271. -->
  272. <module name="ModifierOrder">
  273. <!-- Warn if modifier order is inconsistent with JLS3 8.1.1, 8.3.1, and
  274. 8.4.3. The prescribed order is:
  275. public, protected, private, abstract, static, final, transient, volatile,
  276. synchronized, native, strictfp
  277. -->
  278. <property name="severity" value="error"/>
  279. </module>
  280. <!--
  281. WHITESPACE CHECKS
  282. -->
  283. <module name="WhitespaceAround">
  284. <!-- Checks that various tokens are surrounded by whitespace.
  285. This includes most binary operators and keywords followed
  286. by regular or curly braces.
  287. -->
  288. <property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR,
  289. BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN,
  290. EQUAL, GE, GT, LAND, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
  291. LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
  292. LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
  293. MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION,
  294. SL, SL_ASSIGN, SR_ASSIGN, STAR, STAR_ASSIGN"/>
  295. <property name="severity" value="error"/>
  296. </module>
  297. <module name="WhitespaceAfter">
  298. <!-- Checks that commas, semicolons and typecasts are followed by
  299. whitespace.
  300. -->
  301. <property name="tokens" value="COMMA, SEMI, TYPECAST"/>
  302. </module>
  303. <module name="NoWhitespaceAfter">
  304. <!-- Checks that there is no whitespace after various unary operators.
  305. Linebreaks are allowed.
  306. -->
  307. <property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS,
  308. UNARY_PLUS"/>
  309. <property name="allowLineBreaks" value="true"/>
  310. <property name="severity" value="error"/>
  311. </module>
  312. <module name="NoWhitespaceBefore">
  313. <!-- Checks that there is no whitespace before various unary operators.
  314. Linebreaks are allowed.
  315. -->
  316. <property name="tokens" value="SEMI, DOT, POST_DEC, POST_INC"/>
  317. <property name="allowLineBreaks" value="true"/>
  318. <property name="severity" value="error"/>
  319. </module>
  320. <module name="OperatorWrap">
  321. <!-- Checks that operators like + and ? appear at newlines rather than
  322. at the end of the previous line.
  323. -->
  324. <property name="option" value="NL"/>
  325. <property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL,
  326. GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD,
  327. NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
  328. </module>
  329. <module name="OperatorWrap">
  330. <!-- Checks that assignment operators are at the end of the line. -->
  331. <property name="option" value="eol"/>
  332. <property name="tokens" value="ASSIGN"/>
  333. </module>
  334. <module name="ParenPad">
  335. <!-- Checks that there is no whitespace before close parens or after
  336. open parens.
  337. -->
  338. <property name="severity" value="error"/>
  339. </module>
  340. </module>
  341. <!--
  342. LENGTH and CODING CHECKS
  343. -->
  344. <module name="LineLength">
  345. <!-- Checks if a line is too long. -->
  346. <property name="max" value="120"/>
  347. <property name="severity" value="error"/>
  348. <!--
  349. The default ignore pattern exempts the following elements:
  350. - import statements
  351. - long URLs inside comments
  352. -->
  353. <property name="ignorePattern"
  354. value="^(package .*;\s*)|(import .*;\s*)|( *\* .*https?://.*)$"/>
  355. </module>
  356. </module>