Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
200 righe
5.0 KiB
200 righe
5.0 KiB
2 anni fa
|
<?xml version="1.0"?>
|
||
|
|
||
|
<ruleset
|
||
|
name="Liferay rules"
|
||
|
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"
|
||
|
>
|
||
|
<description>
|
||
|
Selected standard rules from PMD out of box rule sets. Please refer to the origin rule set file, rule name and version info for future update.
|
||
|
</description>
|
||
|
<rule
|
||
|
class="com.liferay.pmd.rules.junit.AssertFailJUnitRule"
|
||
|
language="java"
|
||
|
message="Do not call Assert#fail improperly."
|
||
|
name="AssertFailJUnitRule"
|
||
|
since="0.1">
|
||
|
<description>
|
||
|
Detect when Assert#fail is called improperly.
|
||
|
</description>
|
||
|
<priority>3</priority>
|
||
|
<example>
|
||
|
<![CDATA[
|
||
|
|
||
|
@Test
|
||
|
public void test() {
|
||
|
try {
|
||
|
|
||
|
// ...
|
||
|
|
||
|
}
|
||
|
catch (Exception e) {
|
||
|
Assert.fail();
|
||
|
}
|
||
|
}
|
||
|
]]>
|
||
|
</example>
|
||
|
<example>
|
||
|
<![CDATA[
|
||
|
|
||
|
@Test
|
||
|
public void test() {
|
||
|
Assert.fail();
|
||
|
}
|
||
|
|
||
|
]]>
|
||
|
</example>
|
||
|
</rule>
|
||
|
<rule
|
||
|
class="net.sourceforge.pmd.lang.java.rule.basic.BooleanInstantiationRule"
|
||
|
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-java/rules/java/basic.html#BooleanInstantiation"
|
||
|
message="Avoid instantiating Boolean objects; reference Boolean.TRUE or Boolean.FALSE or call Boolean.valueOf() instead."
|
||
|
name="BooleanInstantiation"
|
||
|
since="1.2"
|
||
|
>
|
||
|
<description>
|
||
|
[Origin rule set file rulesets/java/basic.xml] Avoid instantiating Boolean objects; you can reference Boolean.TRUE, Boolean.FALSE, or call Boolean.valueOf() instead.
|
||
|
</description>
|
||
|
<priority>2</priority>
|
||
|
<example>
|
||
|
<![CDATA[
|
||
|
|
||
|
// Poor, unnecessary creation, just reference Boolean.TRUE
|
||
|
|
||
|
new Boolean("true");
|
||
|
|
||
|
// Poor, unnecessary creation, just reference Boolean.FALSE
|
||
|
|
||
|
Boolean.valueOf(false);
|
||
|
]]>
|
||
|
</example>
|
||
|
</rule>
|
||
|
<rule
|
||
|
class="com.liferay.pmd.rules.java.OverrideBothEqualsAndHashcodeRule"
|
||
|
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-java/rules/java/basic.html#OverrideBothEqualsAndHashcode"
|
||
|
language="java"
|
||
|
message="Ensure you override both equals() and hashCode()"
|
||
|
name="OverrideBothEqualsAndHashcode"
|
||
|
since="0.4"
|
||
|
>
|
||
|
<description>
|
||
|
[Origin rule set file rulesets/java/basic.xml] Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass.
|
||
|
</description>
|
||
|
<priority>3</priority>
|
||
|
<example>
|
||
|
<![CDATA[
|
||
|
|
||
|
// Poor, missing a hashcode() method
|
||
|
|
||
|
public class Bar {
|
||
|
|
||
|
public boolean equals(Object object) {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// Poor, missing an equals() method
|
||
|
|
||
|
public class Baz {
|
||
|
|
||
|
public int hashCode() {
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// Perfect, both methods are provided
|
||
|
|
||
|
public class Foo {
|
||
|
|
||
|
public boolean equals(Object object) {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public int hashCode() {
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
]]>
|
||
|
</example>
|
||
|
</rule>
|
||
|
<rule
|
||
|
class="net.sourceforge.pmd.lang.java.rule.unnecessary.UnnecessaryReturnRule"
|
||
|
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-java/rules/java/unnecessary.html#UnnecessaryReturn"
|
||
|
message="Avoid unnecessary return statements"
|
||
|
name="UnnecessaryReturn"
|
||
|
since="1.3"
|
||
|
>
|
||
|
<description>
|
||
|
[Origin rule set file rulesets/java/unnecessary.xml] Avoid the use of unnecessary return statements.
|
||
|
</description>
|
||
|
<priority>3</priority>
|
||
|
<example>
|
||
|
<![CDATA[
|
||
|
public class Foo {
|
||
|
|
||
|
public void bar() {
|
||
|
int x = 42;
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
]]>
|
||
|
</example>
|
||
|
</rule>
|
||
|
<rule
|
||
|
class="net.sourceforge.pmd.lang.java.rule.unnecessary.UselessOperationOnImmutableRule"
|
||
|
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-java/rules/java/unnecessary.html#UselessOperationOnImmutable"
|
||
|
message="An operation on an Immutable object (String, BigDecimal or BigInteger) won't change the object itself"
|
||
|
name="UselessOperationOnImmutable"
|
||
|
since="3.5">
|
||
|
<description>
|
||
|
[Origin rule set file rulesets/java/unnecessary.xml] An operation on an Immutable object (String, BigDecimal or BigInteger) won't change the object itself since the result of the operation is a new object. Therefore, ignoring the operation result is an error.
|
||
|
</description>
|
||
|
<priority>3</priority>
|
||
|
<example>
|
||
|
<![CDATA[
|
||
|
|
||
|
BigDecimal bigDecimal = new BigDecimal(10);
|
||
|
|
||
|
// Poor, useless operation
|
||
|
|
||
|
bigDecimal.add(new BigDecimal(5));
|
||
|
|
||
|
// Perfect, useful operation
|
||
|
|
||
|
bigDecimal = bigDecimal.add(new BigDecimal(5));
|
||
|
]]>
|
||
|
</example>
|
||
|
</rule>
|
||
|
<rule
|
||
|
class="net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedLocalVariableRule"
|
||
|
externalInfoUrl="http://pmd.sourceforge.net/pmd-5.2.3/pmd-java/rules/java/unusedcode.html#UnusedLocalVariable"
|
||
|
language="java"
|
||
|
message="Avoid unused local variables such as ''{0}''."
|
||
|
name="UnusedLocalVariable"
|
||
|
since="0.1">
|
||
|
<description>
|
||
|
[Origin rule set file rulesets/java/unusedcode.xml] Detects when a local variable is declared and/or assigned, but not used.
|
||
|
</description>
|
||
|
<priority>3</priority>
|
||
|
<example>
|
||
|
<![CDATA[
|
||
|
public class Foo {
|
||
|
|
||
|
public void doSomething() {
|
||
|
|
||
|
// Poor, unused local variable
|
||
|
|
||
|
int i = 5;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
]]>
|
||
|
</example>
|
||
|
</rule>
|
||
|
</ruleset>
|