Skip to content

Commit

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

<!--AlibabaJavaSets-->
<chc>
<rule-repo>pmd</rule-repo>
<rule-key>ClassCastExceptionWithToArrayRule</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>UnsupportedExceptionWithModifyAsListRule</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>ClassCastExceptionWithSubListToArrayListRule</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>ConcurrentExceptionWithModifyOriginSubListRule</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>DontModifyInForeachCircleRule</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>CollectionInitShouldAssignCapacityRule</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>
10 changes: 9 additions & 1 deletion src/main/resources/org/sonar/l10n/pmd.properties
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,12 @@ rule.pmd.StringConcatRule.name=[p3c]Use the append method in StringBuilder insid
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).
rule.pmd.AvoidMissUseOfMathRandomRule.name=[p3c]The return type of Math.random() is double, value range is 0<=x<1 (0 is possible).

#AlibabaJavaSets
rule.pmd.ClassCastExceptionWithToArrayRule.name=[p3c]Do not use toArray method without arguments.
rule.pmd.UnsupportedExceptionWithModifyAsListRule.name=[p3c]Do not use methods which will modify the list after using Arrays.asList to convert array to list.
rule.pmd.ClassCastExceptionWithSubListToArrayListRule.name=[p3c]Do not cast subList in class ArrayList, otherwise ClassCastException will be thrown.
rule.pmd.ConcurrentExceptionWithModifyOriginSubListRule.name=[p3c]When using subList, be careful to modify the size of original list.
rule.pmd.DontModifyInForeachCircleRule.name=[p3c]Do not remove or add elements to a collection in a foreach loop.
rule.pmd.CollectionInitShouldAssignCapacityRule.name=[p3c]HashMap should set a size when initializing.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<p>Look for qualified this usages in the same class.</p>
<p>Examples:</p>
<pre>
Negative example:
List<String> list = new ArrayList<String>();
list.add("22");
//warn
List<String> test = (ArrayList<String>) list.subList(0, 1);

Positive example:
List<String> list2 = new ArrayList<String>(list.subList(0, 1));
</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p>Look for qualified this usages in the same class.</p>
<p>Examples:</p>
<pre>
Negative example:
Integer[] a = (Integer [])c.toArray();

Positive example:
Integer[] b = (Integer [])c.toArray(new Integer[c.size()]);
</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p>Look for qualified this usages in the same class.</p>
<p>Examples:</p>
<pre>
Negative example:
Map<String, String> map = new HashMap<String, String>();

Positive example:
Map<String, String> map = new HashMap<String, String>(16);
</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>Look for qualified this usages in the same class.</p>
<p>Examples:</p>
<pre>
Negative example:
List<String> originList = new ArrayList<String>();
originList.add("22");
List<String> subList = originList.subList(0, 1);
//warn
originList.add("22");
</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<p>Look for qualified this usages in the same class.</p>
<p>Examples:</p>
<pre>
Negative example:
List<String> originList = new ArrayList<String>();
originList.add("22");
for (String item : originList) {
//warn
list.add("bb");
}

Positive example:
Iterator<Integer> it=b.iterator();
while(it.hasNext()){
Integer temp = it.next();
if (delCondition) {
it.remove();
}
}
</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>
Positive example:
List<String> t = Arrays.asList("a","b","c");
//warn
t.add("22");
//warn
t.remove("22");
//warn
t.clear();

</pre>
34 changes: 30 additions & 4 deletions src/main/resources/org/sonar/plugins/pmd/rules-p3c.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,45 @@

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

<!--AlibabaJavaSets-->
<rule key="ClassCastExceptionWithToArrayRule">
<priority>CRITICAL</priority>
<configKey><![CDATA[rulesets/java/ali-set.xml/ClassCastExceptionWithToArrayRule]]></configKey>
</rule>
<rule key="UnsupportedExceptionWithModifyAsListRule">
<priority>CRITICAL</priority>
<configKey><![CDATA[rulesets/java/ali-set.xml/UnsupportedExceptionWithModifyAsListRule]]></configKey>
</rule>
<rule key="ClassCastExceptionWithSubListToArrayListRule">
<priority>CRITICAL</priority>
<configKey><![CDATA[rulesets/java/ali-set.xml/ClassCastExceptionWithSubListToArrayListRule]]></configKey>
</rule>
<rule key="ConcurrentExceptionWithModifyOriginSubListRule">
<priority>CRITICAL</priority>
<configKey><![CDATA[rulesets/java/ali-set.xml/ConcurrentExceptionWithModifyOriginSubListRule]]></configKey>
</rule>
<rule key="DontModifyInForeachCircleRule">
<priority>BLOCKER</priority>
<configKey><![CDATA[rulesets/java/ali-set.xml/DontModifyInForeachCircleRule]]></configKey>
</rule>
<rule key="CollectionInitShouldAssignCapacityRule">
<priority>MAJOR</priority>
<configKey><![CDATA[rulesets/java/ali-set.xml/CollectionInitShouldAssignCapacityRule]]></configKey>
</rule>
</rules>

0 comments on commit 15ceb9f

Please sign in to comment.