Skip to content

Commit 6fdda56

Browse files
committed
add checkstyle
1 parent 6303c14 commit 6fdda56

18 files changed

+545
-247
lines changed

build/check-style-suppression.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN" "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
3+
<suppressions>
4+
</suppressions>

build/check-style.xml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
3+
<!--refer to http://checkstyle.sourceforge.net/availablechecks.html-->
4+
<module name="Checker">
5+
<module name="RegexpSingleline">
6+
<!-- Checks that FIXME is not used in comments. TODO is preferred. -->
7+
<property name="format" value="((//.*)|(\*.*))FIXME"/>
8+
<property name="message" value='TODO is preferred to FIXME. e.g. "TODO(johndoe): Refactor when v2 is released."'/>
9+
</module>
10+
<module name="RegexpSingleline">
11+
<!-- Checks that TODOs are named. (Actually, just that they are followed by an open paren.) -->
12+
<property name="format" value="((//.*)|(\*.*))TODO[^(]"/>
13+
<property name="message" value='All TODOs should be named. e.g. "TODO(johndoe): Refactor when v2 is released."'/>
14+
</module>
15+
<module name="TreeWalker">
16+
<!--Checks the placement of left curly braces on types, methods and other blocks:-->
17+
<module name="LeftCurly"/>
18+
19+
<!--Checks the placement of right curly braces.-->
20+
<module name="RightCurly"/>
21+
22+
<!--Detects empty statements (standalone ';').-->
23+
<module name="EmptyStatement"/>
24+
25+
<!--Checks that classes that override equals() also override hashCode().-->
26+
<module name="EqualsHashCode"/>
27+
28+
<!--Checks that any combination of String literals with optional assignment is on the left side of an equals() comparison.-->
29+
<module name="EqualsAvoidNull"/>
30+
31+
<!--Restricts the number of executable statements to a specified limit-->
32+
<module name="ExecutableStatementCount">
33+
<property name="max" value="40"/>
34+
</module>
35+
36+
<!--Checks for long anonymous inner classes.-->
37+
<module name="AnonInnerLength">
38+
<property name="max" value="15"/>
39+
</module>
40+
41+
<!--Checks for long methods.-->
42+
<module name="MethodLength">
43+
<property name="countEmpty" value="false"/>
44+
<property name="max" value="50"/>
45+
</module>
46+
47+
<!--Checks for unused import statements.-->
48+
<module name="UnusedImports"/>
49+
50+
<!--Checks for imports that are redundant.-->
51+
<module name="RedundantImport"/>
52+
53+
<!--Implements Bloch, Effective Java, Item 17 - Use Interfaces only to define types.-->
54+
<module name="InterfaceIsType"/>
55+
56+
<!--Checks that the order of modifiers conforms to the suggestions in the Java Language specification, sections 8.1.1, 8.3.1 and 8.4.3.-->
57+
<module name="ModifierOrder"/>
58+
59+
<!--Checks there is only one statement per line.-->
60+
<module name="OneStatementPerLine"/>
61+
62+
<!--Checks line wrapping for operators.-->
63+
<module name="OperatorWrap"/>
64+
65+
<!-- naming begin -->
66+
<module name="PackageName">
67+
<property name="format" value="^[a-z][a-z0-9\.]*$"/>
68+
</module>
69+
70+
<module name="TypeName">
71+
<property name="format" value="^[A-Z][a-zA-Z0-9]*$"/>
72+
</module>
73+
74+
<module name="MemberName">
75+
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
76+
</module>
77+
78+
<module name="MethodName">
79+
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
80+
</module>
81+
82+
<module name="ParameterName">
83+
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
84+
</module>
85+
86+
<module name="ConstantName"/>
87+
88+
<module name="StaticVariableName"/>
89+
90+
<module name="LocalVariableName"/>
91+
92+
<module name="ClassTypeParameterName"/>
93+
94+
<module name="MethodTypeParameterName"/>
95+
<!-- naming end -->
96+
97+
<!--Checks the number of parameters that a method or constructor has.-->
98+
<module name="ParameterNumber">
99+
<property name="max" value="5"/>
100+
</module>
101+
102+
<module name="Indentation"/>
103+
104+
<!--Checks that there is no whitespace before a token.-->
105+
<module name="NoWhitespaceBefore">
106+
<property name="tokens" value="SEMI, DOT, POST_DEC, POST_INC"/>
107+
<property name="allowLineBreaks" value="true"/>
108+
</module>
109+
110+
<!--Checks that there is no whitespace after a token.-->
111+
<module name="NoWhitespaceAfter">
112+
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS"/>
113+
</module>
114+
115+
<!--Checks that a token is surrounded by whitespace. Empty constructor and method bodies (blocks) of the form-->
116+
<module name="WhitespaceAround">
117+
<property name="tokens"
118+
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, TYPE_EXTENSION_AND"/>
119+
</module>
120+
121+
<!--Checks that a token is followed by whitespace, with the exception that it does not check for whitespace after the semicolon of an empty for iterator.-->
122+
<module name="WhitespaceAfter"/>
123+
124+
<!--Checks that the whitespace around the Generic tokens < and > are correct to the typical convention.-->
125+
<module name="GenericWhitespace"/>
126+
127+
<!--Checks the padding between the identifier of a method definition, constructor definition, method call, or constructor invocation; and the left parenthesis of the parameter list. -->
128+
<module name="MethodParamPad"/>
129+
130+
<!--Checks if unnecessary parentheses are used in a statement or expression.-->
131+
<module name="UnnecessaryParentheses"/>
132+
133+
<!--Detects uncommented main methods.-->
134+
<module name="UncommentedMain"/>
135+
136+
<!--Checks for overly complicated boolean expressions.-->
137+
<module name="SimplifyBooleanExpression"/>
138+
139+
<!--Checks for overly complicated boolean return statements.-->
140+
<module name="SimplifyBooleanReturn"/>
141+
142+
<!--Restricts nested for blocks to a specified depth (default = 1).-->
143+
<module name="NestedForDepth"/>
144+
145+
<!--Restricts nested if-else blocks to a specified depth (default = 1).-->
146+
<module name="NestedIfDepth"/>
147+
148+
<!--Restricts nested try-catch-finally blocks to a specified depth (default = 1).-->
149+
<module name="NestedTryDepth">
150+
<property name="max" value="0"/>
151+
</module>
152+
153+
<!--Checks that each variable declaration is in its own statement and on its own line.-->
154+
<module name="MultipleVariableDeclarations"/>
155+
156+
<!--Checks that switch statement has "default" clause.-->
157+
<module name="MissingSwitchDefault"/>
158+
</module>
159+
160+
<!--Checks for long source files.-->
161+
<module name="FileLength">
162+
<property name="max" value="500"/>
163+
</module>
164+
165+
<!--Checks to see if a file contains a tab character.-->
166+
<module name="FileTabCharacter"/>
167+
</module>

