Merge remote-tracking branch 'upstream/pmd/7.0.x' into text-utils-simple

This commit is contained in:
Clément Fournier
2022-07-09 11:59:43 +02:00
225 changed files with 8878 additions and 2980 deletions

View File

@ -3384,7 +3384,8 @@
"avatar_url": "https://avatars.githubusercontent.com/u/242337?v=4",
"profile": "https://github.com/jjlharrison",
"contributions": [
"bug"
"bug",
"code"
]
},
{
@ -6639,6 +6640,96 @@
"contributions": [
"code"
]
},
{
"login": "lukelukes",
"name": "lukelukes",
"avatar_url": "https://avatars.githubusercontent.com/u/45536418?v=4",
"profile": "https://github.com/lukelukes",
"contributions": [
"code"
]
},
{
"login": "vibhory2j",
"name": "Vibhor Goyal",
"avatar_url": "https://avatars.githubusercontent.com/u/15845016?v=4",
"profile": "https://github.com/vibhory2j",
"contributions": [
"bug"
]
},
{
"login": "Ramel0921",
"name": "Ramel0921",
"avatar_url": "https://avatars.githubusercontent.com/u/104978096?v=4",
"profile": "https://github.com/Ramel0921",
"contributions": [
"bug"
]
},
{
"login": "flyhard",
"name": "Per Abich",
"avatar_url": "https://avatars.githubusercontent.com/u/409466?v=4",
"profile": "https://github.com/flyhard",
"contributions": [
"code"
]
},
{
"login": "filipponova",
"name": "Filippo Nova",
"avatar_url": "https://avatars.githubusercontent.com/u/12506636?v=4",
"profile": "https://github.com/filipponova",
"contributions": [
"bug"
]
},
{
"login": "dalizi007",
"name": "dalizi007",
"avatar_url": "https://avatars.githubusercontent.com/u/90743616?v=4",
"profile": "https://github.com/dalizi007",
"contributions": [
"code"
]
},
{
"login": "shiomiyan",
"name": "shiomiyan",
"avatar_url": "https://avatars.githubusercontent.com/u/35842766?v=4",
"profile": "https://github.com/shiomiyan",
"contributions": [
"doc"
]
},
{
"login": "lgemeinhardt",
"name": "lgemeinhardt",
"avatar_url": "https://avatars.githubusercontent.com/u/1395165?v=4",
"profile": "https://github.com/lgemeinhardt",
"contributions": [
"bug"
]
},
{
"login": "HaelC",
"name": "Haoliang Chen",
"avatar_url": "https://avatars.githubusercontent.com/u/16898273?v=4",
"profile": "https://haelchan.me/",
"contributions": [
"bug"
]
},
{
"login": "FSchliephacke",
"name": "FSchliephacke",
"avatar_url": "https://avatars.githubusercontent.com/u/10260493?v=4",
"profile": "https://github.com/FSchliephacke",
"contributions": [
"bug"
]
}
],
"contributorsPerLine": 7,

View File

@ -245,12 +245,15 @@ ${rendered_release_notes}"
# Runs the dogfood ruleset with the currently built pmd against itself
#
function pmd_ci_dogfood() {
local mpmdVersion=()
./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false
sed -i 's/<version>[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}.*<\/version>\( *<!-- pmd.dogfood.version -->\)/<version>'"${PMD_CI_MAVEN_PROJECT_VERSION}"'<\/version>\1/' pom.xml
if [ "${PMD_CI_MAVEN_PROJECT_VERSION}" = "7.0.0-SNAPSHOT" ]; then
sed -i 's/pmd-dogfood-config\.xml/pmd-dogfood-config7.xml/' pom.xml
mpmdVersion=(-Denforcer.skip=true -Dpmd.plugin.version=3.18.0-pmd7-SNAPSHOT)
fi
./mvnw verify --show-version --errors --batch-mode --no-transfer-progress "${PMD_MAVEN_EXTRA_OPTS[@]}" \
"${mpmdVersion[@]}" \
-DskipTests \
-Dmaven.javadoc.skip=true \
-Dmaven.source.skip=true \

View File

@ -40,6 +40,11 @@ mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFile=classpath.t
<exclude-pattern>.*/build/generated-sources/.*</exclude-pattern>
<build-command><![CDATA[#!/usr/bin/env bash
## Skip gradle execution
if test -e classpath.txt; then
exit
fi
set -e
# Make sure to use java11. This is already installed by build.sh
@ -129,11 +134,6 @@ index 6021fa574d..15d29ed699 100644
EOF
) | patch --strip=1
## Skip gradle execution
if test -e classpath.txt; then
exit
fi
./gradlew --console=plain --build-cache --no-daemon --max-workers=4 build testClasses -x test -x javadoc -x api -x asciidoctor -x asciidoctorPdf
./gradlew --console=plain --build-cache --no-daemon --max-workers=4 createSquishClasspath -q > classpath.txt
]]></build-command>

View File

