Skip to content

Commit 611a083

Browse files
author
Sandrine Perrin
committed
ADD: pluging for static code analysis with checkstyle (use google configuration), pmd and findbugs.
1 parent a0bd412 commit 611a083

File tree

3 files changed

+420
-0
lines changed

3 files changed

+420
-0
lines changed

checkstyle_google.xml

+336
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,336 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
5+
6+
<!-- This is a checkstyle configuration file. For descriptions of
7+
what the following rules do, please see the checkstyle configuration
8+
page at http://checkstyle.sourceforge.net/config.html -->
9+
10+
<module name="Checker">
11+
12+
13+
<module name="RegexpSingleline">
14+
<!-- Requires a Google copyright notice in each file.
15+
Code intended to be open-sourced may have a multi-line copyright
16+
notice, so that this required text appears on the second line:
17+
<pre>
18+
/*
19+
* Copyright 2008 Google Inc.
20+
*
21+
* (details of open-source license...)
22+
</pre>
23+
-->
24+
<property name="format"
25+
value="^(//| \*) Copyright (\([cC]\) )?[\d]{4}(\-[\d]{4})? (Google Inc\.).*$" />
26+
<property name="minimum" value="1" />
27+
<property name="maximum" value="10" />
28+
<property name="message" value="Google copyright is missing or malformed." />
29+
<property name="severity" value="error" />
30+
</module>
31+
32+
<module name="FileTabCharacter">
33+
<!-- Checks that there are no tab characters in the file.
34+
-->
35+
</module>
36+
37+
<module name="NewlineAtEndOfFile"/>
38+
39+
<module name="RegexpSingleline">
40+
<!-- Checks that FIXME is not used in comments. TODO is preferred.
41+
-->
42+
<property name="format" value="((//.*)|(\*.*))FIXME" />
43+
<property name="message" value='TODO is preferred to FIXME. e.g. "TODO(johndoe): Refactor when v2 is released."' />
44+
</module>
45+
46+
<module name="RegexpSingleline">
47+
<!-- Checks that TODOs are named. (Actually, just that they are followed
48+
by an open paren.)
49+
-->
50+
<property name="format" value="((//.*)|(\*.*))TODO[^(]" />
51+
<property name="message" value='All TODOs should be named. e.g. "TODO(johndoe): Refactor when v2 is released."' />
52+
</module>
53+
54+
<!-- All Java AST specific tests live under TreeWalker module. -->
55+
<module name="TreeWalker">
56+
57+
<!--
58+
59+
IMPORT CHECKS
60+
61+
-->
62+
63+
<module name="RedundantImport">
64+
<!-- Checks for redundant import statements. -->
65+
<property name="severity" value="error"/>
66+
</module>
67+
68+
<module name="ImportOrder">
69+
<!-- Checks for out of order import statements. -->
70+
71+
<property name="severity" value="warning"/>
72+
<property name="groups" value="com.google,android,junit,net,org,java,javax"/>
73+
<!-- This ensures that static imports go first. -->
74+
<property name="option" value="top"/>
75+
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
76+
</module>
77+
78+
<!--
79+
80+
JAVADOC CHECKS
81+
82+
-->
83+
84+
<!-- Checks for Javadoc comments. -->
85+
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
86+
<module name="JavadocMethod">
87+
<property name="scope" value="protected"/>
88+
<property name="severity" value="warning"/>
89+
<property name="allowMissingJavadoc" value="true"/>
90+
<property name="allowMissingParamTags" value="true"/>
91+
<property name="allowMissingReturnTag" value="true"/>
92+
<property name="allowMissingThrowsTags" value="true"/>
93+
<property name="allowThrowsTagsForSubclasses" value="true"/>
94+
<property name="allowUndeclaredRTE" value="true"/>
95+
</module>
96+
97+
<module name="JavadocType">
98+
<property name="scope" value="protected"/>
99+
<property name="severity" value="error"/>
100+
</module>
101+
102+
<module name="JavadocStyle">
103+
<property name="severity" value="warning"/>
104+
</module>
105+
106+
<!--
107+
108+
NAMING CHECKS
109+
110+
-->
111+
112+
<!-- Item 38 - Adhere to generally accepted naming conventions -->
113+
114+
<module name="PackageName">
115+
<!-- Validates identifiers for package names against the
116+
supplied expression. -->
117+
<!-- Here the default checkstyle rule restricts package name parts to
118+
seven characters, this is not in line with common practice at Google.
119+
-->
120+
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,})*$"/>
121+
<property name="severity" value="warning"/>
122+
</module>
123+
124+
<module name="TypeNameCheck">
125+
<!-- Validates static, final fields against the
126+
expression "^[A-Z][a-zA-Z0-9]*$". -->
127+
<metadata name="altname" value="TypeName"/>
128+
<property name="severity" value="warning"/>
129+
</module>
130+
131+
<module name="ConstantNameCheck">
132+
<!-- Validates non-private, static, final fields against the supplied
133+
public/package final fields "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$". -->
134+
<metadata name="altname" value="ConstantName"/>
135+
<property name="applyToPublic" value="true"/>
136+
<property name="applyToProtected" value="true"/>
137+
<property name="applyToPackage" value="true"/>
138+
<property name="applyToPrivate" value="false"/>
139+
<property name="format" value="^([A-Z][A-Z0-9]*(_[A-Z0-9]+)*|FLAG_.*)$"/>
140+
<message key="name.invalidPattern"
141+
value="Variable ''{0}'' should be in ALL_CAPS (if it is a constant) or be private (otherwise)."/>
142+
<property name="severity" value="warning"/>
143+
</module>
144+
145+
<module name="StaticVariableNameCheck">
146+
<!-- Validates static, non-final fields against the supplied
147+
expression "^[a-z][a-zA-Z0-9]*_?$". -->
148+
<metadata name="altname" value="StaticVariableName"/>
149+
<property name="applyToPublic" value="true"/>
150+
<property name="applyToProtected" value="true"/>
151+
<property name="applyToPackage" value="true"/>
152+
<property name="applyToPrivate" value="true"/>
153+
<property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
154+
<property name="severity" value="warning"/>
155+
</module>
156+
157+
<module name="MemberNameCheck">
158+
<!-- Validates non-static members against the supplied expression. -->
159+
<metadata name="altname" value="MemberName"/>
160+
<property name="applyToPublic" value="true"/>
161+
<property name="applyToProtected" value="true"/>
162+
<property name="applyToPackage" value="true"/>
163+
<property name="applyToPrivate" value="true"/>
164+
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
165+
<property name="severity" value="warning"/>
166+
</module>
167+
168+
<module name="MethodNameCheck">
169+
<!-- Validates identifiers for method names. -->
170+
<metadata name="altname" value="MethodName"/>
171+
<property name="format" value="^[a-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$"/>
172+
<property name="severity" value="warning"/>
173+
</module>
174+
175+
<module name="ParameterName">
176+
<!-- Validates identifiers for method parameters against the
177+
expression "^[a-z][a-zA-Z0-9]*$". -->
178+
<property name="severity" value="warning"/>
179+
</module>
180+
181+
<module name="LocalFinalVariableName">
182+
<!-- Validates identifiers for local final variables against the
183+
expression "^[a-z][a-zA-Z0-9]*$". -->
184+
<property name="severity" value="warning"/>
185+
</module>
186+
187+
<module name="LocalVariableName">
188+
<!-- Validates identifiers for local variables against the
189+
expression "^[a-z][a-zA-Z0-9]*$". -->
190+
<property name="severity" value="warning"/>
191+
</module>
192+
193+
194+
<!--
195+
196+
LENGTH and CODING CHECKS
197+
198+
-->
199+
200+
<module name="LineLength">
201+
<!-- Checks if a line is too long. -->
202+
<property name="max" value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.max}" default="100"/>
203+
<property name="severity" value="error"/>
204+
205+
<!--
206+
The default ignore pattern exempts the following elements:
207+
- import statements
208+
- long URLs inside comments
209+
-->
210+
211+
<property name="ignorePattern"
212+
value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.ignorePattern}"
213+
default="^(package .*;\s*)|(import .*;\s*)|( *\* *https?://.*)$"/>
214+
</module>
215+
216+
<module name="LeftCurly">
217+
<!-- Checks for placement of the left curly brace ('{'). -->
218+
<property name="severity" value="warning"/>
219+
</module>
220+
221+
<module name="RightCurly">
222+
<!-- Checks right curlies on CATCH, ELSE, and TRY blocks are on
223+
the same line. e.g., the following example is fine:
224+
<pre>
225+
if {
226+
...
227+
} else
228+
</pre>
229+
-->
230+
<!-- This next example is not fine:
231+
<pre>
232+
if {
233+
...
234+
}
235+
else
236+
</pre>
237+
-->
238+
<property name="option" value="same"/>
239+
<property name="severity" value="warning"/>
240+
</module>
241+
242+
<!-- Checks for braces around if and else blocks -->
243+
<module name="NeedBraces">
244+
<property name="severity" value="warning"/>
245+
<property name="tokens" value="LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
246+
</module>
247+
248+
<module name="UpperEll">
249+
<!-- Checks that long constants are defined with an upper ell.-->
250+
<property name="severity" value="error"/>
251+
</module>
252+
253+
<module name="FallThrough">
254+
<!-- Warn about falling through to the next case statement. Similar to
255+
javac -Xlint:fallthrough, but the check is suppressed if a single-line comment
256+
on the last non-blank line preceding the fallen-into case contains 'fall through' (or
257+
some other variants which we don't publicized to promote consistency).
258+
-->
259+
<property name="reliefPattern"
260+
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
261+
<property name="severity" value="error"/>
262+
</module>
263+
264+
265+
<!--
266+
267+
MODIFIERS CHECKS
268+
269+
-->
270+
271+
<module name="ModifierOrder">
272+
<!-- Warn if modifier order is inconsistent with JLS3 8.1.1, 8.3.1, and
273+
8.4.3. The prescribed order is:
274+
public, protected, private, abstract, static, final, transient, volatile,
275+
synchronized, native, strictfp
276+
-->
277+
</module>
278+
279+
280+
<!--
281+
282+
WHITESPACE CHECKS
283+
284+
-->
285+
286+
<module name="WhitespaceAround">
287+
<!-- Checks that various tokens are surrounded by whitespace.
288+
This includes most binary operators and keywords followed
289+
by regular or curly braces.
290+
-->
291+
<property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR,
292+
BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN,
293+
EQUAL, GE, GT, LAND, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
294+
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
295+
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
296+
MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION,
297+
SL, SL_ASSIGN, SR_ASSIGN, STAR, STAR_ASSIGN"/>
298+
<property name="severity" value="error"/>
299+
</module>
300+
301+
<module name="WhitespaceAfter">
302+
<!-- Checks that commas, semicolons and typecasts are followed by
303+
whitespace.
304+
-->
305+
<property name="tokens" value="COMMA, SEMI, TYPECAST"/>
306+
</module>
307+
308+
<module name="NoWhitespaceAfter">
309+
<!-- Checks that there is no whitespace after various unary operators.
310+
Linebreaks are allowed.
311+
-->
312+
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS,
313+
UNARY_PLUS"/>
314+
<property name="allowLineBreaks" value="true"/>
315+
<property name="severity" value="error"/>
316+
</module>
317+
318+
<module name="NoWhitespaceBefore">
319+
<!-- Checks that there is no whitespace before various unary operators.
320+
Linebreaks are allowed.
321+
-->
322+
<property name="tokens" value="SEMI, DOT, POST_DEC, POST_INC"/>
323+
<property name="allowLineBreaks" value="true"/>
324+
<property name="severity" value="error"/>
325+
</module>
326+
327+
<module name="ParenPad">
328+
<!-- Checks that there is no whitespace before close parens or after
329+
open parens.
330+
-->
331+
<property name="severity" value="warning"/>
332+
</module>
333+
334+
</module>
335+
</module>
336+

pmd-rules.xml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Custom ruleset" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
5+
6+
<!-- TEST CONFIG FILE -->
7+
8+
<description>
9+
This ruleset checks my code for bad stuff
10+
</description>
11+
12+
<!-- We'll use the entire 'strings' ruleset -->
13+
<rule ref="rulesets/java/strings.xml" />
14+
15+
<!-- Here's some rules we'll specify one at a time -->
16+
<rule ref="rulesets/java/unusedcode.xml/UnusedLocalVariable" />
17+
<rule ref="rulesets/java/unusedcode.xml/UnusedPrivateField" />
18+
<rule ref="rulesets/java/imports.xml/DuplicateImports" />
19+
<rule ref="rulesets/java/basic.xml/UnnecessaryConversionTemporary" />
20+
21+
22+
<!-- We want to customize this rule a bit, change the message and raise the priority -->
23+
<rule
24+
ref="rulesets/java/basic.xml/EmptyCatchBlock"
25+
message="Must handle exceptions">
26+
<priority>2</priority>
27+
</rule>
28+
29+
<!-- Now we'll customize a rule's property value -->
30+
<rule ref="rulesets/java/codesize.xml/CyclomaticComplexity">
31+
<properties>
32+
<property name="reportLevel" value="5"/>
33+
</properties>
34+
</rule>
35+
36+
<!-- We want everything from braces.xml except WhileLoopsMustUseBraces -->
37+
<rule ref="rulesets/java/braces.xml">
38+
<exclude name="WhileLoopsMustUseBraces"/>
39+
</rule>
40+
</ruleset>

0 commit comments

Comments
 (0)