build/find-bugs-exclude-filter.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<FindBugsFilter>
2+
<!--refer to http://findbugs.sourceforge.net/bugDescriptions.html for all Bug code-->
3+
<Match>
4+
<!--RV: Method ignores exceptional return value, this is OK for us, a lot of 3rd party lib results in side effect (which is not good practice), like File.mkdirs()-->
5+
<!--EI: May expose internal representation by returning reference to mutable object (EI_EXPOSE_REP)-->
6+
<!--EI2: May expose internal representation by incorporating reference to mutable object (EI_EXPOSE_REP2)-->
7+
<Bug code="RV,EI,EI2"/>
8+
</Match>
9+
</FindBugsFilter>

build/pmd.xml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
4+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
5+
<description>PMD rules</description>
6+
7+
<rule ref="rulesets/java/basic.xml">
8+
<exclude name="AvoidUsingHardCodedIP"/>
9+
<!--flaw/buggy rules-->
10+
<exclude name="CheckResultSet"/>
11+
<exclude name="AvoidThreadGroup"/>
12+
</rule>
13+
14+
<rule ref="rulesets/java/strings.xml">
15+
<exclude name="AvoidDuplicateLiterals"/>
16+
</rule>
17+
18+
<rule ref="rulesets/java/unusedcode.xml"/>
19+
20+
<rule ref="rulesets/java/imports.xml/DuplicateImports"/>
21+
<rule ref="rulesets/java/imports.xml/DontImportJavaLang"/>
22+
<rule ref="rulesets/java/imports.xml/UnusedImports"/>
23+
<rule ref="rulesets/java/imports.xml/ImportFromSamePackage"/>
24+
25+
<rule ref="rulesets/java/typeresolution.xml/LooseCoupling"/>
26+
<rule ref="rulesets/java/typeresolution.xml/CloneMethodMustImplementCloneable"/>
27+
<rule ref="rulesets/java/typeresolution.xml/UnusedImports"/>
28+
29+
<rule ref="rulesets/java/controversial.xml/UnnecessaryConstructor"/>
30+
<rule ref="rulesets/java/controversial.xml/AssignmentInOperand"/>
31+
<rule ref="rulesets/java/controversial.xml/DontImportSun"/>
32+
<rule ref="rulesets/java/controversial.xml/UnnecessaryParentheses"/>
33+
<rule ref="rulesets/java/controversial.xml/DoNotCallGarbageCollectionExplicitly"/>
34+
35+
<rule ref="rulesets/java/coupling.xml/LooseCoupling"/>
36+
37+
<rule ref="rulesets/java/design.xml/SimplifyBooleanReturns"/>
38+
<rule ref="rulesets/java/design.xml/SimplifyBooleanExpressions"/>
39+
<rule ref="rulesets/java/design.xml/SwitchStmtsShouldHaveDefault"/>
40+
<rule ref="rulesets/java/design.xml/AvoidDeeplyNestedIfStmts"/>
41+
<rule ref="rulesets/java/design.xml/AvoidReassigningParameters"/>
42+
<rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod"/>
43+
<rule ref="rulesets/java/design.xml/AccessorClassGeneration"/>
44+
<rule ref="rulesets/java/design.xml/FinalFieldCouldBeStatic"/>
45+
<rule ref="rulesets/java/design.xml/CloseResource"/>
46+
<rule ref="rulesets/java/design.xml/NonStaticInitializer"/>
47+
<rule ref="rulesets/java/design.xml/DefaultLabelNotLastInSwitchStmt"/>
48+
<rule ref="rulesets/java/design.xml/NonCaseLabelInSwitchStatement"/>
49+
<rule ref="rulesets/java/design.xml/OptimizableToArrayCall"/>
50+
<rule ref="rulesets/java/design.xml/BadComparison"/>
51+
<rule ref="rulesets/java/design.xml/EqualsNull"/>
52+
<rule ref="rulesets/java/design.xml/InstantiationToGetClass"/>
53+
<rule ref="rulesets/java/design.xml/IdempotentOperations"/>
54+
<rule ref="rulesets/java/design.xml/ImmutableField"/>
55+
<rule ref="rulesets/java/design.xml/AvoidProtectedFieldInFinalClass"/>
56+
<rule ref="rulesets/java/design.xml/MissingBreakInSwitch"/>
57+
<rule ref="rulesets/java/design.xml/UseNotifyAllInsteadOfNotify"/>
58+
<rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause"/>
59+
<rule ref="rulesets/java/design.xml/SimplifyConditional"/>
60+
<rule ref="rulesets/java/design.xml/CompareObjectsWithEquals"/>
61+
<rule ref="rulesets/java/design.xml/PositionLiteralsFirstInComparisons"/>
62+
<rule ref="rulesets/java/design.xml/UnnecessaryLocalBeforeReturn"/>
63+
<rule ref="rulesets/java/design.xml/AvoidConstantsInterface"/>
64+
<rule ref="rulesets/java/design.xml/UnsynchronizedStaticDateFormatter"/>
65+
<rule ref="rulesets/java/design.xml/PreserveStackTrace"/>
66+
<rule ref="rulesets/java/design.xml/UseCollectionIsEmpty"/>
67+
<rule ref="rulesets/java/design.xml/ClassWithOnlyPrivateConstructorsShouldBeFinal"/>
68+
<rule ref="rulesets/java/design.xml/SingularField"/>
69+
70+
<rule ref="rulesets/java/finalizers.xml/AvoidCallingFinalize"/>
71+
72+
<rule ref="rulesets/java/junit.xml/SimplifyBooleanAssertion"/>
73+
<rule ref="rulesets/java/junit.xml/UseAssertNullInsteadOfAssertTrue"/>
74+
<rule ref="rulesets/java/junit.xml/UseAssertSameInsteadOfAssertTrue"/>
75+
<rule ref="rulesets/java/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>
76+
<rule ref="rulesets/java/junit.xml/UnnecessaryBooleanAssertion"/>
77+
78+
<rule ref="rulesets/java/strictexception.xml/ExceptionAsFlowControl"/>
79+
<rule ref="rulesets/java/strictexception.xml/AvoidCatchingNPE"/>
80+
<rule ref="rulesets/java/strictexception.xml/AvoidThrowingNullPointerException"/>
81+
<rule ref="rulesets/java/strictexception.xml/DoNotExtendJavaLangError"/>
82+
<rule ref="rulesets/java/strictexception.xml/DoNotThrowExceptionInFinally"/>
83+
<rule ref="rulesets/java/strictexception.xml/AvoidThrowingNewInstanceOfSameException"/>
84+
</ruleset>

