mirror of https://github.com/alibaba/p3c.git
parent
1ade912a4e
commit
40eaededd1
@ -1,52 +1,52 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="AlibabaJavaConstants" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
|
||||
|
||||
<rule name="UpperEllRule"
|
||||
message="java.constant.UpperEllRule.rule.msg"
|
||||
class="com.alibaba.p3c.pmd.lang.java.rule.constant.UpperEllRule">
|
||||
<priority>1</priority>
|
||||
<example>
|
||||
<rule name="UpperEllRule"
|
||||
message="java.constant.UpperEllRule.rule.msg"
|
||||
class="com.alibaba.p3c.pmd.lang.java.rule.constant.UpperEllRule">
|
||||
<priority>1</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
Negative example:
|
||||
//It is hard to tell whether it is number 11 or Long 1.
|
||||
Long warn = 1l;
|
||||
Negative example:
|
||||
//It is hard to tell whether it is number 11 or Long 1.
|
||||
Long warn = 1l;
|
||||
]]>
|
||||
</example>
|
||||
<example>
|
||||
<![CDATA[
|
||||
Positive example:
|
||||
Long notwarn = 1L;
|
||||
Positive example:
|
||||
Long notwarn = 1L;
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="UndefineMagicConstantRule"
|
||||
message="java.constant.UndefineMagicConstantRule.rule.msg"
|
||||
class="com.alibaba.p3c.pmd.lang.java.rule.constant.UndefineMagicConstantRule">
|
||||
<priority>3</priority>
|
||||
</rule>
|
||||
|
||||
<rule name="UndefineMagicConstantRule"
|
||||
message="java.constant.UndefineMagicConstantRule.rule.msg"
|
||||
class="com.alibaba.p3c.pmd.lang.java.rule.constant.UndefineMagicConstantRule">
|
||||
<priority>3</priority>
|
||||
|
||||
<example>
|
||||
<example>
|
||||
<![CDATA[
|
||||
Negative example:
|
||||
//Magic values, except for predefined, are forbidden in coding.
|
||||
if(key.equals("Id#taobao_1")){
|
||||
//...
|
||||
}
|
||||
Negative example:
|
||||
//Magic values, except for predefined, are forbidden in coding.
|
||||
if (key.equals("Id#taobao_1")) {
|
||||
//...
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
<example>
|
||||
<![CDATA[
|
||||
Positive example:
|
||||
String KEY_PRE = "Id#taobao_1";
|
||||
if(key.equals(KEY_PRE)){
|
||||
//...
|
||||
}
|
||||
Positive example:
|
||||
String KEY_PRE = "Id#taobao_1";
|
||||
if (KEY_PRE.equals(key)) {
|
||||
//...
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
@ -1,52 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
|
||||
<code-fragment id="sets-UnsupportedExceptionWithModifyAsListRule-ok"><![CDATA[
|
||||
public class Foo {
|
||||
private void method(long aLong) {
|
||||
List<String> t = Arrays.asList("a","b","c");
|
||||
}
|
||||
<code-fragment id="sets-UnsupportedExceptionWithModifyAsListRule-ok"><![CDATA[
|
||||
public class Foo {
|
||||
private void method(long aLong) {
|
||||
List<String> t = Arrays.asList("a","b","c");
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
</code-fragment>
|
||||
|
||||
<test-code>
|
||||
<description>sets-UnsupportedExceptionWithModifyAsListRule-ok.</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code-ref id="sets-UnsupportedExceptionWithModifyAsListRule-ok" />
|
||||
</test-code>
|
||||
|
||||
<code-fragment id="sets-UnsupportedExceptionWithModifyAsListRule-warn"><![CDATA[
|
||||
public class Foo {
|
||||
private void method1() {
|
||||
if(true){
|
||||
List<String> list = Arrays.asList("a","b","c");
|
||||
list.add("d");
|
||||
list.remove("22");
|
||||
list.clear();
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add("b");
|
||||
list.remove("b");
|
||||
}
|
||||
|
||||
private void method2() {
|
||||
if(true){
|
||||
List<String> list = Arrays.asList("a","b","c");
|
||||
list.add("d");
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add("b");
|
||||
}
|
||||
}
|
||||
<test-code>
|
||||
<description>sets-UnsupportedExceptionWithModifyAsListRule-ok.</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code-ref id="sets-UnsupportedExceptionWithModifyAsListRule-ok"/>
|
||||
</test-code>
|
||||
|
||||
<code-fragment id="sets-UnsupportedExceptionWithModifyAsListRule-warn"><![CDATA[
|
||||
public class Foo {
|
||||
private void method1() {
|
||||
if (true) {
|
||||
List<String> list = Arrays.asList("a", "b", "c");
|
||||
list.add("d");
|
||||
list.remove("22");
|
||||
list.clear();
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add("b");
|
||||
list.remove("b");
|
||||
}
|
||||
|
||||
private void method2() {
|
||||
if (true) {
|
||||
List<String> list = Arrays.asList("a", "b", "c");
|
||||
list.add("d");
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add("b");
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
</code-fragment>
|
||||
|
||||
<test-code>
|
||||
<description>sets-UnsupportedExceptionWithModifyAsListRule-warn.</description>
|
||||
<expected-problems>4</expected-problems>
|
||||
<expected-linenumbers>5,6,7,17</expected-linenumbers>
|
||||
<code-ref id="sets-UnsupportedExceptionWithModifyAsListRule-warn" />
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>sets-UnsupportedExceptionWithModifyAsListRule-warn.</description>
|
||||
<expected-problems>4</expected-problems>
|
||||
<expected-linenumbers>5,6,7,17</expected-linenumbers>
|
||||
<code-ref id="sets-UnsupportedExceptionWithModifyAsListRule-warn"/>
|
||||
</test-code>
|
||||
|
||||
</test-data>
|
Loading…
Reference in New Issue