Skip to content

Commit 69b6476

Browse files
committed
feature: upgrade alibaba-p3c to 2.0.0
1 parent 7021a1a commit 69b6476

File tree

10 files changed

+84
-31
lines changed

10 files changed

+84
-31
lines changed

code-format-checkstyle/src/main/resources/alibaba-p3c/java/ali-comment.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ruleset name="AlibabaJavaComments" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6-
6+
<description>AlibabaJavaComments</description>
77

88
<rule name="CommentsMustBeJavadocFormatRule" message="java.comment.CommentsMustBeJavadocFormatRule.rule.msg"
99
class="com.alibaba.p3c.pmd.lang.java.rule.comment.CommentsMustBeJavadocFormatRule">

code-format-checkstyle/src/main/resources/alibaba-p3c/java/ali-concurrent.xml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6+
<description>AlibabaJavaConcurrent</description>
67

78
<rule name="ThreadPoolCreationRule"
89
language="java"
@@ -116,10 +117,8 @@ Positive example 3:
116117
<example>
117118
<![CDATA[
118119
public class TimerTaskThread extends Thread {
119-
public TimerTaskThread() {
120-
super.setName("TimerTaskThread");
121-
// do something
122-
}
120+
public TimerTaskThread(){
121+
super.setName("TimerTaskThread"); …
123122
}
124123
]]>
125124
</example>
@@ -136,21 +135,20 @@ Positive example 3:
136135
<![CDATA[
137136
Positive example 1:
138137
private static final String FORMAT = "yyyy-MM-dd HH:mm:ss";
139-
public String getFormat(Date date) {
138+
public String getFormat(Date date){
140139
SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT);
141-
return dateFormat.format(date);
140+
return sdf.format(date);
142141
}
143142
]]>
144143
</example>
145144
<example>
146145
<![CDATA[
147146
Positive example 2:
148147
private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
149-
public void getFormat() {
150-
synchronized(SIMPLE_DATE_FORMAT) {
151-
SIMPLE_DATE_FORMAT.format(new Date());
152-
// do something
153-
}
148+
public void getFormat(){
149+
synchronized (sdf){
150+
sdf.format(new Date());
151+
….;
154152
}
155153
]]>
156154
</example>

code-format-checkstyle/src/main/resources/alibaba-p3c/java/ali-constant.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ruleset name="AlibabaJavaConstants" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6-
6+
<description>AlibabaJavaConstants</description>
77

88
<rule name="UpperEllRule"
99
message="java.constant.UpperEllRule.rule.msg"

code-format-checkstyle/src/main/resources/alibaba-p3c/java/ali-exception.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<ruleset name="AlibabaJavaExceptions" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6+
<description>AlibabaJavaExceptions</description>
67

78
<rule name="MethodReturnWrapperTypeRule"
89
language="java"

code-format-checkstyle/src/main/resources/alibaba-p3c/java/ali-flowcontrol.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<ruleset name="AlibabaJavaFlowControl" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6+
<description>AlibabaJavaFlowControl</description>
67

78
<rule name="SwitchStatementRule"
89
language="java"

code-format-checkstyle/src/main/resources/alibaba-p3c/java/ali-naming.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<ruleset name="AlibabaJavaNaming" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6+
<description>AlibabaJavaNaming</description>
67

78

89
<rule name="ClassNamingShouldBeCamelRule"

code-format-checkstyle/src/main/resources/alibaba-p3c/java/ali-oop.xml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<ruleset name="AlibabaJavaOop" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6+
<description>AlibabaJavaOop</description>
67

78
<rule name="EqualsAvoidNullRule"
89
language="java"
@@ -18,7 +19,7 @@
1819
System.out.println("hello world");
1920
}
2021
}
21-
]]>
22+
]]>
2223
</example>
2324
</rule>
2425

@@ -36,7 +37,7 @@
3637
if (a.equals(b)) {
3738
// code
3839
}
39-
]]>
40+
]]>
4041
</example>
4142
</rule>
4243

@@ -53,7 +54,7 @@
5354
String str;
5455
Integer a;
5556
}
56-
]]>
57+
]]>
5758
</example>
5859
</rule>
5960

@@ -69,7 +70,7 @@
6970
String str;
7071
Integer a;
7172
}
72-
]]>
73+
]]>
7374
</example>
7475
</rule>
7576

@@ -99,7 +100,7 @@
99100
return "Super{" + "firstName=" + firstName + '\'' + '}';
100101
}
101102
}
102-
]]>
103+
]]>
103104
</example>
104105
</rule>
105106

@@ -131,4 +132,26 @@ Positive example:
131132
</example>
132133
</rule>
133134

135+
<rule name="BigDecimalAvoidDoubleConstructorRule"
136+
language="java"
137+
message="java.oop.BigDecimalAvoidDoubleConstructorRule.rule.msg"
138+
class="com.alibaba.p3c.pmd.lang.java.rule.oop.BigDecimalAvoidDoubleConstructorRule">
139+
<description>java.oop.StringConcatRule.rule.msg.desc</description>
140+
<priority>3</priority>
141+
142+
<example>
143+
<![CDATA[
144+
Negative example:
145+
BigDecimal good1 = new BigDecimal(0.1);
146+
]]>
147+
</example>
148+
<example>
149+
<![CDATA[
150+
Positive example:
151+
BigDecimal good1 = new BigDecimal("0.1");
152+
BigDecimal good2 = BigDecimal.valueOf(0.1);
153+
]]>
154+
</example>
155+
</rule>
156+
134157
</ruleset>