pom.xml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,65 @@
2222
<encoding>${project.build.sourceEncoding}</encoding>
2323
</configuration>
2424
</plugin>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-checkstyle-plugin</artifactId>
28+
<version>${plugin.checkstyle.version}</version>
29+
<configuration>
30+
<configLocation>${project.basedir}/build/check-style.xml</configLocation>
31+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
32+
<suppressionsLocation>${project.basedir}/build/check-style-suppression.xml</suppressionsLocation>
33+
<consoleOutput>true</consoleOutput>
34+
<failsOnError>true</failsOnError>
35+
</configuration>
36+
<executions>
37+
<execution>
38+
<phase>verify</phase>
39+
<goals>
40+
<goal>check</goal>
41+
</goals>
42+
</execution>
43+
</executions>
44+
</plugin>
45+
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-pmd-plugin</artifactId>
49+
<version>${plugin.pmd.version}</version>
50+
<configuration>
51+
<rulesets>
52+
<ruleset>build/pmd.xml</ruleset>
53+
</rulesets>
54+
<targetJdk>${project.build.jdk}</targetJdk>
55+
<verbose>true</verbose>
56+
</configuration>
57+
<executions>
58+
<execution>
59+
<phase>verify</phase>
60+
<goals>
61+
<goal>check</goal>
62+
<goal>cpd-check</goal>
63+
</goals>
64+
</execution>
65+
</executions>
66+
</plugin>
67+
68+
<plugin>
69+
<groupId>org.codehaus.mojo</groupId>
70+
<artifactId>findbugs-maven-plugin</artifactId>
71+
<version>${plugin.findbugs.version}</version>
72+
<configuration>
73+
<excludeFilterFile>build/find-bugs-exclude-filter.xml</excludeFilterFile>
74+
</configuration>
75+
<executions>
76+
<execution>
77+
<phase>verify</phase>
78+
<goals>
79+
<goal>check</goal>
80+
</goals>
81+
</execution>
82+
</executions>
83+
</plugin>
2584
</plugins>
2685
</build>
2786

