Skip to content

Commit

Permalink
add other rule set
Browse files Browse the repository at this point in the history
  • Loading branch information
mrprince committed Feb 27, 2018
1 parent 1267199 commit 3189718
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/main/resources/com/sonar/sqale/pmd-model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4453,6 +4453,60 @@
<txt>min</txt>
</prop>
</chc>

<!--AlibabaJavaOthers-->
<chc>
<rule-repo>pmd</rule-repo>
<rule-key>AvoidPatternCompileInMethodRule</rule-key>
<prop>
<key>remediationFunction</key>
<txt>CONSTANT_ISSUE</txt>
</prop>
<prop>
<key>offset</key>
<val>2</val>
<txt>min</txt>
</prop>
</chc>
<chc>
<rule-repo>pmd</rule-repo>
<rule-key>AvoidApacheBeanUtilsCopyRule</rule-key>
<prop>
<key>remediationFunction</key>
<txt>CONSTANT_ISSUE</txt>
</prop>
<prop>
<key>offset</key>
<val>2</val>
<txt>min</txt>
</prop>
</chc>
<chc>
<rule-repo>pmd</rule-repo>
<rule-key>AvoidNewDateGetTimeRule</rule-key>
<prop>
<key>remediationFunction</key>
<txt>CONSTANT_ISSUE</txt>
</prop>
<prop>
<key>offset</key>
<val>2</val>
<txt>min</txt>
</prop>
</chc>
<chc>
<rule-repo>pmd</rule-repo>
<rule-key>AvoidMissUseOfMathRandomRule</rule-key>
<prop>
<key>remediationFunction</key>
<txt>CONSTANT_ISSUE</txt>
</prop>
<prop>
<key>offset</key>
<val>2</val>
<txt>min</txt>
</prop>
</chc>
</chc>
</chc>
</sqale>
5 changes: 5 additions & 0 deletions src/main/resources/org/sonar/l10n/pmd.properties
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,8 @@ rule.pmd.PojoNoDefaultValueRule.name=[p3c]While defining POJO classes like DO, D
rule.pmd.PojoMustOverrideToStringRule.name=[p3c]We can call the toString method in a POJO directly to print property values.
rule.pmd.StringConcatRule.name=[p3c]Use the append method in StringBuilder inside a loop body when concatenating multiple strings.

#AlibabaJavaOthers
rule.pmd.AvoidPatternCompileInMethodRule.name=[p3c]When using regex, precompile needs to be done in order to increase the matching performance.
rule.pmd.AvoidApacheBeanUtilsCopyRule.name=[p3c]Avoid using *Apache Beanutils* to copy attributes.
rule.pmd.AvoidNewDateGetTimeRule.name=[p3c]Use System.currentTimeMillis() to get the current millisecond. Do not use new Date().getTime().
rule.pmd.AvoidMissUseOfMathRandomRule.name=[p3c]The return type of Math.random() is double, value range is 0<=x<1 (0 is possible).
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>Look for qualified this usages in the same class.</p>
<p>Examples:</p>
<pre>
TestObject a = new TestObject();
TestObject b = new TestObject();
a.setX(b.getX());
a.setY(b.getY());
</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>Look for qualified this usages in the same class.</p>
<p>Examples:</p>
<pre>
Negative example:
Long randomLong =(long) (Math.random() * 10);
Positive example:
Long randomLong = new Random().nextLong();
</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p>Look for qualified this usages in the same class.</p>
<p>Examples:</p>
<pre>
public class TimeMillisDemo {
public static void main(String args[]) {
// Positive example:
long a = System.currentTimeMillis();
// Negative example:
long b = new Date().getTime();

System.out.println(a);
System.out.println(b);
}
}
</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<p>Look for qualified this usages in the same class.</p>
<p>Examples:</p>
<pre>
public class XxxClass {
// Use precompile
private static Pattern NUMBER_PATTERN = Pattern.compile("[0-9]+");
public Pattern getNumberPattern() {
// Avoid use Pattern.compile in method body.
Pattern localPattern = Pattern.compile("[0-9]+");
return localPattern;
}
}
</pre>
17 changes: 17 additions & 0 deletions src/main/resources/org/sonar/plugins/pmd/rules-p3c.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,21 @@
<configKey><![CDATA[rulesets/java/ali-oop.xml/PojoMustOverrideToStringRule]]></configKey>
</rule>

<!--AlibabaJavaOthers-->
<rule key="AvoidPatternCompileInMethodRule">
<priority>CRITICAL</priority>
<configKey><![CDATA[rulesets/java/ali-other.xml/AvoidPatternCompileInMethodRule]]></configKey>
</rule>
<rule key="AvoidApacheBeanUtilsCopyRule">
<priority>CRITICAL</priority>
<configKey><![CDATA[rulesets/java/ali-other.xml/AvoidApacheBeanUtilsCopyRule]]></configKey>
</rule>
<rule key="AvoidNewDateGetTimeRule">
<priority>CRITICAL</priority>
<configKey><![CDATA[rulesets/java/ali-other.xml/AvoidNewDateGetTimeRule]]></configKey>
</rule>
<rule key="AvoidMissUseOfMathRandomRule">
<priority>CRITICAL</priority>
<configKey><![CDATA[rulesets/java/ali-other.xml/AvoidMissUseOfMathRandomRule]]></configKey>
</rule>
</rules>

0 comments on commit 3189718

Please sign in to comment.