@ -27,7 +27,7 @@ function git_repo_sync() {
pmd_ci_log_group_start "Git Sync"
git remote add pmd-sf "${PMD_SF_USER}@git.code.sf.net:/p/pmd/code"
if [ -n "${PMD_CI_BRANCH}" ]; then
git push pmd-sf "${PMD_CI_BRANCH}:${PMD_CI_BRANCH}"
retry 5 git push pmd-sf "${PMD_CI_BRANCH}:${PMD_CI_BRANCH}"
pmd_ci_log_success "Successfully pushed ${PMD_CI_BRANCH} to sourceforge"
elif [ -n "${PMD_CI_TAG}" ]; then
git push pmd-sf tag "${PMD_CI_TAG}"
@ -39,6 +39,43 @@ function git_repo_sync() {
pmd_ci_log_group_end
}
#
# From: https://gist.github.com/sj26/88e1c6584397bb7c13bd11108a579746
#
# Retry a command up to a specific number of times until it exits successfully,
# with exponential back off.
#
# $ retry 5 echo Hello
# Hello
#
# $ retry 5 false
# Retry 1/5 exited 1, retrying in 1 seconds...
# Retry 2/5 exited 1, retrying in 2 seconds...
# Retry 3/5 exited 1, retrying in 4 seconds...
# Retry 4/5 exited 1, retrying in 8 seconds...
# Retry 5/5 exited 1, no more retries left.
#
function retry {
local retries=$1
shift
local count=0
until "$@"; do
exit=$?
wait=$((2 ** $count))
count=$(($count + 1))
if [ $count -lt $retries ]; then
echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
sleep $wait
else
echo "Retry $count/$retries exited $exit, no more retries left."
return $exit
fi
done
return 0
}
git_repo_sync
exit 0

View File

@ -46,7 +46,7 @@ jobs:
run: |
echo "LANG=en_US.UTF-8" >> $GITHUB_ENV
echo "MAVEN_OPTS=-Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3 -DautoReleaseAfterClose=true -DstagingProgressTimeoutMinutes=30" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/17/scripts" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/18/scripts" >> $GITHUB_ENV
- name: Check Environment
shell: bash
run: |

View File

@ -22,7 +22,7 @@ jobs:
shell: bash
run: |
echo "LANG=en_US.UTF-8" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/17/scripts" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/18/scripts" >> $GITHUB_ENV
- name: Sync
run: .ci/git-repo-sync.sh
shell: bash

View File

@ -36,7 +36,7 @@ jobs:
run: |
echo "LANG=en_US.UTF-8" >> $GITHUB_ENV
echo "MAVEN_OPTS=-Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3 -DstagingProgressTimeoutMinutes=30" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/17/scripts" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/18/scripts" >> $GITHUB_ENV
- name: Check Environment
shell: bash
run: |

View File

@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar

View File

@ -68,14 +68,14 @@ GEM
multipart-post (2.1.1)
nap (1.1.0)
no_proxy_fix (0.1.2)
nokogiri (1.13.5)
nokogiri (1.13.6)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
octokit (4.22.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
open4 (1.3.4)
pmdtester (1.5.0)
pmdtester (1.5.1)
differ (~> 0.1)
liquid (~> 5.2)
logger-colors (~> 1.0)

View File

@ -8,7 +8,7 @@
- lang-name: matches the grammar name (eg "Swift")
- lang-terse-name: uncapitalized package name (eg "swift")
- node-prefix: prefix for generated AST nodes (eg "Sw")
- root-node-name: name of the root node (eg "TopLevel"), will be made to implement RootNode
- root-node-name: name of the root node without prefix (eg "TopLevel"), will be made to implement RootNode
See AntlrGeneratedParserBase
@ -31,9 +31,45 @@
<property name="base-visitor-name" value="${lang-name}BaseVisitor"/>
<property name="base-visitor-file" value="${target-package-dir}/${base-visitor-name}.java"/>
<property name="listener-name" value="${lang-name}Listener"/>
<property name="listener-file" value="${target-package-dir}/${visitor-name}.java"/>
<property name="base-listener-name" value="${lang-name}BaseListener"/>
<property name="base-listener-file" value="${target-package-dir}/${base-visitor-name}.java"/>
<property name="node-itf-name" value="${lang-name}Node"/>
<property name="base-class-name" value="Abstract${lang-name}Node"/>
<condition property="rename-parser">
<and>
<not>
<available file="${parser-file}"/>
</not>
<available file="${target-package-dir}/${lang-name}.java"/>
</and>
</condition>
<target name="rename-parser" description="Rename the parser to our conventional name if needed"
if="rename-parser">
<replace file="${target-package-dir}/${lang-name}.java">
<replacefilter token="class ${lang-name} "
value="class ${parser-name} "/>
<replacefilter token="public ${lang-name}(TokenStream input)"
value="public ${parser-name}(TokenStream input)"/>
</replace>
<replace dir="${target-package-dir}">
<include name="${lang-name}.java"/>
<include name="${visitor-name}.java"/>
<include name="${base-visitor-name}.java"/>
<include name="${listener-name}.java"/>
<include name="${base-listener-name}.java"/>
<replacefilter token="${lang-name}." value="${parser-name}."/>
</replace>
<move file="${target-package-dir}/${lang-name}.java"
tofile="${parser-file}"/>
</target>
<target name="cpd-language" description="Adapt Antlr sources for CPD-only languages">
<!-- We only need the Lexer file. -->
<delete file="${parser-file}"/>
@ -45,7 +81,7 @@
</delete>
</target>
<target name="pmd-language" description="Adapt Antlr sources for PMD languages">
<target name="pmd-language" description="Adapt Antlr sources for PMD languages" depends="rename-parser">
<!-- Adapt parser. -->
<replace file="${parser-file}">

View File

@ -72,6 +72,14 @@ export RELEASE_VERSION
export DEVELOPMENT_VERSION
export CURRENT_BRANCH
# check for SNAPSHOT version of pmd.build-tools.version
BUILD_TOOLS_VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=pmd.build-tools.version -q -DforceStdout)
BUILD_TOOLS_VERSION_RELEASE=${BUILD_TOOLS_VERSION%-SNAPSHOT}
if [ "${BUILD_TOOLS_VERSION}" != "${BUILD_TOOLS_VERSION_RELEASE}" ]; then
echo "Error: version pmd.build-tools.version is ${BUILD_TOOLS_VERSION} - snapshot is not allowed"
exit 1
fi
RELEASE_RULESET="pmd-core/src/main/resources/rulesets/releases/${RELEASE_VERSION//\./}.xml"
echo "* Update date info in **docs/_config.yml**."

View File

@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (6.0.4.8)
activesupport (6.0.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
@ -232,7 +232,7 @@ GEM
jekyll-seo-tag (~> 2.1)
minitest (5.15.0)
multipart-post (2.1.1)
nokogiri (1.13.5)
nokogiri (1.13.6)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
octokit (4.22.0)

View File

@ -2,7 +2,7 @@ repository: pmd/pmd
pmd:
version: 7.0.0-SNAPSHOT
previous_version: 6.45.0
previous_version: 6.47.0
date: ??-?????-2022
release_type: major

View File

@ -244,6 +244,21 @@ entries:
- title: Security
output: web, pdf
url: /pmd_rules_jsp_security.html
- title: null
output: web, pdf
subfolders:
- title: Kotlin Rules
output: web, pdf
subfolderitems:
- title: Index
output: web, pdf
url: /pmd_rules_kotlin.html
- title: Best Practices
output: web, pdf
url: /pmd_rules_kotlin_bestpractices.html
- title: Error Prone
output: web, pdf
url: /pmd_rules_kotlin_errorprone.html
- title: null
output: web, pdf
subfolders:
@ -382,6 +397,9 @@ entries:
- title: JSP
url: /pmd_languages_jsp.html
output: web, pdf
- title: Kotlin
url: /pmd_languages_kotlin.html
output: web, pdf
- title: PLSQL
url: /pmd_languages_plsql.html
output: web, pdf

View File

@ -49,6 +49,26 @@ Given the full Antlr support, PMD now fully supports Swift. We are pleased to an
* {% rule "swift/bestpractices/UnavailableFunction" %} (`swift-bestpractices`) flags any function throwing a `fatalError` not marked as
`@available(*, unavailable)` to ensure no calls are actually performed in the codebase.
Contributors: [@lsoncini](https://github.com/lsoncini), [@matifraga](https://github.com/matifraga), [@tomidelucca](https://github.com/tomidelucca)
#### Kotlin support (experimental)
PMD now supports Kotlin as an additional language for analyzing source code. It is based on
the official kotlin Antlr grammar. Java-based rules and XPath-based rules are supported.
Kotlin support has **experimental** stability level, meaning no compatibility should
be expected between even incremental releases. Any functionality can be added, removed or changed without
warning.
We are shipping the following rules:
* {% rule kotlin/bestpractices/FunctionNameTooShort %} (`kotlin-bestpractices`) finds functions with a too short name.
* {% rule kotlin/errorprone/OverrideBothEqualsAndHashcode %} (`kotlin-errorprone`) finds classes with only either `equals`
or `hashCode` overridden, but not both. This leads to unexpected behavior once instances of such classes
are used in collections (Lists, HashMaps, ...).
Contributors: [@jborgers](https://github.com/jborgers), [@stokpop](https://github.com/stokpop)
#### XPath 3.1 support
Support for XPath versions 1.0, 1.0-compatibility was removed, support for XPath 2.0 is deprecated. The default (and only) supported XPath version is now XPath 3.1. This version of the XPath language is mostly identical to XPath 2.0. Notable changes:
@ -243,6 +263,8 @@ The following previously deprecated rules have been finally removed:
* java-performance
* [#1224](https://github.com/pmd/pmd/issues/1224): \[java] InefficientEmptyStringCheck false negative in anonymous class
* [#2712](https://github.com/pmd/pmd/issues/2712): \[java] SimplifyStartsWith false-positive with AssertJ
* kotlin
* [#419](https://github.com/pmd/pmd/issues/419): \[kotlin] Add support for Kotlin
### API Changes

View File

@ -246,6 +246,43 @@ the breaking API changes will be performed in 7.0.0.
an API is tagged as `@Deprecated` or not in the latest minor release. During the development of 7.0.0,
we may decide to remove some APIs that were not tagged as deprecated, though we'll try to avoid it." %}
#### 6.47.0
No changes.
#### 6.46.0
##### Deprecated ruleset references
Ruleset references with the following formats are now deprecated and will produce a warning
when used on the CLI or in a ruleset XML file:
- `<lang-name>-<ruleset-name>`, eg `java-basic`, which resolves to `rulesets/java/basic.xml`
- the internal release number, eg `600`, which resolves to `rulesets/releases/600.xml`
Use the explicit forms of these references to be compatible with PMD 7.
##### Deprecated API
- {% jdoc core::RuleSetReferenceId#toString() %} is now deprecated. The format of this
method will remain the same until PMD 7. The deprecation is intended to steer users
away from relying on this format, as it may be changed in PMD 7.
- {% jdoc core::PMDConfiguration#getInputPaths() %} and
{% jdoc core::PMDConfiguration#setInputPaths(java.lang.String) %} are now deprecated.
A new set of methods have been added, which use lists and do not rely on comma splitting.
##### Internal API
Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0.
You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning.
- {% jdoc core::cpd.CPDCommandLineInterface %} has been internalized. In order to execute CPD either
{% jdoc !!core::cpd.CPD#run(java.lang.String...) %} or {% jdoc !!core::cpd.CPD#main(java.lang.String[]) %}
should be used.
- Several members of {% jdoc test::cli.BaseCPDCLITest %} have been deprecated with replacements.
- The methods {% jdoc !!core::ant.Formatter#start(java.lang.String) %},
{% jdoc !!core::ant.Formatter#end(net.sourceforge.pmd.Report) %}, {% jdoc !!core::ant.Formatter#getRenderer() %},
and {% jdoc !!core::ant.Formatter#isNoOutputSupplied() %} have been internalized.
#### 6.45.0
##### Experimental APIs
@ -1543,3 +1580,17 @@ large projects, with many duplications, it was causing `OutOfMemoryError`s (see
as it finds only contrived cases of creating a primitive wrapper and unboxing it explicitly
in the same expression. In PMD 7 this and more cases will be covered by a
new rule `UnnecessaryBoxing`.
* Since 6.46.0: The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule
{% rule java/codestyle/EmptyControlStatement %} merges their functionality:
* {% rule java/errorprone/EmptyFinallyBlock %}
* {% rule java/errorprone/EmptyIfStmt %}
* {% rule java/errorprone/EmptyInitializer %}
* {% rule java/errorprone/EmptyStatementBlock %}
* {% rule java/errorprone/EmptySwitchStatements %}
* {% rule java/errorprone/EmptySynchronizedBlock %}
* {% rule java/errorprone/EmptyTryBlock %}
* {% rule java/errorprone/EmptyWhileStmt %}
* Since 6.46.0: The Java rule {% rule java/errorprone/EmptyStatementNotInLoop %} is deprecated and removed from the quickstart
ruleset. Use the new rule {% rule java/codestyle/UnnecessarySemicolon %} instead.

View File

@ -3,17 +3,54 @@ title: Adding PMD support for a new ANTLR grammar based language
short_title: Adding a new language with ANTLR
tags: [devdocs, extending]
summary: "How to add a new language to PMD using ANTLR grammar."
last_updated: July 21, 2019
last_updated: October 2021
sidebar: pmd_sidebar
permalink: pmd_devdocs_major_adding_new_language_antlr.html
folder: pmd/devdocs
# needs to be changed to branch master instead of pmd/7.0.x
#
# needs to be changed to branch master instead of pmd/7.0.x once pmd7 is released
# https://github.com/pmd/pmd/blob/pmd/7.0.x -> https://github.com/pmd/pmd/blob/master
#
---
{% include callout.html type="warning" content="
## 1. Start with a new sub-module.
**Before you start...**<br><br>
This is really a big contribution and can't be done with a drive by contribution. It requires dedicated passion
and long commitment to implement support for a new language.<br><br>
This step by step guide is just a small intro to get the basics started and it's also not necessarily up-to-date
or complete and you have to be able to fill in the blanks.<br><br>
Currently the Antlr integration has some basic limitations compared to JavaCC: The output of the
Antlr parser generator is not an abstract syntax tree (AST) but a parse tree. As such, a parse tree is
much more fine-grained than what a typical JavaCC grammar will produce. This means that the
parse tree is much deeper and contains nodes down to the different token types.<br><br>
The Antlr nodes themselves don't have any attributes because they are on the wrong abstraction level.
As they don't have attributes, there are no attributes that can be used in XPath based rules.<br><br>
In order to overcome these limitations, one would need to implement a post-processing step that transforms
a parse tree into an abstract syntax tree and introducing real nodes on a higher abstraction level. This
step is **not** described in this guide.<br><br>
After the basic support for a language is there, there are lots of missing features left. Typical features
that can greatly improve rule writing are: symbol table, type resolution, call/data flow analysis.<br><br>
Symbol table keeps track of variables and their usages. Type resolution tries to find the actual class type
of each used type, following along method calls (including overloaded and overwritten methods), allowing
to query sub types and type hierarchy. This requires additional configuration of an auxiliary classpath.
Call and data flow analysis keep track of the data as it is moving through different execution paths
a program has.<br><br>
These features are out of scope of this guide. Type resolution and data flow are features that
definitely don't come for free. It is much effort and requires perseverance to implement.<br><br>
" %}
## 1. Start with a new sub-module
* See pmd-swift for examples.
## 2. Implement an AST parser for your language
@ -24,7 +61,7 @@ folder: pmd/devdocs
## 3. Create AST node classes
* The individual AST nodes are generated, but you need to define the common interface for them.
* You need a need to define the supertype interface for all nodes of the language. For that, we provide
* You need to define the supertype interface for all nodes of the language. For that, we provide
[`AntlrNode`](https://github.com/pmd/pmd/blob/pmd/7.0.x/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrNode.java).
* See [`SwiftNode`](https://github.com/pmd/pmd/blob/pmd/7.0.x/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/ast/SwiftNode.java)
as an example.
@ -52,7 +89,7 @@ folder: pmd/devdocs
## 4. Generate your parser
* Make sure, you have the property `<antlr4.visitor>true</antlr4.visitor>` in your `pom.xml` file.
* This is just a matter of building the language module. ANTLR is called via ant, and this step is added
to the phase `generate-sources`. So you can just call e.g. `./mvnw generate-source -pl pmd-swift` to
to the phase `generate-sources`. So you can just call e.g. `./mvnw generate-sources -pl pmd-swift` to
have the parser generated.
* The generated code will be placed under `target/generated-sources/antlr4` and will not be committed to
source control.

View File

@ -1,16 +1,40 @@
---
title: Adding PMD support for a new JAVACC grammar based language
short_title: Adding a new language with JAVACC
title: Adding PMD support for a new JavaCC grammar based language
short_title: Adding a new language with JavaCC
tags: [devdocs, extending]
summary: "How to add a new language to PMD using JAVACC grammar."
last_updated: October 5, 2019
summary: "How to add a new language to PMD using JavaCC grammar."
last_updated: October 2021
sidebar: pmd_sidebar
permalink: pmd_devdocs_major_adding_new_language_javacc.html
folder: pmd/devdocs
---
{% include callout.html type="warning" content="
## 1. Start with a new sub-module.
**Before you start...**<br><br>
This is really a big contribution and can't be done with a drive by contribution. It requires dedicated passion
and long commitment to implement support for a new language.<br><br>
This step by step guide is just a small intro to get the basics started and it's also not necessarily up-to-date
or complete and you have to be able to fill in the blanks.<br><br>
After the basic support for a language is there, there are lots of missing features left. Typical features
that can greatly improve rule writing are: symbol table, type resolution, call/data flow analysis.<br><br>
Symbol table keeps track of variables and their usages. Type resolution tries to find the actual class type
of each used type, following along method calls (including overloaded and overwritten methods), allowing
to query sub types and type hierarchy. This requires additional configuration of an auxiliary classpath.
Call and data flow analysis keep track of the data as it is moving through different execution paths
a program has.<br><br>
These features are out of scope of this guide. Type resolution and data flow are features that
definitely don't come for free. It is much effort and requires perseverance to implement.<br><br>
" %}
## 1. Start with a new sub-module
* See pmd-java or pmd-vm for examples.
## 2. Implement an AST parser for your language

View File

@ -14,5 +14,11 @@ last_updated: April 2022 (6.45.0)
The HTML language module uses [jsoup](https://jsoup.org/) for parsing.
XPath rules are supported, but the DOM is not a typical XML/XPath DOM. E.g.
text nodes are normal nodes. This might change in the future.
XPath 2.0 rules are supported, but the DOM is not always a typical XML/XPath DOM.
In the Designer, text nodes appear as nodes with name "#text", but they can
be selected as usual using `text()`.
XML Namespaces are not supported. The local name of attributes include the prefix,
so that you have to select attributes by e.g. `//*[@*[local-name() = 'if:true']]`.
Only XPath 1.0 rules are not supported.

View File

@ -0,0 +1,14 @@
---
title: Kotlin Support
permalink: pmd_languages_kotlin.html
tags: [languages]
summary: "Kotlin-specific features and guidance"
---
Kotlin support in PMD is based on the official grammar from <https://github.com/Kotlin/kotlin-spec>.
Java-based rules and XPath-based rules are supported.
{% include note.html content="Kotlin support has **experimental** stability level, meaning no compatibility should
be expected between even incremental releases. Any functionality can be added, removed or changed without
warning." %}

File diff suppressed because it is too large Load Diff

View File

@ -76,14 +76,14 @@ The tool comes with a rather extensive help text, simply running with `--help`!
%}
{% include custom/cli_option_row.html options="--file-list"
option_arg="filepath"
description="Path to file containing a comma delimited list of files to analyze.
description="Path to file containing a list of files to analyze, one path per line.
If this is given, then you don't need to provide `--dir`."
%}
{% include custom/cli_option_row.html options="--force-language"
option_arg="lang"
description="Force a language to be used for all input files, irrespective of
filenames. When using this option, the automatic language selection
by extension is disabled and all files are tried to be parsed with
file names. When using this option, the automatic language selection
by extension is disabled and PMD tries to parse all files with
the given language `&lt;lang&gt;`. Parsing errors are ignored and unparsable files
are skipped.
@ -92,9 +92,9 @@ The tool comes with a rather extensive help text, simply running with `--help`!
%}
{% include custom/cli_option_row.html options="--ignore-list"
option_arg="filepath"
description="Path to file containing a comma delimited list of files to ignore.
description="Path to file containing a list of files to ignore, one path per line.
This option can be combined with `--dir` and `--file-list`.
This ignore list takes precedence over any files in the filelist."
This ignore list takes precedence over any files in the file-list."
%}
{% include custom/cli_option_row.html options="--help,-h,-H"
description="Display help on usage."

View File

@ -112,9 +112,9 @@ Novice as much as advanced readers may want to [read on on Refactoring Guru](htt
languages="Java"
%}
{% include custom/cli_option_row.html options="--ignore-annotations"
description="Ignore language annotations when comparing text"
description="Ignore language annotations (Java) or attributes (C#) when comparing text"
default="false"
languages="Java"
languages="C#, Java"
%}
{% include custom/cli_option_row.html options="--ignore-literal-sequences"
description="Ignore sequences of literals (common e.g. in list initializers)"

View File

@ -197,7 +197,7 @@ To install the PMD plugin for Eclipse:
* Start Eclipse and open a project
* Select "Help"->"Software Updates"->"Find and Install"
* Click "Next", then click "New remote site"
* Enter "PMD" into the Name field and <https://dl.bintray.com/pmd/pmd-eclipse-plugin/updates/> into the URL field
* Enter "PMD" into the Name field and <https://pmd.github.io/pmd-eclipse-plugin-p2-site/> into the URL field
* Click through the rest of the dialog boxes to install the plugin
Alternatively, you can download the latest zip file and follow the above procedures

View File

@ -21,9 +21,6 @@ This is a {{ site.pmd.release_type }} release.
### Fixed Issues
* javascript
* [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal
### API Changes
### External Contributions

View File

@ -5,6 +5,220 @@ permalink: pmd_release_notes_old.html
Previous versions of PMD can be downloaded here: https://github.com/pmd/pmd/releases
## 25-June-2022 - 6.47.0
The PMD team is pleased to announce PMD 6.47.0.
This is a minor release.
### Table Of Contents
* [Fixed Issues](#fixed-issues)
* [API Changes](#api-changes)
* [External Contributions](#external-contributions)
* [Stats](#stats)
### Fixed Issues
* core
* [#3999](https://github.com/pmd/pmd/issues/3999): \[cli] All files are analyzed despite parameter `--file-list`
* [#4009](https://github.com/pmd/pmd/issues/4009): \[core] Cannot build PMD with Temurin 17
* java-bestpractices
* [#3824](https://github.com/pmd/pmd/issues/3824): \[java] UnusedPrivateField: Do not flag fields annotated with @<!-- -->Version
* [#3825](https://github.com/pmd/pmd/issues/3825): \[java] UnusedPrivateField: Do not flag fields annotated with @<!-- -->Id or @<!-- -->EmbeddedId
* java-design
* [#3823](https://github.com/pmd/pmd/issues/3823): \[java] ImmutableField: Do not flag fields in @<!-- -->Entity
* [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @<!-- -->Value (Spring)
* [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @<!-- -->Captor (Mockito)
* [#4004](https://github.com/pmd/pmd/issues/4004): \[java] ImmutableField reports fields annotated with @<!-- -->GwtMock (GwtMockito) and @<!-- -->Spy (Mockito)
* [#4008](https://github.com/pmd/pmd/issues/4008): \[java] ImmutableField not reporting fields that are only initialized in the declaration
* [#4011](https://github.com/pmd/pmd/issues/4011): \[java] ImmutableField: Do not flag fields annotated with @<!-- -->Inject
* [#4020](https://github.com/pmd/pmd/issues/4020): \[java] ImmutableField reports fields annotated with @<!-- -->FindBy and @<!-- -->FindBys (Selenium)
* java-errorprone
* [#3936](https://github.com/pmd/pmd/issues/3936): \[java] AvoidFieldNameMatchingMethodName should consider enum class
* [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases
### API Changes
No changes.
### External Contributions
* [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota)
* [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007)
* [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @<!-- -->Value (Spring) or @<!-- -->Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison)
* [#4003](https://github.com/pmd/pmd/pull/4003): \[java] UnusedPrivateField - Ignore fields annotated with @<!-- -->Id/@<!-- -->EmbeddedId/@<!-- -->Version (JPA) or @<!-- -->Mock/@<!-- -->Spy/@<!-- -->MockBean (Mockito/Spring) - [@jjlharrison](https://github.com/jjlharrison)
* [#4006](https://github.com/pmd/pmd/pull/4006): \[doc] Fix eclipse plugin update site URL - [@shiomiyan](https://github.com/shiomiyan)
* [#4010](https://github.com/pmd/pmd/pull/4010): \[core] Bump kotlin to version 1.7.0 - [@maikelsteneker](https://github.com/maikelsteneker)
### Stats
* 45 commits
* 23 closed tickets & PRs
* Days since last release: 27
## 28-May-2022 - 6.46.0
The PMD team is pleased to announce PMD 6.46.0.
This is a minor release.
### Table Of Contents
* [New and noteworthy](#new-and-noteworthy)
* [CLI improvements](#cli-improvements)
* [C# Improvements](#c#-improvements)
* [New Rules](#new-rules)
* [Deprecated Rules](#deprecated-rules)
* [Fixed Issues](#fixed-issues)
* [API Changes](#api-changes)
* [Deprecated ruleset references](#deprecated-ruleset-references)
* [Deprecated API](#deprecated-api)
* [Internal API](#internal-api)
* [External Contributions](#external-contributions)
* [Stats](#stats)
### New and noteworthy
#### CLI improvements
The PMD CLI now allows repeating the `--dir` (`-d`) and `--rulesets` (`-R`) options,
as well as providing several space-separated arguments to either of them. For instance:
```shell
pmd -d src/main/java src/test/java -R rset1.xml -R rset2.xml
```
This also allows globs to be used on the CLI if your shell supports shell expansion.
For instance, the above can be written
```shell
pmd -d src/*/java -R rset*.xml
```
Please use theses new forms instead of using comma-separated lists as argument to these options.
#### C# Improvements
When executing CPD on C# sources, the option `--ignore-annotations` is now supported as well.
It ignores C# attributes when detecting duplicated code. This option can also be enabled via
the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details.
#### New Rules
This release ships with 2 new Java rules.
* [`EmptyControlStatement`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_codestyle.html#emptycontrolstatement) reports many instances of empty things, e.g. control statements whose
body is empty, as well as empty initializers.
EmptyControlStatement also works for empty `for` and `do` loops, while there were previously
no corresponding rules.
This new rule replaces the rules EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock,
EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, and EmptyWhileStmt.
```xml
<rule ref="category/java/codestyle.xml/EmptyControlStatement"/>
```
The rule is part of the quickstart.xml ruleset.
* [`UnnecessarySemicolon`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_codestyle.html#unnecessarysemicolon) reports semicolons that are unnecessary (so called "empty statements"
and "empty declarations").
This new rule replaces the rule EmptyStatementNotInLoop.
```xml
<rule ref="category/java/codestyle.xml/UnnecessarySemicolon"/>
```
The rule is part of the quickstart.xml ruleset.
#### Deprecated Rules
* The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule
[`EmptyControlStatement`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_codestyle.html#emptycontrolstatement) merges their functionality:
* [`EmptyFinallyBlock`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptyfinallyblock)
* [`EmptyIfStmt`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptyifstmt)
* [`EmptyInitializer`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptyinitializer)
* [`EmptyStatementBlock`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptystatementblock)
* [`EmptySwitchStatements`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptyswitchstatements)
* [`EmptySynchronizedBlock`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptysynchronizedblock)
* [`EmptyTryBlock`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptytryblock)
* [`EmptyWhileStmt`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptywhilestmt)
* The Java rule [`EmptyStatementNotInLoop`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptystatementnotinloop) is deprecated and removed from the quickstart
ruleset. Use the new rule [`UnnecessarySemicolon`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_codestyle.html#unnecessarysemicolon) instead.
### Fixed Issues
* cli
* [#1445](https://github.com/pmd/pmd/issues/1445): \[core] Allow CLI to take globs as parameters
* core
* [#2352](https://github.com/pmd/pmd/issues/2352): \[core] Deprecate \<lang\>-\<ruleset\> hyphen notation for ruleset references
* [#3787](https://github.com/pmd/pmd/issues/3787): \[core] Internalize some methods in Ant Formatter
* [#3835](https://github.com/pmd/pmd/issues/3835): \[core] Deprecate system properties of CPDCommandLineInterface
* [#3942](https://github.com/pmd/pmd/issues/3942): \[core] common-io path traversal vulnerability (CVE-2021-29425)
* cs (c#)
* [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations)
* go
* [#2752](https://github.com/pmd/pmd/issues/2752): \[go] Error parsing unicode values
* html
* [#3955](https://github.com/pmd/pmd/pull/3955): \[html] Improvements for handling text and comment nodes
* [#3978](https://github.com/pmd/pmd/pull/3978): \[html] Add additional file extensions htm, xhtml, xht, shtml
* java
* [#3423](https://github.com/pmd/pmd/issues/3423): \[java] Error processing identifiers with Unicode
* java-bestpractices
* [#3954](https://github.com/pmd/pmd/issues/3954): \[java] NPE in UseCollectionIsEmptyRule when .size() is called in a record
* java-design
* [#3874](https://github.com/pmd/pmd/issues/3874): \[java] ImmutableField reports fields annotated with @Autowired (Spring) and @Mock (Mockito)
* java-errorprone
* [#3096](https://github.com/pmd/pmd/issues/3096): \[java] EmptyStatementNotInLoop FP in 6.30.0 with IfStatement
* java-performance
* [#3379](https://github.com/pmd/pmd/issues/3379): \[java] UseArraysAsList must ignore primitive arrays
* [#3965](https://github.com/pmd/pmd/issues/3965): \[java] UseArraysAsList false positive with non-trivial loops
* javascript
* [#2605](https://github.com/pmd/pmd/issues/2605): \[js] Support unicode characters
* [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal
* python
* [#2604](https://github.com/pmd/pmd/issues/2604): \[python] Support unicode identifiers
### API Changes
#### Deprecated ruleset references
Ruleset references with the following formats are now deprecated and will produce a warning
when used on the CLI or in a ruleset XML file:
- `<lang-name>-<ruleset-name>`, eg `java-basic`, which resolves to `rulesets/java/basic.xml`
- the internal release number, eg `600`, which resolves to `rulesets/releases/600.xml`
Use the explicit forms of these references to be compatible with PMD 7.
#### Deprecated API
- <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.46.0/net/sourceforge/pmd/RuleSetReferenceId.html#toString()"><code>toString</code></a> is now deprecated. The format of this
method will remain the same until PMD 7. The deprecation is intended to steer users
away from relying on this format, as it may be changed in PMD 7.
- <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.46.0/net/sourceforge/pmd/PMDConfiguration.html#getInputPaths()"><code>getInputPaths</code></a> and
<a href="https://docs.pmd-code.org/apidocs/pmd-core/6.46.0/net/sourceforge/pmd/PMDConfiguration.html#setInputPaths(java.lang.String)"><code>setInputPaths</code></a> are now deprecated.
A new set of methods have been added, which use lists and do not rely on comma splitting.
#### Internal API
Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0.
You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning.
- <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.46.0/net/sourceforge/pmd/cpd/CPDCommandLineInterface.html#"><code>CPDCommandLineInterface</code></a> has been internalized. In order to execute CPD either
<a href="https://docs.pmd-code.org/apidocs/pmd-core/6.46.0/net/sourceforge/pmd/cpd/CPD.html#run(java.lang.String...)"><code>CPD#run</code></a> or <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.46.0/net/sourceforge/pmd/cpd/CPD.html#main(java.lang.String[])"><code>CPD#main</code></a>
should be used.
- Several members of <a href="https://docs.pmd-code.org/apidocs/pmd-test/6.46.0/net/sourceforge/pmd/cli/BaseCPDCLITest.html#"><code>BaseCPDCLITest</code></a> have been deprecated with replacements.
- The methods <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.46.0/net/sourceforge/pmd/ant/Formatter.html#start(java.lang.String)"><code>Formatter#start</code></a>,
<a href="https://docs.pmd-code.org/apidocs/pmd-core/6.46.0/net/sourceforge/pmd/ant/Formatter.html#end(net.sourceforge.pmd.Report)"><code>Formatter#end</code></a>, <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.46.0/net/sourceforge/pmd/ant/Formatter.html#getRenderer()"><code>Formatter#getRenderer</code></a>,
and <a href="https://docs.pmd-code.org/apidocs/pmd-core/6.46.0/net/sourceforge/pmd/ant/Formatter.html#isNoOutputSupplied()"><code>Formatter#isNoOutputSupplied</code></a> have been internalized.
### External Contributions
* [#3961](https://github.com/pmd/pmd/pull/3961): \[java] Fix #3954 - NPE in UseCollectionIsEmptyRule with record - [@flyhard](https://github.com/flyhard)
* [#3964](https://github.com/pmd/pmd/pull/3964): \[java] Fix #3874 - ImmutableField: fix mockito/spring false positives - [@lukelukes](https://github.com/lukelukes)
* [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) - [@maikelsteneker](https://github.com/maikelsteneker)
### Stats
* 92 commits
* 30 closed tickets & PRs
* Days since last release: 28
## 30-April-2022 - 6.45.0
The PMD team is pleased to announce PMD 6.45.0.

View File

@ -9,7 +9,7 @@
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>
<properties>

View File

@ -8,7 +8,7 @@
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>
<build>
@ -61,10 +61,6 @@
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>

View File

@ -11,18 +11,18 @@ import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import org.apache.commons.io.FilenameUtils;
import org.junit.Before;
import org.junit.Test;
import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
import net.sourceforge.pmd.util.IOUtil;
public class ApexCpdTest {
private File testdir;
@Before
public void setUp() {
String path = FilenameUtils.normalize("src/test/resources/net/sourceforge/pmd/cpd/issue427");
String path = IOUtil.normalizePath("src/test/resources/net/sourceforge/pmd/cpd/issue427");
testdir = new File(path);
}

View File

@ -17,13 +17,12 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.document.FileLocation;
import net.sourceforge.pmd.util.IOUtil;
public class ApexParserTest extends ApexParserTestBase {
@ -158,7 +157,7 @@ public class ApexParserTest extends ApexParserTestBase {
for (File file : fList) {
if (file.isFile() && file.getName().endsWith(".cls")) {
String sourceCode = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
String sourceCode = IOUtil.readFileToString(file, StandardCharsets.UTF_8);
Assert.assertNotNull(parse(sourceCode));
}
}
@ -170,7 +169,7 @@ public class ApexParserTest extends ApexParserTestBase {
*/
@Test
public void parseInheritedSharingClass() throws IOException {
String source = IOUtils.toString(ApexParserTest.class.getResourceAsStream("InheritedSharing.cls"),
String source = IOUtil.readToString(ApexParserTest.class.getResourceAsStream("InheritedSharing.cls"),
StandardCharsets.UTF_8);
parse(source);
}
@ -182,7 +181,7 @@ public class ApexParserTest extends ApexParserTestBase {
*/
@Test
public void stackOverflowDuringClassParsing() throws Exception {
String source = IOUtils.toString(ApexParserTest.class.getResourceAsStream("StackOverflowClass.cls"),
String source = IOUtil.readToString(ApexParserTest.class.getResourceAsStream("StackOverflowClass.cls"),
StandardCharsets.UTF_8);
ASTUserClassOrInterface<?> rootNode = parse(source);

Some files were not shown because too many files have changed in this diff Show More