@@ -50,6 +109,9 @@
50109
<gson.version>2.6.2</gson.version>
51110
<jackson-core.version>2.7.4</jackson-core.version>
52111
<aspectj.version>1.6.12</aspectj.version>
112+
<plugin.checkstyle.version>2.17</plugin.checkstyle.version>
113+
<plugin.pmd.version>3.5</plugin.pmd.version>
114+
<plugin.findbugs.version>3.0.1</plugin.findbugs.version>
53115
</properties>
54116

55117
<dependencies>

src/main/java/com/github/config/MainConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@Configuration
1515
public class MainConfig {
1616

17-
//TODO 填写公众号开发信息
17+
//TODO(user) 填写公众号开发信息
1818
//商站宝测试公众号 APP_ID
1919
protected static final String APP_ID = "";
2020
//商站宝测试公众号 APP_SECRET

src/main/java/com/github/config/MenuConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import me.chanjar.weixin.common.api.WxConsts;
44
import me.chanjar.weixin.common.bean.WxMenu;
5-
import me.chanjar.weixin.common.exception.WxErrorException;
65
import me.chanjar.weixin.mp.api.WxMpService;
76

87
/**
@@ -72,14 +71,14 @@ protected static WxMenu getMenu() {
7271
*
7372
* @param args
7473
*/
75-
public static void main(String[] args) {
74+
/*public static void main(String[] args) {
7675
MainConfig mainConfig = new MainConfig();
7776
WxMpService wxMpService = mainConfig.wxMpService();
7877
try {
7978
wxMpService.menuCreate(getMenu());
8079
} catch (WxErrorException e) {
8180
e.printStackTrace();
8281
}
83-
}
82+
}*/
8483

8584
}

0 commit comments

Comments
 (0)