code-format-checkstyle/src/main/resources/alibaba-p3c/java/ali-orm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<ruleset name="AlibabaJavaOrm" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6+
<description>AlibabaJavaOrm</description>
67

78
<rule name="IbatisMethodQueryForListRule"
89
language="java"

code-format-checkstyle/src/main/resources/alibaba-p3c/java/ali-other.xml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<ruleset name="AlibabaJavaOthers" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6+
<description>AlibabaJavaOthers</description>
67

78
<rule name="AvoidPatternCompileInMethodRule" language="java"
89
message="java.other.AvoidPatternCompileInMethodRule.rule.msg"
@@ -52,7 +53,7 @@
5253
long a = System.currentTimeMillis();
5354
// Negative example:
5455
long b = new Date().getTime();
55-
56+
5657
System.out.println(a);
5758
System.out.println(b);
5859
}
@@ -101,6 +102,32 @@ Negative example:
101102
<![CDATA[
102103
Positive example:
103104
SimpleDateFormat format = new SimpleDateFormat("YYYY-mm-dd HH:mm:ss");
105+
]]>
106+
</example>
107+
</rule>
108+
109+
<rule name="AvoidDoubleOrFloatEqualCompareRule" language="java"
110+
message="java.other.AvoidDoubleOrFloatEqualCompareRule.rule.msg"
111+
class="com.alibaba.p3c.pmd.lang.java.rule.other.AvoidDoubleOrFloatEqualCompareRule">
112+
<description>java.other.AvoidDoubleOrFloatEqualCompareRule.rule.desc</description>
113+
<priority>2</priority>
114+
<example>
115+
<![CDATA[
116+
Negative example:
117+
float g = 0.7f-0.6f;
118+
float h = 0.8f-0.7f;
119+
if (g == h) {
120+
System.out.println("true");
121+
}
122+
]]>
123+
</example>
124+
<example>
125+
<![CDATA[
126+
Positive example:
127+
double dis = 1e-6;
128+
double d1 = 0.0000001d;
129+
double d2 = 0d;
130+
System.out.println(Math.abs(d1 - d2) < dis);
104131
]]>
105132
</example>
106133
</rule>

code-format-checkstyle/src/main/resources/alibaba-p3c/java/ali-set.xml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
<ruleset name="AlibabaJavaSets" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
6-
6+
<description>AlibabaJavaSets</description>
7+
78
<rule name="ClassCastExceptionWithToArrayRule"
89
message="java.set.ClassCastExceptionWithToArrayRule.rule.msg"
910
class="com.alibaba.p3c.pmd.lang.java.rule.set.ClassCastExceptionWithToArrayRule">
1011
<priority>2</priority>
1112
<example>
12-
<![CDATA[
13+
<![CDATA[
1314
Negative example:
1415
Integer[] a = (Integer [])c.toArray();
1516
]]>
16-
</example>
17+
</example>
1718
<example>
1819
<![CDATA[
1920
Positive example:
@@ -27,7 +28,7 @@ Positive example:
2728
class="com.alibaba.p3c.pmd.lang.java.rule.set.UnsupportedExceptionWithModifyAsListRule">
2829
<priority>2</priority>
2930
<example>
30-
<![CDATA[
31+
<![CDATA[
3132
Positive example:
3233
List<String> t = Arrays.asList("a","b","c");
3334
//warn
@@ -46,7 +47,7 @@ Positive example:
4647
<description>java.set.ClassCastExceptionWithSubListToArrayListRule.rule.msg.desc</description>
4748
<priority>2</priority>
4849
<example>
49-
<![CDATA[
50+
<![CDATA[
5051
Negative example:
5152
List<String> list = new ArrayList<String>();
5253
list.add("22");
@@ -55,7 +56,7 @@ Negative example:
5556
]]>
5657
</example>
5758
<example>
58-
<![CDATA[
59+
<![CDATA[
5960
Positive example:
6061
List<String> list2 = new ArrayList<String>(list.subList(0, 1));
6162
]]>
@@ -85,7 +86,7 @@ Negative example:
8586
<priority>1</priority>
8687

8788
<example>
88-
<![CDATA[
89+
<![CDATA[
8990
Negative example:
9091
List<String> originList = new ArrayList<String>();
9192
originList.add("22");
@@ -94,9 +95,9 @@ Negative example:
9495
list.add("bb");
9596
}
9697
]]>
97-
</example>
98+
</example>
9899
<example>
99-
<![CDATA[
100+
<![CDATA[
100101
Positive example:
101102
Iterator<Integer> it=b.iterator();
102103
while(it.hasNext()){
@@ -115,14 +116,14 @@ Negative example:
115116
<description>java.set.CollectionInitShouldAssignCapacityRule.rule.msg.desc</description>
116117
<priority>3</priority>
117118
<example>
118-
<![CDATA[
119+
<![CDATA[
119120
Negative example:
120121
Map<String, String> map = new HashMap<String, String>();
121122
122123
]]>
123-
</example>
124+
</example>
124125
<example>
125-
<![CDATA[
126+
<![CDATA[
126127
Positive example:
127128
Map<String, String> map = new HashMap<String, String>(16);
128129
]]>

0 commit comments

Comments
 (0)