Merge branch 'pr-1140'

This commit is contained in:
Andreas Dangel
2018-05-23 20:22:23 +02:00
3 changed files with 41 additions and 21 deletions

View File

@ -47,6 +47,7 @@ This is a bug fixing release.
* [#527](https://github.com/pmd/pmd/issues/572): \[java] False Alarm of JUnit4TestShouldUseTestAnnotation on Predicates
* [#1063](https://github.com/pmd/pmd/issues/1063): \[java] MissingOverride is triggered in illegal places
* java-codestyle
* [#720](https://github.com/pmd/pmd/issues/720): \[java] ShortVariable should whitelist lambdas
* [#955](https://github.com/pmd/pmd/issues/955): \[java] Detect identical catch statements
* [#1064](https://github.com/pmd/pmd/issues/1064): \[java] ClassNamingConventions suggests to add Util suffix for simple exception wrappers
* [#1065](https://github.com/pmd/pmd/issues/1065): \[java] ClassNamingConventions shouldn't prohibit numbers in class names

View File

@ -1425,13 +1425,19 @@ Fields, local variables, or parameter names that are very short are not helpful
<priority>3</priority>
<properties>
<property name="minimum" type="Integer" value="3" min="1" max="100" description="Number of characters that are required as a minimum for a variable name."/>
<property name="version" value="2.0"/>
<property name="xpath">
<value>
<![CDATA[
//VariableDeclaratorId[string-length(@Image) < $minimum]
[not(ancestor::ForInit)]
[not(../../VariableDeclarator and ../../../LocalVariableDeclaration and ../../../../ForStatement)]
[not((ancestor::FormalParameter) and (ancestor::TryStatement))]
(: ForStatement :)
[not(../../..[self::ForInit])]
(: Foreach statement :)
[not(../../..[self::ForStatement])]
(: Catch statement parameter :)
[not(../..[self::CatchStatement])]
(: Lambda expression parameter :)
[not(parent::LambdaExpression or ../../..[self::LambdaExpression])]
]]>
</value>
</property>

View File

@ -3,10 +3,9 @@
xmlns="http://pmd.sourceforge.net/rule-tests"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
<test-code>
<description><![CDATA[
param
]]></description>
<description>param</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
@ -15,10 +14,9 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
none
]]></description>
<description>none</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -28,10 +26,9 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
local
]]></description>
<description>local</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
@ -43,10 +40,9 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
for
]]></description>
<description>for</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -56,10 +52,9 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
field
]]></description>
<description>field</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
@ -67,10 +62,9 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
catch(Exception e) is OK
]]></description>
<description>catch(Exception e) is OK</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@ -81,6 +75,7 @@ public class Foo {
]]></code>
</test-code>
<test-code>
<description>ShortVariable false positive with for-each loops</description>
<expected-problems>0</expected-problems>
@ -93,6 +88,7 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description>ShortVariable within for-each loops</description>
<expected-problems>1</expected-problems>
@ -106,6 +102,7 @@ public class Foo {
}
]]></code>
</test-code>
<test-code>
<description>#1361 ShortVariable configuration - 7 characters</description>
<rule-property name="minimum">7</rule-property>
@ -120,6 +117,7 @@ public class ShortVariable {
}
]]></code>
</test-code>
<test-code>
<description>#1361 ShortVariable configuration - 1 characters</description>
<rule-property name="minimum">1</rule-property>
@ -130,6 +128,21 @@ public class ShortVariable {
String thisIsOk = "";
String foo = ""; // that's ok, too, now
}
}
]]></code>
</test-code>
<test-code>
<description>#720 Whitelist lambda parameters</description>
<rule-property name="minimum">1</rule-property>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class ShortVariable {
public void bar() {
String thisIsOk = a -> foo();
String foo = (a, b) -> foo();
String bar = (String a, Boolean b) -> foo();
}
}
]]></code>
</test-code>