forked from phoedos/pmd
Merge branch 'master' into CSRFInVisualForce
This commit is contained in:
@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF8"?>
|
||||
<toolchains>
|
||||
<!-- place this file in ${user.home}/.m2/toolchains.xml -->
|
||||
|
||||
<!-- see: https://github.com/travis-ci/travis-cookbooks/blob/master/cookbooks/travis_java/templates/ubuntu/jdk_switcher.sh.erb -->
|
||||
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>1.6</version>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/usr/lib/jvm/java-6-openjdk-amd64</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>1.7</version>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/usr/lib/jvm/java-7-openjdk-amd64</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>1.8</version>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/usr/lib/jvm/java-8-oracle</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>
|
@ -28,7 +28,6 @@ deploy:
|
||||
file:
|
||||
- pmd-dist/target/pmd-*.zip
|
||||
- target/pmd-doc-*.zip
|
||||
# TODO : This won't copy the changelog to GitHub
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
||||
@ -54,7 +53,7 @@ env:
|
||||
- secure: "mmHRnK/8CHfgtwaTN3MgjFD1R8EVQhIb/a0Aag3gPaHWW52Ex6xWG7GsF4kRcdzHdIdrQxHZTiDa2oVMWbnQ16CAu4dZJadwTxhBW4JmE1tsi2C6i+uwMBPvnKBXHwt+QOAqNB0L/ByYwWLkucSLoyRs6qU0i7sJ3ZC/EPCuLI8VfBlFUVegSbp2WmclmFnxOi5MKr15Zwd8BGgyWUsvd1OHxhvO3Xr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BS84m1ttCEk4g="
|
||||
|
||||
|
||||
# Secure Keys, that need to be set for snapshot builds
|
||||
|
@ -14,7 +14,7 @@ curl -H "Accept: application/json" -X PUT -d "default=windows&default=mac&defaul
|
||||
# Assumes, the release has already been created by travis github releases provider
|
||||
RELEASE_ID=$(curl -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" https://api.github.com/repos/pmd/pmd/releases/tags/pmd_releases/${RELEASE_VERSION}|jq ".id")
|
||||
RELEASE_NAME="PMD ${RELEASE_VERSION} ($(date -u +%d-%B-%Y))"
|
||||
RELEASE_BODY=$(cat src/site/markdown/overview/changelog.md)
|
||||
RELEASE_BODY=$(tail -n +3 src/site/markdown/overview/changelog.md) # skips the first 2 lines - the heading 'PMD Release Notes'
|
||||
RELEASE_BODY="${RELEASE_BODY//$'\\'/\\\\}"
|
||||
RELEASE_BODY="${RELEASE_BODY//$'\r'/}"
|
||||
RELEASE_BODY="${RELEASE_BODY//$'\n'/\\r\\n}"
|
||||
@ -26,7 +26,9 @@ cat > release-edit-request.json <<EOF
|
||||
}
|
||||
EOF
|
||||
echo "Updating release at https://api.github.com/repos/pmd/pmd/releases/${RELEASE_ID}..."
|
||||
RESPONSE=$(curl -i -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" -H "Content-Type: application/json" --data-binary "@release-edit-request.json" -X PATCH https://api.github.com/repos/pmd/pmd/releases/${RELEASE_ID})
|
||||
|
||||
|
||||
RESPONSE=$(curl -i -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" -H "Content-Type: application/json" --data "@release-edit-request.json" -X PATCH https://api.github.com/repos/pmd/pmd/releases/${RELEASE_ID})
|
||||
if [[ "$RESPONSE" != *"HTTP/1.1 200"* ]]; then
|
||||
echo "Request:"
|
||||
cat release-edit-request.json
|
||||
@ -41,19 +43,24 @@ fi
|
||||
|
||||
echo "Adding the site to pmd.github.io..."
|
||||
# clone pmd.github.io. Note: This uses the ssh key setup earlier
|
||||
git clone --depth 1 git@github.com:pmd/pmd.github.io.git
|
||||
rsync -a target/pmd-doc-${RELEASE_VERSION}/ pmd.github.io/pmd-${RELEASE_VERSION}/
|
||||
# In order to speed things up, we use a sparse checkout - no need to checkout all directories here
|
||||
mkdir pmd.github.io
|
||||
(
|
||||
cd pmd.github.io
|
||||
git config user.email "adangel@users.sourceforge.net"
|
||||
git config user.name "Andreas Dangel (PMD Releases)"
|
||||
git checkout master
|
||||
git add pmd-${RELEASE_VERSION}
|
||||
git commit -q -m "Added pmd-${RELEASE_VERSION}"
|
||||
git rm -qr latest
|
||||
cp -a pmd-${RELEASE_VERSION} latest
|
||||
git add latest
|
||||
git commit -q -m "Copying pmd-${RELEASE_VERSION} to latest"
|
||||
git push origin master
|
||||
cd pmd.github.io
|
||||
git init
|
||||
git config user.email "adangel+pmd-bot@users.sourceforge.net"
|
||||
git config user.name "Andreas Dangel (PMD Releases)"
|
||||
git config core.sparsecheckout true
|
||||
git remote add origin git@github.com:pmd/pmd.github.io.git
|
||||
echo "latest/" > .git/info/sparse-checkout
|
||||
git pull --depth=1 origin master
|
||||
rsync -a ../target/pmd-doc-${RELEASE_VERSION}/ pmd-${RELEASE_VERSION}/
|
||||
git add pmd-${RELEASE_VERSION}
|
||||
git commit -q -m "Added pmd-${RELEASE_VERSION}"
|
||||
git rm -qr latest
|
||||
cp -a pmd-${RELEASE_VERSION} latest
|
||||
git add latest
|
||||
git commit -q -m "Copying pmd-${RELEASE_VERSION} to latest"
|
||||
git push origin master
|
||||
)
|
||||
|
||||
|
@ -9,11 +9,15 @@ import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
|
||||
import net.sourceforge.pmd.lang.apex.ApexParserOptions;
|
||||
import net.sourceforge.pmd.lang.rule.XPathRule;
|
||||
import net.sourceforge.pmd.renderers.CodeClimateRule;
|
||||
|
||||
public class ApexXPathRule extends XPathRule {
|
||||
public class ApexXPathRule extends XPathRule implements CodeClimateRule {
|
||||
|
||||
public ApexXPathRule() {
|
||||
super.setLanguage(LanguageRegistry.getLanguage(ApexLanguageModule.NAME));
|
||||
definePropertyDescriptor(CODECLIMATE_CATEGORIES);
|
||||
definePropertyDescriptor(CODECLIMATE_REMEDIATION_MULTIPLIER);
|
||||
definePropertyDescriptor(CODECLIMATE_BLOCK_HIGHLIGHTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
155
pmd-apex/src/main/resources/rulesets/apex/braces.xml
Normal file
155
pmd-apex/src/main/resources/rulesets/apex/braces.xml
Normal file
@ -0,0 +1,155 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="Braces"
|
||||
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>
|
||||
The Braces ruleset contains rules regarding the use and placement of braces.
|
||||
</description>
|
||||
|
||||
<rule name="IfStmtsMustUseBraces"
|
||||
language="apex"
|
||||
since="5.6.0"
|
||||
message="Avoid using if statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/braces.html#IfStmtsMustUseBraces">
|
||||
<description>
|
||||
Avoid using if statements without using braces to surround the code block. If the code
|
||||
formatting or indentation is lost then it becomes difficult to separate the code being
|
||||
controlled from the rest.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfBlockStatement/ExpressionStatement
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
|
||||
if (foo) // not recommended
|
||||
x++;
|
||||
|
||||
if (foo) { // preferred approach
|
||||
x++;
|
||||
}
|
||||
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="WhileLoopsMustUseBraces"
|
||||
language="apex"
|
||||
since="5.6.0"
|
||||
message="Avoid using 'while' statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/braces.html#WhileLoopsMustUseBraces">
|
||||
<description>
|
||||
Avoid using 'while' statements without using braces to surround the code block. If the code
|
||||
formatting or indentation is lost then it becomes difficult to separate the code being
|
||||
controlled from the rest.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//WhileLoopStatement/ExpressionStatement
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
while (true) // not recommended
|
||||
x++;
|
||||
|
||||
while (true) { // preferred approach
|
||||
x++;
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="IfElseStmtsMustUseBraces"
|
||||
language="apex"
|
||||
since="5.6.0"
|
||||
message="Avoid using 'if...else' statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/braces.html#IfElseStmtsMustUseBraces">
|
||||
<description>
|
||||
Avoid using if..else statements without using surrounding braces. If the code formatting
|
||||
or indentation is lost then it becomes difficult to separate the code being controlled
|
||||
from the rest.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ExpressionStatement[parent::IfBlockStatement]
|
||||
|
|
||||
//ExpressionStatement[parent::IfElseBlockStatement]
|
||||
|
|
||||
//IfElseBlockStatement[parent::IfBlockStatement]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
// this is OK
|
||||
if (foo) x++;
|
||||
|
||||
// but this is not
|
||||
if (foo)
|
||||
x = x+1;
|
||||
else
|
||||
x = x-1;
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ForLoopsMustUseBraces"
|
||||
language="apex"
|
||||
since="5.6.0"
|
||||
message="Avoid using 'for' statements without curly braces"
|
||||
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/apex/braces.html#ForLoopsMustUseBraces">
|
||||
<description>
|
||||
Avoid using 'for' statements without using surrounding braces. If the code formatting or
|
||||
indentation is lost then it becomes difficult to separate the code being controlled
|
||||
from the rest.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ForLoopStatement
|
||||
[child::ExpressionStatement]
|
||||
|
|
||||
//ForEachStatement
|
||||
[child::ExpressionStatement]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
for (int i = 0; i < 42; i++) // not recommended
|
||||
foo();
|
||||
|
||||
for (int i = 0; i < 42; i++) { // preferred approach
|
||||
foo();
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Default ruleset used by the CodeClimate Engine for Salesforce.com Apex" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
<description>Default ruleset used by the Code Climate Engine for Salesforce.com Apex</description>
|
||||
|
||||
<!-- COMPLEXITY -->
|
||||
<rule ref="rulesets/apex/complexity.xml/ExcessiveClassLength" message="Avoid really long classes (lines of code)">
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
@ -91,6 +93,8 @@
|
||||
<property name="cc_block_highlighting" value="false" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- PERFORMANCE -->
|
||||
<rule ref="rulesets/apex/performance.xml/AvoidSoqlInLoops" message="Avoid Soql queries inside loops">
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
@ -127,6 +131,7 @@
|
||||
<property name="cc_block_highlighting" value="false" />
|
||||
</properties>
|
||||
</rule>
|
||||
<!-- NAMING -->
|
||||
<rule ref="rulesets/apex/style.xml/ClassNamingConventions" message="Class names should begin with an uppercase character">
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
@ -163,6 +168,7 @@
|
||||
<property name="cc_block_highlighting" value="false" />
|
||||
</properties>
|
||||
</rule>
|
||||
<!-- TESTS -->
|
||||
<rule ref="rulesets/apex/apexunit.xml/ApexUnitTestClassShouldHaveAsserts" message="Apex unit test classes should have at least one System.assert() or assertEquals() or AssertNotEquals() call">
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
@ -181,6 +187,7 @@
|
||||
<property name="cc_block_highlighting" value="false" />
|
||||
</properties>
|
||||
</rule>
|
||||
<!-- SECURITY -->
|
||||
<rule ref="rulesets/apex/security.xml/ApexSharingViolations" message="Apex classes should declare a sharing model if DML or SOQL is used">
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
@ -280,6 +287,41 @@
|
||||
<property name="cc_block_highlighting" value="false"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
|
||||
<!-- BRACES -->
|
||||
<rule ref="rulesets/apex/braces.xml/IfStmtsMustUseBraces" message="Avoid using if statements without curly braces">
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<!-- relevant for Code Climate output only -->
|
||||
<property name="cc_categories" value="Style" />
|
||||
<property name="cc_remediation_points_multiplier" value="5" />
|
||||
<property name="cc_block_highlighting" value="false" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/apex/braces.xml/WhileLoopsMustUseBraces" message="Avoid using 'while' statements without curly braces">
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<!-- relevant for Code Climate output only -->
|
||||
<property name="cc_categories" value="Style" />
|
||||
<property name="cc_remediation_points_multiplier" value="5" />
|
||||
<property name="cc_block_highlighting" value="false" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/apex/braces.xml/IfElseStmtsMustUseBraces" message="Avoid using 'if...else' statements without curly braces">
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<!-- relevant for Code Climate output only -->
|
||||
<property name="cc_categories" value="Style" />
|
||||
<property name="cc_remediation_points_multiplier" value="5" />
|
||||
<property name="cc_block_highlighting" value="false" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/apex/braces.xml/ForLoopsMustUseBraces" message="Avoid using 'for' statements without curly braces">
|
||||
<priority>3</priority>
|
||||
<properties>
|
||||
<!-- relevant for Code Climate output only -->
|
||||
<property name="cc_categories" value="Style" />
|
||||
<property name="cc_remediation_points_multiplier" value="5" />
|
||||
<property name="cc_block_highlighting" value="false" />
|
||||
</properties>
|
||||
</rule>
|
||||
</ruleset>
|
@ -2,4 +2,4 @@
|
||||
# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
#
|
||||
|
||||
rulesets.filenames=rulesets/apex/complexity.xml,rulesets/apex/performance.xml,rulesets/apex/style.xml,rulesets/apex/apexunit.xml,rulesets/apex/security.xml
|
||||
rulesets.filenames=rulesets/apex/complexity.xml,rulesets/apex/performance.xml,rulesets/apex/style.xml,rulesets/apex/apexunit.xml,rulesets/apex/security.xml,rulesets/apex/braces.xml
|
||||
|
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.rule.braces;
|
||||
|
||||
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
|
||||
public class BracesRulesTest extends SimpleAggregatorTst {
|
||||
|
||||
private static final String RULESET = "apex-braces";
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
addRule(RULESET, "ForLoopsMustUseBraces");
|
||||
addRule(RULESET, "IfElseStmtsMustUseBraces");
|
||||
addRule(RULESET, "IfStmtsMustUseBraces");
|
||||
addRule(RULESET, "WhileLoopsMustUseBraces");
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
simple failure case
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
for (int i=0; i<42;i++)
|
||||
foo();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
ok
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
for (int i=0; i<42;i++) {
|
||||
foo();
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
for (int i=0; i<42;)
|
||||
foo();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
for (int i=0;;)
|
||||
foo();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
for (;;)
|
||||
foo();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
for-each
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
for (Account a : accounts)
|
||||
foo();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
@ -0,0 +1,125 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
else without braces
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
if (true) {
|
||||
x=2;
|
||||
} else
|
||||
y=4;
|
||||
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
ok
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
if (true) {
|
||||
x=2;
|
||||
} else {
|
||||
x=4;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
two sets of missing braces
|
||||
]]></description>
|
||||
<expected-problems>2</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
if (true)
|
||||
y=2;
|
||||
else
|
||||
x=4;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
elseif with missing braces
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
if (true) {
|
||||
x=2;
|
||||
} else if (true) {
|
||||
x = 3;
|
||||
} else
|
||||
y=4;
|
||||
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
elseif with braces after else
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
if (true) {
|
||||
x=2;
|
||||
} else if (true) {
|
||||
x = 3;
|
||||
} else {
|
||||
y=4;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
elseif with missing braces, first braces on separate line
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
if (true)
|
||||
{
|
||||
x=2;
|
||||
}
|
||||
else
|
||||
y=4;
|
||||
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
nested ifs without braces
|
||||
]]></description>
|
||||
<expected-problems>2</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
if (true)
|
||||
if (false)
|
||||
x=2;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
simple failure case
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
if (true) x=2;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
ok
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
if (true) {
|
||||
x=2;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
nested ifs
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
if (true) {
|
||||
if (true) bar();
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
no braces
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class WhileLoopsNeedBraces1 {
|
||||
void foo() {
|
||||
int x =0;
|
||||
while (true)
|
||||
x++;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
with braces
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class WhileLoopsNeedBraces2 {
|
||||
void foo() {
|
||||
int x =0;
|
||||
while (true) {
|
||||
x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
17
pmd-core/src/main/resources/rulesets/releases/560.xml
Normal file
17
pmd-core/src/main/resources/rulesets/releases/560.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="560"
|
||||
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>
|
||||
This ruleset contains links to rules that are new in PMD v5.6.0
|
||||
</description>
|
||||
|
||||
<rule ref="rulesets/apex/braces.xml/IfStmtsMustUseBraces"/>
|
||||
<rule ref="rulesets/apex/braces.xml/WhileLoopsMustUseBraces"/>
|
||||
<rule ref="rulesets/apex/braces.xml/IfElseStmtsMustUseBraces"/>
|
||||
<rule ref="rulesets/apex/braces.xml/ForLoopsMustUseBraces"/>
|
||||
|
||||
</ruleset>
|
||||
|
@ -15,9 +15,17 @@ public class ASTClassOrInterfaceBody extends AbstractJavaNode {
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept the visitor. *
|
||||
* Accept the visitor.
|
||||
*/
|
||||
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
public boolean isAnonymousInnerClass() {
|
||||
return jjtGetParent() instanceof ASTAllocationExpression;
|
||||
}
|
||||
|
||||
public boolean isEnumChild() {
|
||||
return jjtGetParent() instanceof ASTEnumConstant;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class ASTFieldDeclaration extends AbstractJavaAccessTypeNode implements D
|
||||
|
||||
@Override
|
||||
public boolean isPublic() {
|
||||
if (isInterfaceMember()) {
|
||||
if (isAnnotationMember() || isInterfaceMember()) {
|
||||
return true;
|
||||
}
|
||||
return super.isPublic();
|
||||
@ -41,7 +41,7 @@ public class ASTFieldDeclaration extends AbstractJavaAccessTypeNode implements D
|
||||
|
||||
@Override
|
||||
public boolean isStatic() {
|
||||
if (isInterfaceMember()) {
|
||||
if (isAnnotationMember() || isInterfaceMember()) {
|
||||
return true;
|
||||
}
|
||||
return super.isStatic();
|
||||
|
@ -7,10 +7,7 @@ package net.sourceforge.pmd.lang.java.rule.design;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTEnumDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.AbstractJavaAccessNode;
|
||||
@ -60,13 +57,10 @@ public class AccessorMethodGenerationRule extends AbstractJavaRule {
|
||||
}
|
||||
|
||||
for (final NameOccurrence no : occurrences) {
|
||||
Node n = no.getLocation();
|
||||
while (n != null && !(n instanceof ASTClassOrInterfaceDeclaration) && !(n instanceof ASTEnumDeclaration)) {
|
||||
n = n.jjtGetParent();
|
||||
}
|
||||
ClassScope usedAtScope = no.getLocation().getScope().getEnclosingScope(ClassScope.class);
|
||||
|
||||
// Are we within the same class that defines the field / method?
|
||||
if (!n.getImage().equals(classScope.getClassName())) {
|
||||
if (!classScope.equals(usedAtScope)) {
|
||||
addViolation(data, no.getLocation());
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTBlock;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTBlockStatement;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCatchStatement;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
|
||||
@ -135,7 +135,7 @@ public class ScopeAndDeclarationFinder extends JavaParserVisitorAdapter {
|
||||
ClassNameDeclaration classNameDeclaration = new ClassNameDeclaration(node);
|
||||
s.addDeclaration(classNameDeclaration);
|
||||
|
||||
if (node instanceof ASTClassOrInterfaceBodyDeclaration) {
|
||||
if (node instanceof ASTClassOrInterfaceBody) {
|
||||
addScope(new ClassScope(classNameDeclaration), node);
|
||||
} else {
|
||||
addScope(new ClassScope(node.getImage(), classNameDeclaration), node);
|
||||
@ -195,7 +195,7 @@ public class ScopeAndDeclarationFinder extends JavaParserVisitorAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTClassOrInterfaceBodyDeclaration node, Object data) {
|
||||
public Object visit(ASTClassOrInterfaceBody node, Object data) {
|
||||
if (node.isAnonymousInnerClass() || node.isEnumChild()) {
|
||||
createClassScope(node);
|
||||
cont(node);
|
||||
|
@ -292,7 +292,6 @@ in each object at runtime.
|
||||
<![CDATA[
|
||||
//FieldDeclaration
|
||||
[@Final='true' and @Static='false']
|
||||
[not (../../../../ClassOrInterfaceDeclaration[@Interface='true'])]
|
||||
/VariableDeclarator/VariableInitializer/Expression
|
||||
/PrimaryExpression[not(PrimarySuffix)]/PrimaryPrefix/Literal
|
||||
]]>
|
||||
|
@ -10,9 +10,12 @@ import java.util.Set;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTLambdaExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
|
||||
|
||||
public class ScopeAndDeclarationFinderTest extends STBBaseTst {
|
||||
@ -44,4 +47,28 @@ public class ScopeAndDeclarationFinderTest extends STBBaseTst {
|
||||
Assert.assertEquals(1, scope.getVariableDeclarations().get(decl).size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnonInnerClassScoping() {
|
||||
String source = "public class Foo {" + PMD.EOL
|
||||
+ " public static final Creator<Foo> CREATOR = new Creator<Foo>() {" + PMD.EOL
|
||||
+ " @Override public Foo createFromParcel(Parcel source) {" + PMD.EOL
|
||||
+ " return new Foo();" + PMD.EOL
|
||||
+ " }" + PMD.EOL
|
||||
+ " @Override public Foo[] newArray(int size) {" + PMD.EOL
|
||||
+ " return new Foo[size];" + PMD.EOL
|
||||
+ " }" + PMD.EOL
|
||||
+ " };" + PMD.EOL
|
||||
+ "}" + PMD.EOL;
|
||||
parseCode(source, LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.6"));
|
||||
|
||||
ClassScope cs = (ClassScope) acu.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getScope();
|
||||
Assert.assertEquals(1, cs.getClassDeclarations().size()); // There should be 1 anonymous class
|
||||
|
||||
List<ASTMethodDeclarator> methods = acu.findDescendantsOfType(ASTMethodDeclarator.class);
|
||||
Assert.assertEquals(2, methods.size());
|
||||
ClassScope scope1 = methods.get(0).getScope().getEnclosingScope(ClassScope.class);
|
||||
ClassScope scope2 = methods.get(1).getScope().getEnclosingScope(ClassScope.class);
|
||||
Assert.assertSame(scope1, scope2);
|
||||
}
|
||||
}
|
||||
|
@ -163,6 +163,33 @@ public class Foo {
|
||||
|
||||
/* package */ void outerPackage() {
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
#274 - Method inside static inner class incorrectly reported as generating accessor methods
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo implements Parcelable {
|
||||
public static final Creator<Foo> CREATOR = new Creator<Foo>() {
|
||||
@Override
|
||||
public Foo createFromParcel(Parcel source) {
|
||||
return new Foo(source.readString(),
|
||||
getBooleanForInt(source.readInt()),
|
||||
source.readLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Foo[] newArray(int size) {
|
||||
return new Foo[size];
|
||||
}
|
||||
|
||||
private boolean getBooleanForInt(int value) {
|
||||
return value == 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -90,6 +90,15 @@ public class FinalFieldCouldBeStaticTest {
|
||||
|
||||
interface Test {
|
||||
byte[] bar();
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#275 - False positive in @interface</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public @interface MetricType {
|
||||
int CHECKBOX = 0, COUNTER = 1, SPINNER = 2, NOTE = 3, STOPWATCH = 4, HEADER = 5;
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -6,8 +6,9 @@
|
||||
|
||||
<description>Rules concerning basic VF guidelines.</description>
|
||||
|
||||
<rule name="VfUnescapeEl" since="3.7"
|
||||
message="Avoid unescaped user controlled content in EL" class="net.sourceforge.pmd.lang.vf.rule.security.VfUnescapeElRule"
|
||||
<rule name="VfUnescapeEl" since="5.6.0"
|
||||
message="Avoid unescaped user controlled content in EL"
|
||||
class="net.sourceforge.pmd.lang.vf.rule.security.VfUnescapeElRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/rules/vf/security.html#VfUnescapeElRule">
|
||||
<description><![CDATA[Avoid unescaped user controlled content in EL as it results in XSS. ]]>
|
||||
</description>
|
||||
|
7
pom.xml
7
pom.xml
@ -447,6 +447,9 @@ Additionally it includes CPD, the copy-paste-detector. CPD finds duplicated code
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>${javadoc.plugin.version}</version>
|
||||
<configuration>
|
||||
<quiet>true</quiet>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -466,12 +469,12 @@ Additionally it includes CPD, the copy-paste-detector. CPD finds duplicated code
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-core</artifactId>
|
||||
<version>5.5.2</version>
|
||||
<version>5.5.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-java</artifactId>
|
||||
<version>5.5.2</version>
|
||||
<version>5.5.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@
|
||||
The PMD team is pleased to announce PMD 5.6.0.
|
||||
|
||||
The most significant changes are on analysis performance, support for Salesforce's Visualforce language
|
||||
a whole new **Apex Security Rule Set**.
|
||||
a whole new **Apex Security Rule Set** and the new **Braces Rule Set for Apex**.
|
||||
|
||||
We have added initial support for **incremental analysis**. The experimental feature allows
|
||||
PMD to cache analysis results between executions to speed up the analysis for all
|
||||
@ -32,12 +32,13 @@ making it over 500X faster, and `PreserveStackTrace` which is now 7X faster.
|
||||
* [Incremental Analysis](#Incremental_Analysis)
|
||||
* [Visualforce Support](#Visualforce_support)
|
||||
* [Apex Security Rule Set](#Apex_Security_Rule_Set)
|
||||
* [Apex Braces Rule Set](#Apex_Braces_Rule_Set)
|
||||
* [New Rules](#New_Rules)
|
||||
* [Modified Rules](#Modified_Rules)
|
||||
* [CPD Suppression](#CPD_Suppression)
|
||||
* [Fixed Issues](#Fixed_Issues)
|
||||
* [API Changes](#API_Changes)
|
||||
* [External Contributions](#External_Contributions)
|
||||
* [Fixed Issues](#Fixed_Issues)
|
||||
* [API Changes](#API_Changes)
|
||||
* [External Contributions](#External_Contributions)
|
||||
|
||||
### New and noteworthy
|
||||
|
||||
@ -229,6 +230,84 @@ attacks if unescaped.
|
||||
Makes sure that all values obtained from URL parameters are properly escaped / sanitized
|
||||
to avoid XSS attacks.
|
||||
|
||||
#### Apex Braces Rule Set
|
||||
|
||||
The Braces Rule Set has been added and serves the same purpose as the Braces Rule Set from Java:
|
||||
It checks the use and placement of braces around if-statements, for-loops and so on.
|
||||
|
||||
##### IfStmtsMustUseBraces
|
||||
|
||||
Avoid using if statements without using braces to surround the code block. If the code
|
||||
formatting or indentation is lost then it becomes difficult to separate the code being
|
||||
controlled from the rest.
|
||||
|
||||
For instance, the following code shows the different. PMD would report on the not recommended approach:
|
||||
|
||||
```
|
||||
if (foo) // not recommended
|
||||
x++;
|
||||
|
||||
if (foo) { // preferred approach
|
||||
x++;
|
||||
}
|
||||
```
|
||||
|
||||
##### WhileLoopsMustUseBraces
|
||||
|
||||
Avoid using 'while' statements without using braces to surround the code block. If the code
|
||||
formatting or indentation is lost then it becomes difficult to separate the code being
|
||||
controlled from the rest.
|
||||
|
||||
For instance, the following code shows the different. PMD would report on the not recommended approach:
|
||||
|
||||
```
|
||||
while (true) // not recommended
|
||||
x++;
|
||||
|
||||
while (true) { // preferred approach
|
||||
x++;
|
||||
}
|
||||
```
|
||||
|
||||
##### IfElseStmtsMustUseBraces
|
||||
|
||||
Avoid using if..else statements without using surrounding braces. If the code formatting
|
||||
or indentation is lost then it becomes difficult to separate the code being controlled
|
||||
from the rest.
|
||||
|
||||
For instance, the following code shows the different. PMD would report on the not recommended approach:
|
||||
|
||||
```
|
||||
// this is not recommended
|
||||
if (foo)
|
||||
x = x+1;
|
||||
else
|
||||
x = x-1;
|
||||
|
||||
// preferred approach
|
||||
if (foo) {
|
||||
x = x+1;
|
||||
} else {
|
||||
x = x-1;
|
||||
}
|
||||
```
|
||||
|
||||
##### ForLoopsMustUseBraces
|
||||
|
||||
Avoid using 'for' statements without using surrounding braces. If the code formatting or
|
||||
indentation is lost then it becomes difficult to separate the code being controlled
|
||||
from the rest.
|
||||
|
||||
For instance, the following code shows the different. PMD would report on the not recommended approach:
|
||||
|
||||
```
|
||||
for (int i = 0; i < 42; i++) // not recommended
|
||||
foo();
|
||||
|
||||
for (int i = 0; i < 42; i++) { // preferred approach
|
||||
foo();
|
||||
}
|
||||
```
|
||||
|
||||
#### New Rules
|
||||
|
||||
@ -347,6 +426,8 @@ For example:
|
||||
* [#216](https://github.com/pmd/pmd/issues/216): \[java] \[doc] NonThreadSafeSingleton: Be more explicit as to why double checked locking is not recommended
|
||||
* [#219](https://github.com/pmd/pmd/issues/219): \[java] UnnecessaryLocalBeforeReturn: ClassCastException in switch case with local variable returned
|
||||
* [#240](https://github.com/pmd/pmd/issues/240): \[java] UnnecessaryLocalBeforeReturn: Enhance by checking usages
|
||||
* [#274](https://github.com/pmd/pmd/issues/274): \[java] AccessorMethodGeneration: Method inside static inner class incorrectly reported
|
||||
* [#275](https://github.com/pmd/pmd/issues/275): \[java] FinalFieldCouldBeStatic: Constant in @interface incorrectly reported as "could be made static"
|
||||
* java-imports
|
||||
* [#1546](https://sourceforge.net/p/pmd/bugs/1546/): \[java] UnnecessaryFullyQualifiedNameRule doesn't take into consideration conflict resolution
|
||||
* [#1547](https://sourceforge.net/p/pmd/bugs/1547/): \[java] UnusedImportRule - False Positive for only usage in Javadoc - {@link ClassName#CONSTANT}
|
||||
@ -425,4 +506,5 @@ For example:
|
||||
* [#268](https://github.com/pmd/pmd/pull/268): \[apex] Support safe escaping via String method
|
||||
* [#273](https://github.com/pmd/pmd/pull/273): \[apex] Shade jackson on apex
|
||||
* [#280](https://github.com/pmd/pmd/pull/280): \[apex] Support for Aggregate Result in CRUD rules
|
||||
* [#281](https://github.com/pmd/pmd/pull/281): \[apex] Add Braces Rule Set
|
||||
|
||||
|
Reference in New Issue
Block a user