Merge branch 'master' into issue-2847-new-rule-explicit-types

This commit is contained in:
Andreas Dangel committed 2023-08-28 20:26:17 +02:00
commit 5d873fd241
384 files changed
+8047 -8576

No files matched your search

+31 -2
View File
@@ -2679,7 +2679,7 @@
]
},
{
"login": "Fernal73",
"login": "linusjf",
"name": "Linus Fernandes",
"avatar_url": "https://avatars.githubusercontent.com/u/24714685?v=4",
"profile": "https://linusfernandes.com/",
@@ -4496,7 +4496,8 @@
"avatar_url": "https://avatars.githubusercontent.com/u/25647167?v=4",
"profile": "https://github.com/nawforce",
"contributions": [
"bug"
"bug",
"code"
]
},
{
@@ -7173,6 +7174,34 @@
"contributions": [
"doc"
]
},
{
"login": "wener-tiobe",
"name": "Wener",
"avatar_url": "https://avatars.githubusercontent.com/u/85687939?v=4",
"profile": "https://github.com/wener-tiobe",
"contributions": [
"code"
]
},
{
"login": "anastasiia-koba",
"name": "Anastasiia Koba",
"avatar_url": "https://avatars.githubusercontent.com/u/42797303?v=4",
"profile": "https://github.com/anastasiia-koba",
"contributions": [
"code"
]
},
{
"login": "krdabrowski",
"name": "Krystian Dabrowski",
"avatar_url": "https://avatars.githubusercontent.com/u/98942253?v=4",
"profile": "https://github.com/krdabrowski",
"contributions": [
"bug",
"code"
]
}
],
"contributorsPerLine": 7,
+15 -15
View File
@@ -30,7 +30,7 @@ function build() {
if pmd_ci_utils_is_fork_or_pull_request; then
pmd_ci_log_group_start "Build with mvnw"
./mvnw clean install --show-version --errors --batch-mode --no-transfer-progress "${PMD_MAVEN_EXTRA_OPTS[@]}"
./mvnw clean install --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
pmd_ci_log_group_end
# Execute danger and dogfood only for pull requests in our own repository
@@ -64,7 +64,7 @@ function build() {
if [ "$(pmd_ci_utils_get_os)" != "linux" ]; then
pmd_ci_log_group_start "Build with mvnw"
./mvnw clean verify --show-version --errors --batch-mode --no-transfer-progress "${PMD_MAVEN_EXTRA_OPTS[@]}"
./mvnw clean verify --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
pmd_ci_log_group_end
pmd_ci_log_info "Stopping build here, because os is not linux"
@@ -81,7 +81,7 @@ function build() {
if [ "${PMD_CI_BRANCH}" = "experimental-apex-parser" ]; then
pmd_ci_log_group_start "Build with mvnw"
./mvnw clean install --show-version --errors --batch-mode --no-transfer-progress "${PMD_MAVEN_EXTRA_OPTS[@]}"
./mvnw clean install --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
pmd_ci_log_group_end
pmd_ci_log_group_start "Creating new baseline for regression tester"
@@ -128,7 +128,7 @@ function build() {
-Dmaven.source.skip \
-Dcheckstyle.skip \
-Dpmd.skip \
--show-version --errors --batch-mode --no-transfer-progress \
--show-version --errors --batch-mode \
clean package \
sonar:sonar -Dsonar.login="${SONAR_TOKEN}" -Psonar
pmd_ci_log_success "New sonar results: https://sonarcloud.io/dashboard?id=net.sourceforge.pmd%3Apmd"
@@ -144,7 +144,7 @@ function build() {
-Dcheckstyle.skip \
-Dpmd.skip \
-DrepoToken="${COVERALLS_REPO_TOKEN}" \
--show-version --errors --batch-mode --no-transfer-progress \
--show-version --errors --batch-mode \
clean package jacoco:report \
coveralls:report -Pcoveralls
pmd_ci_log_success "New coveralls result: https://coveralls.io/github/pmd/pmd"
@@ -176,7 +176,7 @@ function pmd_ci_build_run() {
pmd_ci_log_info "This is a snapshot build"
fi
./mvnw clean deploy -P${mvn_profiles} --show-version --errors --batch-mode --no-transfer-progress "${PMD_MAVEN_EXTRA_OPTS[@]}"
./mvnw clean deploy -P${mvn_profiles} --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}"
}
#
@@ -184,8 +184,8 @@ function pmd_ci_build_run() {
#
function pmd_ci_deploy_build_artifacts() {
# Deploy to sourceforge files https://sourceforge.net/projects/pmd/files/pmd/
pmd_ci_sourceforge_uploadFile "pmd/${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-bin-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
pmd_ci_sourceforge_uploadFile "pmd/${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-src-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
pmd_ci_sourceforge_uploadFile "pmd/${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-bin.zip"
pmd_ci_sourceforge_uploadFile "pmd/${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-src.zip"
# Deploy SBOM
cp pmd-dist/target/bom.xml "pmd-dist/target/pmd-${PMD_CI_MAVEN_PROJECT_VERSION}-cyclonedx.xml"
cp pmd-dist/target/bom.json "pmd-dist/target/pmd-${PMD_CI_MAVEN_PROJECT_VERSION}-cyclonedx.json"
@@ -198,8 +198,8 @@ function pmd_ci_deploy_build_artifacts() {
GH_RELEASE="$RESULT"
# Deploy to github releases
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-bin-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-src-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-bin.zip"
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-src.zip"
# Deploy SBOM
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-${PMD_CI_MAVEN_PROJECT_VERSION}-cyclonedx.xml"
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-${PMD_CI_MAVEN_PROJECT_VERSION}-cyclonedx.json"
@@ -214,13 +214,13 @@ function pmd_ci_build_and_upload_doc() {
pmd_doc_generate_jekyll_site
pmd_doc_create_archive
pmd_ci_sourceforge_uploadFile "pmd/${PMD_CI_MAVEN_PROJECT_VERSION}" "docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
pmd_ci_sourceforge_uploadFile "pmd/${PMD_CI_MAVEN_PROJECT_VERSION}" "docs/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-doc.zip"
if pmd_ci_maven_isReleaseBuild; then
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "docs/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-doc.zip"
fi
# Deploy doc to https://docs.pmd-code.org/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/
pmd_code_uploadDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}" "docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
pmd_code_uploadDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}" "docs/pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-doc.zip"
# Deploy javadoc to https://docs.pmd-code.org/apidocs/*/${PMD_CI_MAVEN_PROJECT_VERSION}/
pmd_code_uploadJavadoc "${PMD_CI_MAVEN_PROJECT_VERSION}" "$(pwd)"
@@ -284,9 +284,9 @@ function pmd_ci_dogfood() {
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.20.1-pmd-7-SNAPSHOT)
mpmdVersion=(-Denforcer.skip=true -Dpmd.plugin.version=3.21.1-pmd-7-SNAPSHOT)
fi
./mvnw verify --show-version --errors --batch-mode --no-transfer-progress "${PMD_MAVEN_EXTRA_OPTS[@]}" \
./mvnw verify --show-version --errors --batch-mode "${PMD_MAVEN_EXTRA_OPTS[@]}" \
"${mpmdVersion[@]}" \
-DskipTests \
-Dmaven.javadoc.skip=true \
+2 -2
View File
@@ -35,8 +35,8 @@ function pmd_doc_create_archive() {
echo -e "\n\n"
pmd_ci_log_info "Creating pmd-doc archive..."
mv _site "pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}"
zip -qr "pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" "pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/"
pmd_ci_log_success "Successfully created pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
zip -qr "pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-doc.zip" "pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/"
pmd_ci_log_success "Successfully created pmd-dist-${PMD_CI_MAVEN_PROJECT_VERSION}-doc.zip"
popd || exit 1
}
+1
View File
@@ -50,6 +50,7 @@ function regression_tester_uploadBaseline() {
--patch-branch "${baseline_branch}" \
--patch-config ./pmd/.ci/files/all-regression-rules.xml \
--list-of-project ./pmd/.ci/files/project-list.xml --html-flag \
--threads "$(nproc)" \
--error-recovery
pushd target/reports || { echo "Directory 'target/reports' doesn't exist"; exit 1; }
BRANCH_FILENAME="${baseline_branch/\//_}"
+11 -2
View File
@@ -54,8 +54,8 @@ jobs:
shell: bash
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/21/scripts" >> $GITHUB_ENV
echo "MAVEN_OPTS=-Daether.connector.http.connectionMaxTtl=180 -DautoReleaseAfterClose=true -DstagingProgressTimeoutMinutes=30" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/master/scripts" >> $GITHUB_ENV
- name: Check Environment
shell: bash
run: |
@@ -70,3 +70,12 @@ jobs:
env:
PMD_CI_SECRET_PASSPHRASE: ${{ secrets.PMD_CI_SECRET_PASSPHRASE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Workaround actions/upload-artifact#176
run: |
echo "artifacts_path=$(realpath ..)" >> $GITHUB_ENV
- name: Upload regression tester report
uses: actions/upload-artifact@v3
with:
name: pmd-regression-tester
path: ${{ env.artifacts_path }}/target/pr-*-diff-report-*.tar.gz
if-no-files-found: ignore
+1 -1
View File
@@ -24,7 +24,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/21/scripts" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/master/scripts" >> $GITHUB_ENV
- name: Sync
run: .ci/git-repo-sync.sh
shell: bash
+2 -2
View File
@@ -35,8 +35,8 @@ jobs:
shell: bash
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/21/scripts" >> $GITHUB_ENV
echo "MAVEN_OPTS=-Daether.connector.http.connectionMaxTtl=180 -DstagingProgressTimeoutMinutes=30" >> $GITHUB_ENV
echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/master/scripts" >> $GITHUB_ENV
- name: Check Environment
shell: bash
run: |
+2 -2
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.9.0/apache-maven-3.9.0-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
+12 -22
View File
@@ -2,6 +2,7 @@ require 'pmdtester'
require 'time'
require 'logger'
require 'fileutils'
require 'etc'
@logger = Logger.new(STDOUT)
@@ -16,6 +17,7 @@ def get_args(base_branch, autogen = TRUE, patch_config = './pmd/.ci/files/all-re
'--keep-reports',
'--error-recovery',
'--baseline-download-url', 'https://pmd-code.org/pmd-regression-tester/',
'--threads', Etc.nprocessors.to_s,
# '--debug',
]
end
@@ -49,18 +51,16 @@ def run_pmdtester
message2 = create_message
end
report_url = upload_report
tar_report
if report_url
message1 += "[Full report](#{report_url}/diff1/index.html)"
message1 += "[Download full report as build artifact](#{ENV['PMD_CI_JOB_URL']})"
# set value of sticky to true and the message is kept after new commits are submitted to the PR
message(message1, sticky: true)
if message2
message2 += "[Download full report as build artifact](#{ENV['PMD_CI_JOB_URL']})"
# set value of sticky to true and the message is kept after new commits are submitted to the PR
message(message1, sticky: true)
if message2
message2 += "[Full report](#{report_url}/diff2/index.html)"
# set value of sticky to true and the message is kept after new commits are submitted to the PR
message(message2, sticky: true)
end
message(message2, sticky: true)
end
rescue StandardError => e
@@ -82,23 +82,13 @@ def create_message
"#{@summary[:configerrors][:removed]} configuration errors.\n"
end
def upload_report
def tar_report
Dir.chdir('target') do
tar_filename = "pr-#{ENV['PMD_CI_PULL_REQUEST_NUMBER']}-diff-report-#{Time.now.strftime("%Y-%m-%dT%H-%M-%SZ")}.tar.gz"
`tar czf #{tar_filename} diff1/ diff2/`
tar_size = (10 * File.size(tar_filename) / 1024 / 1024)/10.0
@logger.info "Uploading file #{tar_filename} (#{tar_size}mb) now..."
report_url = `curl -u #{ENV['PMD_CI_CHUNK_TOKEN']} -T #{tar_filename} https://chunk.io`
if $?.success?
report_url.chomp!
@logger.info "Successfully uploaded #{tar_filename} to #{report_url}"
report_url
else
@logger.error "Error while uploading #{tar_filename} to chunk.io: #{report_url}"
warn("Uploading the diff report failed, this message is mainly used to remind the maintainers of PMD.")
nil
end
@logger.info "Created file #{tar_filename} (#{tar_size}mb)"
end
end
+6 -6
View File
@@ -28,7 +28,7 @@ GEM
differ (0.1.2)
et-orbi (1.2.7)
tzinfo
faraday (2.7.4)
faraday (2.7.5)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-http-cache (2.5.0)
@@ -46,17 +46,17 @@ GEM
kramdown (~> 2.0)
liquid (5.4.0)
logger-colors (1.0.0)
mini_portile2 (2.8.1)
mini_portile2 (2.8.2)
nap (1.1.0)
no_proxy_fix (0.1.2)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
nokogiri (1.15.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
octokit (5.6.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
open4 (1.3.4)
pmdtester (1.5.3)
pmdtester (1.5.4)
differ (~> 0.1)
liquid (~> 5.4)
logger-colors (~> 1.0)
@@ -68,7 +68,7 @@ GEM
racc (1.6.2)
rchardet (1.8.0)
rexml (3.2.5)
rouge (4.1.0)
rouge (4.1.1)
ruby2_keywords (0.0.5)
rufus-scheduler (3.8.2)
fugit (~> 1.1, >= 1.1.6)
+5 -5
View File
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.4.3)
activesupport (7.0.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
@@ -24,7 +24,7 @@ GEM
ffi (>= 1.15.0)
eventmachine (1.2.7)
execjs (2.8.1)
faraday (2.7.4)
faraday (2.7.5)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
@@ -205,14 +205,14 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.3.6)
mini_portile2 (2.8.1)
mini_portile2 (2.8.2)
minima (2.5.1)
jekyll (>= 3.5, < 5.0)
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
minitest (5.18.0)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
nokogiri (1.15.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
octokit (4.25.1)
faraday (>= 1, < 3)
+1 -1
View File
@@ -3,7 +3,7 @@ repository: pmd/pmd
pmd:
version: 7.0.0-SNAPSHOT
previous_version: 6.55.0
date: 27-May-2023
date: ??-?????-2023
release_type: major
# release types: major, minor, bugfix
+3
View File
@@ -436,6 +436,9 @@ entries:
- title: Julia
url: /pmd_languages_julia.html
output: web, pdf
- title: Coco
url: /pmd_languages_coco.html
output: web, pdf
- title: Developer Documentation
output: web, pdf
folderitems:
+4 -1
View File
@@ -13,7 +13,10 @@ layout: default
{% if page.summary %}
<div class="summary">{{page.summary}}</div>
{% endif %}
<div id="inline-toc"><!-- empty, move TOC here when screen size too small --></div>
<details id="inline-toc-details">
<summary>Table of Contents</summary>
<div id="inline-toc"><!-- empty, move TOC here when screen size too small --></div>
</details>
{{content}}
+11 -2
View File
@@ -1007,9 +1007,9 @@ span.soft {
}
}
@media (max-width: 990px) {
@media (min-height: 600px) and (min-width: 990px) {
#mysidebar {
position: relative;
position: fixed !important;
}
}
@@ -1025,6 +1025,15 @@ span.soft {
}
}
#inline-toc-details {
display: none;
}
@media (max-width: 1350px) {
#inline-toc-details {
display: block;
}
}
.col-md-9 img {
max-width: 100%;
max-height: 100%;
+1 -1
View File
@@ -26,7 +26,7 @@ additional_js:
**PMD** is a static source code analyzer. It finds common programming flaws like
unused variables, empty catch blocks, unnecessary object creation, and
so forth. It's mainly concerned with **Java and Apex**, but **supports 14 other
so forth. It's mainly concerned with **Java and Apex**, but **supports 16 other
languages**.
PMD features many **built-in checks** (in PMD lingo, *rules*), which are documented
-11
View File
@@ -17,17 +17,6 @@ $(document).ready(function () {
headers: 'h2,h3,h4',
});
$('#mysidebar').height($(".nav").height());
// this script says, if the height of the viewport is greater than 600px, then insert position-fixed class,
// which makes the nav bar float in a fixed position as your scroll. If you have a lot of nav items,
// this height may not work for you.
var h = $(window).height();
//console.log (h);
if (h > 600) {
$( '#mysidebar' ).attr('class', 'nav position-fixed');
}
// activate tooltips. although this is a bootstrap js function, it must be activated this way in your theme.
$('[data-toggle="tooltip"]').tooltip({
placement: 'top',
+13
View File
@@ -0,0 +1,13 @@
---
title: Coco
permalink: pmd_languages_coco.html
---
Coco is a modern programming language designed specifically for building event-driven software.
It is part of the Coco Platform from <https://cocotec.io/>.
## Support in PMD
Starting from version 7.0.0, Coco support was added to CPD.
### Limitations
- Support for Coco only extends to CPD to detect code duplication in Coco source files.
File diff suppressed because it is too large. Load diff
+4 -4
View File
@@ -127,10 +127,10 @@ The tool comes with a rather extensive help text, simply running with `--help`!
%}
{% include custom/cli_option_row.html options="--minimum-priority"
option_arg="priority"
description="Rule priority threshold; rules with lower priority
than configured here won't be used.
Valid values (case insensitive): High, Medium High,
Medium, Medium Low, Low"
description="Rule priority threshold; rules with lower priority than configured here won't be used.
Valid values (case insensitive): High, Medium_High, Medium, Medium_Low, Low.
An integer between 1 (High) and 5 (Low) is also supported. See [Configuring rules](pmd_userdocs_configuring_rules.html)
on how to override priorities in custom rulesets."
default="Low"
%}
{% include custom/cli_option_row.html options="--no-ruleset-compatibility"
+12 -5
View File
@@ -4,7 +4,7 @@ short_title: Configuring rules
keywords: [property, properties, message, priority]
tags: [userdocs, getting_started]
summary: "Learn how to configure your rules directly from the ruleset XML."
last_updated: May 2018 (6.4.0)
last_updated: May 2023 (7.0.0)
permalink: pmd_userdocs_configuring_rules.html
author: Hooper Bloob <hooperbloob@users.sourceforge.net>, Romain Pelisse <rpelisse@users.sourceforge.net>, Clément Fournier <clement.fournier76@gmail.com>
---
@@ -17,13 +17,20 @@ value and change the message the rule will print on the report.
Similarly, the **priority** of a rule can be changed via a nested
element. Using priority, you can deactivate some rules based on a
minimum priority threshold (set using the `-min` CLI option).
Priority is an integer ranging from 1 to 5, with 1 being the highest
priority.
minimum priority threshold (set using the `--minimum-priority` CLI option).
Priority in the ruleset is an integer ranging from 1 to 5, with 1 being the highest
priority. On the command line, you can either use the integer or the following values:
| Priority | --minimum-priority value |
|----------|--------------------------|
| 1 | High |
| 2 | Medium_High |
| 3 | Medium |
| 4 | Medium_Low |
| 5 | Low |
Putting things together, the following rule reference lowers the priority
of EmptyCatchBlock to 5, such that e.g. using the `-min 4` CLI parameters
of EmptyCatchBlock to 5 ("Low"), such that e.g. using the `--minimum-priority=Medium_Low` CLI parameters
will cause the rule to be ignored.
```xml
+18 -9
View File
@@ -144,6 +144,11 @@ Novice as much as advanced readers may want to [read on on Refactoring Guru](htt
default="false"
languages="C#, C++, Lua"
%}
{% include custom/cli_option_row.html options="--ignore-sequences"
description="Ignore sequences of identifier and literals"
default="false"
languages="C++"
%}
{% include custom/cli_option_row.html options="--ignore-usings"
description="Ignore `using` directives in C# when comparing text"
default="false"
@@ -261,30 +266,34 @@ to be "debug".
* C#
* C/C++
* [Coco](pmd_languages_coco.html)
* Dart
* EcmaScript (JavaScript)
* Fortran
* Gherkin (Cucumber)
* [Gherkin](pmd_languages_gherkin.html) (Cucumber)
* Go
* Groovy
* Html
* Java
* Jsp
* Kotlin
* [Html](pmd_languages_html.html)
* [Java](pmd_languages_java.html)
* [Jsp](pmd_languages_jsp.html)
* [Julia](pmd_languages_julia.html)
* [Kotlin](pmd_languages_kotlin.html)
* Lua
* Matlab
* Modelica
* Objective-C
* Perl
* PHP
* PL/SQL
* [PL/SQL](pmd_languages_plsql.html)
* Python
* Ruby
* Salesforce.com Apex
* [Salesforce.com Apex](pmd_languages_apex.html)
* Scala
* Swift
* Visualforce
* XML
* T-SQL
* [TypeScript](pmd_languages_js_ts.html)
* [Visualforce](pmd_languages_visualforce.html)
* [XML](pmd_languages_xml.html)
## Available report formats
@@ -3,7 +3,7 @@ title: Defining rule properties
short_title: Defining rule properties
tags: [extending, userdocs]
summary: "Learn how to define your own properties both for Java and XPath rules."
last_updated: February 2020 (6.22.0)
last_updated: August 2022 (7.0.0)
permalink: pmd_userdocs_extending_defining_properties.html
author: Hooper Bloob <hooperbloob@users.sourceforge.net>, Romain Pelisse <rpelisse@users.sourceforge.net>, Clément Fournier <clement.fournier76@gmail.com>
---
@@ -27,7 +27,7 @@ The basic thing you need to do as a developer is to define a **property descript
* Its *description*, for documentation purposes;
* Its *default value*
Don't worry, all of these attributes can be specified in a single Java statement (or xml element for XPath rules).
All of these attributes can be specified in a single Java statement (or XML element for XPath rules).
## For Java rules
@@ -43,7 +43,7 @@ You can then retrieve the value of the property at any time using {% jdoc !a!pro
Properties can be built using type-specific **builders**, which can be obtained
from the factory methods of {% jdoc :PF %}. For example, to build a
string property, you'd call
string property, you would call
```java
PropertyFactory.stringProperty("myProperty")
.desc("This is my property")
@@ -53,51 +53,42 @@ PropertyFactory.stringProperty("myProperty")
This is fairly more readable than a constructor call, but keep in mind the description and the default value are not optional.
{%include note.html
content='As of version 6.10.0, all property concrete classes are deprecated for
removal in 7.0.0. See the <a href="pmd_release_notes_pmd7.html#properties-framework">detailed list of planned removals</a> for
information about how to migrate.' %}
For **numeric properties**, you can add constraints on the range of acceptable values, e.g.
```java
PropertyFactory.intProperty("myIntProperty")
.desc("This is my property")
.defaultValue(3)
.require(positive())
.range(0, 100)
.require(positive()) // must be > 0
.require(below(100)) // must be <= 100
.build();
```
The {% jdoc props::constraints.NumericConstraints#positive() %} method is part of
the {% jdoc props::constraints.NumericConstraints %} class, which provides some
other constraints. The constraint mechanism will be completely unlocked with 7.0.0,
since we'll be migrating our API to Java 8.
Predefined constraints such as `positive` and `below` are available in the class {% jdoc props::NumericConstraints %}.
A custom constraint can be implemented by implementing the interface {% jdoc props::PropertyConstraint %}.
**Enumerated properties** are a bit less straightforward to define, though they are
arguably more powerful. These properties don't have a specific value type, instead,
**Enumerated properties** do not have a specific value type, instead,
you can choose any type of value, provided the values are from a closed set. To make
that actionable, you give string labels to each of the acceptable values, and the user
will provide one of those labels as a value in the XML. The property will give you back
the associated value, not the label. Here's an example:
```java
static Map<String, ModeStrategy> map = new HashMap<>();
static {
map.put("easyMode", new EasyStrategy());
map.put("hardMode", new HardStrategy());
enum Mode {
Easy, Hard
}
static PropertyDescriptor<ModeStrategy> modeProperty
= PropertyFactory.enumProperty("modeProperty", map)
// Using this method, the labels are the `toString` of each enum constant.
// To customize this look at the overloads of `enumProperty`.
static PropertyDescriptor<Mode> modeProperty
= PropertyFactory.enumProperty("modeProperty", Mode.class)
.desc("This is my property")
.defaultValue(new EasyStrategy())
.defaultValue(Mode.Easy)
.build();
```
### Example
You can see an example of properties used in a PMD rule [here](https://github.com/pmd/pmd/blob/d06b01785a712e61d33f366520f37c2473f5bd1a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SingularFieldRule.java#L43-L52).
You can see an example of properties used in a PMD rule such as [AvoidReassigningLoopVariables](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidReassigningLoopVariablesRule.java#L40).
There are several things to notice here:
* The property descriptors are declared `static final`, which should generally be
the case, as descriptors are immutable and can be shared between instances of the same rule;
@@ -114,22 +105,15 @@ doesn't change).
XPath rules can also define their own properties. To do so, you must add a `property` element in the `properties` element of your rule, which **declares the `type` attribute**. This attribute conditions what type the underlying property has, and can have the following values:
| `type` attribute | XSD type
|----------|----------|
|Integer | xs:integer
|Long | xs:integer
|Double | xs:decimal
|Boolean | xs:boolean
|String | xs:string
|Character| xs:string
|Regex | xs:string
{% include note.html
content="In XPath 1.0 mode, all values are actually represented as
string values, which is mostly fine as there is no type
checking. This is a problem when [migrating from XPath 1.0
to 2.0](pmd_userdocs_extending_writing_xpath_rules.html#migrating-from-10-to-20) though" %}
| `type` attribute | XSD type |
|------------------|------------|
| Integer | xs:integer |
| Long | xs:integer |
| Double | xs:decimal |
| Boolean | xs:boolean |
| String | xs:string |
| Character | xs:string |
| Regex | xs:string |
Note that enumerated properties are not available in XPath rules (yet?).
@@ -160,20 +144,17 @@ You can then use the property in XPath with the syntax `$propertyName`, for exam
### Multivalued properties
Multivalued properties are also allowed and their `type` attribute has the form
`List[Boolean]` or `List[Character]`, with every above type allowed. These
properties **require XPath 2.0** to work properly, and make use of the
**sequence datatype** provided by that language. You thus need to set the
`version` property to `2.0` to use them. Properties can also declare the
`delimiter` attribute.
`List[Boolean]` or `List[Character]`, with every above type allowed. These properties
make use of the **sequence datatype** provided by XPath 2.0 and above.
When providing multiple values, the delimiter is a simple comma ("`,`"). The comma can be escaped
with a backslash when needed.
```xml
<rule name="MyXpathRule" ...>
<properties>
<property name="version" value="2.0" />
<property name="intProp" type="List[Integer]" value="1,2,5" description="An IntegerMultiProperty." />
<property name="reportedIdentifiers" type="List[String]" value="foo$bar" delimiter="$"
<property name="reportedIdentifiers" type="List[String]" value="foo,bar"
description="A StringMultiProperty." />
<property name="xpath">
<![CDATA[
@@ -2,7 +2,7 @@
title: Rule guidelines
tags: [extending, userdocs]
summary: "Rule Guidelines, or the last touches to a rule"
last_updated: February 2020 (6.22.0)
last_updated: Mai 2023 (7.0.0)
permalink: pmd_userdocs_extending_rule_guidelines.html
author: Xavier Le Vourch, Ryan Gustafson, Romain Pelisse
---
@@ -12,26 +12,38 @@ Here is a bunch of thing to do you may consider once your rule is “up and runn
## How to define rules priority
Rule priority may, of course, changes a lot depending on the context of the project. However, you can use the following guidelines to assert the legitimate priority of your rule:
Rule priority may, of course, changes a lot depending on the context of the project. However, you can use the
following guidelines to assert the legitimate priority of your rule:
1. **Change absolutely required.** Behavior is critically broken/buggy.
2. **Change highly recommended.** Behavior is quite likely to be broken/buggy.
3. **Change recommended.** Behavior is confusing, perhaps buggy, and/or against standards/best practices.
4. **Change optional.** Behavior is not likely to be buggy, but more just flies in the face of standards/style/good taste.
5. **Change highly optional.** Nice to have, such as a consistent naming policy for package/class/fields…
1. **High: Change absolutely required.** Behavior is critically broken/buggy.
2. **Medium High: Change highly recommended.** Behavior is quite likely to be broken/buggy.
3. **Medium: Change recommended.** Behavior is confusing, perhaps buggy, and/or against standards/best practices.
4. **Medium Low: Change optional.** Behavior is not likely to be buggy, but more just flies in the face of
standards/style/good taste.
5. **Low: Change highly optional.** Nice to have, such as a consistent naming policy for package/class/fields…
For instance, lets take the ExplicitCallToGC rule (“Do not explicitly trigger a garbage collection.”). Calling GC is a bad idea, but it doesnt break the application. So we skip priority one. However, as explicit call to gc may really hinder application performances, we set for the priority 2.
For instance, let's take the DoNotCallGarbageCollectionExplicitly rule
(“Do not explicitly trigger a garbage collection.”). Calling GC is
a bad idea, but it doesn't break the application. So we skip priority one. However, as explicit call to gc may really
hinder application performances, we set for the priority 2 ("Medium High").
## Correctness
You should try to run the rule on a large code base, like the jdk source code for instance. This will help ensure that the rule does not raise exceptions when dealing with unusual constructs.
You should try to run the rule on a large code base, like the jdk source code for instance. This will help ensure
that the rule does not raise exceptions when dealing with unusual constructs.
If your rule is stateful, make sure that it is reinitialized correctly. The “-stress” command line option can be used as the files will then not be ordered but processed randomly. Running pmd with the “-stress” option several times and sorting the text output should produce identical results if the state information is correctly reset.
If your rule is stateful, make sure that it is reinitialized correctly for each file.
## Performance issues
When writing a new rule, using command line option -benchmark on a few rules can give an indication on how the rule compares to others. To get the full picture, use the rulesets/internal/all-java.xml ruleset with “-benchmark”.
When writing a new rule, using command line option `--benchmark` on a few rules can give an indication on how
the rule compares to others. To get the full picture, use the `rulesets/internal/all-java.xml` ruleset
with “--benchmark”.
Rules which use the RuleChain to visit the AST are faster than rules which perform manual visitation of the AST. The difference is small for an individual Java rule, but when running 100s of rules, it is measurable. For XPath rules, the difference is extremely noticeable due to Jaxen overhead for AST navigation. Make sure your XPath rules using the RuleChain.
Rules which use the RuleChain to visit the AST are faster than rules which perform manual visitation of the AST.
The difference is small for an individual Java rule, but when running 100s of rules, it is measurable.
For XPath rules, the difference is extremely noticeable due to the overhead for AST navigation.
Make sure your XPath rules using the RuleChain. If RuleChain can't be used for your XPath rule, then this fact
is logged as a debug message.
(TODO How does one know except by running in a debugger or horrendous performance?).
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+76 -8
View File
@@ -378,7 +378,7 @@ Commands:
Warning: May not support the full CPD feature set
ast-dump Experimental: dumps the AST of parsing source code
Exit Codes:
0 Succesful analysis, no violations found
0 Successful analysis, no violations found
1 An unexpected error occurred during execution
2 Usage error, please refer to the command help
4 Successful analysis, at least 1 violation found
@@ -446,7 +446,7 @@ Contributors: [Lucas Soncini](https://github.com/lsoncini) (@lsoncini),
This PMD release ships a new version of the pmd-designer.
For the changes, see [PMD Designer Changelog](https://github.com/pmd/pmd-designer/releases/tag/7.0.0-rc1).
#### New CPD report format cpdhtml-v2.xslt
### New CPD report format cpdhtml-v2.xslt
Thanks to @mohan-chinnappan-n a new CPD report format has been added which features a data table.
It uses an XSLT stylesheet to convert CPD's XML format into HTML.
@@ -495,20 +495,28 @@ We are shipping the following rules:
Contributors: [Jeroen Borgers](https://github.com/jborgers) (@jborgers),
[Peter Paul Bakker](https://github.com/stokpop) (@stokpop)
#### New: CPD support for TypeScript
### New: CPD support for TypeScript
Thanks to a contribution, CPD now supports the TypeScript language. It is shipped
with the rest of the JavaScript support in the module `pmd-javascript`.
Contributors: [Paul Guyot](https://github.com/pguyot) (@pguyot)
#### New: CPD support for Julia
### New: CPD support for Julia
Thanks to a contribution, CPD now supports the Julia language. It is shipped
in the new module `pmd-julia`.
Contributors: [Wener](https://github.com/wener-tiobe) (@wener-tiobe)
### New: CPD support for Coco
Thanks to a contribution, CPD now supports Coco, a modern programming language
designed specifically for building event-driven software. It is shipped in the new
module `pmd-coco`.
Contributors: [Wener](https://github.com/wener-tiobe) (@wener-tiobe)
### Changed: JavaScript support
The JS specific parser options have been removed. The parser now always retains comments and uses version ES6.
@@ -529,6 +537,13 @@ the Java module, listing all possible versions enables other languages as well t
Related issue: [[core] Explicitly name all language versions (#4120)](https://github.com/pmd/pmd/issues/4120)
### Changed: CPP can now ignore identifiers in sequences (CPD)
* new command line option for CPD: `--ignore-sequences`.
* This option is used for CPP only: with the already existing option `--ignore-literal-sequences`, only
literals were ignored. The new option additional ignores identifiers as well in sequences.
* See [PR #4470](https://github.com/pmd/pmd/pull/4470) for details.
## 🌟 New and changed rules
### New Rules
@@ -676,6 +691,9 @@ The following previously deprecated rules have been finally removed:
* {% deleted_rule apex/performance/AvoidSoqlInLoops %} -> use {% rule apex/performance/OperationWithLimitsInLoop %}
* {% deleted_rule apex/performance/AvoidSoslInLoops %} -> use {% rule apex/performance/OperationWithLimitsInLoop %}
* {% deleted_rule apex/performance/AvoidDmlStatementsInLoops %} -> use {% rule apex/performance/OperationWithLimitsInLoop %}
* {% deleted_rule apex/codestyle/VariableNamingConventions %} -> use {% rule apex/codestyle/FieldNamingConventions %},
{% rule apex/codestyle/FormalParameterNamingConventions %}, {% rule apex/codestyle/LocalVariableNamingConventions %},
or {% rule apex/codestyle/PropertyNamingConventions %}
**Java**
@@ -748,9 +766,6 @@ The following previously deprecated rules have been finally removed:
use {% rule "java/bestpractices/SimplifiableTestAssertion" %}
* UseAssertTrueInsteadOfAssertEquals (java-bestpractices) ->
use {% rule "java/bestpractices/SimplifiableTestAssertion" %}
* VariableNamingConventions (apex-codestyle) -> use {% rule apex/codestyle/FieldNamingConventions %},
{% rule apex/codestyle/FormalParameterNamingConventions %}, {% rule apex/codestyle/LocalVariableNamingConventions %},
or {% rule apex/codestyle/PropertyNamingConventions %}
* VariableNamingConventions (java-codestyle) -> use {% rule java/codestyle/FieldNamingConventions %},
{% rule java/codestyle/FormalParameterNamingConventions %},
or {% rule java/codestyle/LocalVariableNamingConventions %}
@@ -768,6 +783,12 @@ The following previously deprecated rules have been finally removed:
to be reviewed.
* Custom rules using rulechains: Need to override {% jdoc core::lang.rule.AbstractRule#buildTargetSelector() %}
using {% jdoc core::lang.rule.RuleTargetSelector#forTypes(java.lang.Class,java.lang.Class...) %}.
* The asset filenames of PMD on [GitHub Releases](https://github.com/pmd/pmd/releases) are
now `pmd-dist-<version>-bin.zip`, `pmd-dist-<version>-src.zip` and `pmd-dist-<version>-doc.zip`.
Keep that in mind, if you have an automated download script.
The structure inside the ZIP files stay the same, e.g. we still provide inside the binary distribution
ZIP file the base directory `pmd-bin-<version>`.
### For integrators
@@ -963,8 +984,45 @@ and [Adding a new language with ANTLR](pmd_devdocs_major_adding_new_language_ant
Related issue: [[core] Language lifecycle (#3782)](https://github.com/pmd/pmd/issues/3782)
### Rule properties
### API removals
* The old deprecated classes like `IntProperty` and `StringProperty` have been removed. Please use
{% jdoc core::properties.PropertyFactory %} to create properties.
* All properties which accept multiple values now use a comma (`,`) as a delimiter. The previous default was a
pipe character (`|`). The delimiter is not configurable anymore. If needed, the comma can be escaped
with a backslash.
* The `min` and `max` attributes in property definitions in the XML are now optional and can appear separately
or be omitted.
### API changes
#### 7.0.0-rc3
* The following previously deprecated classes have been removed:
* pmd-core
* `net.sourceforge.pmd.PMD`
* `net.sourceforge.pmd.cli.PMDCommandLineInterface`
* `net.sourceforge.pmd.cli.PMDParameters`
* `net.sourceforge.pmd.cli.PmdParametersParseResult`
* The asset filenames of PMD on [GitHub Releases](https://github.com/pmd/pmd/releases) are
now `pmd-dist-<version>-bin.zip`, `pmd-dist-<version>-src.zip` and `pmd-dist-<version>-doc.zip`.
Keep that in mind, if you have an automated download script.
The structure inside the ZIP files stay the same, e.g. we still provide inside the binary distribution
ZIP file the base directory `pmd-bin-<version>`.
* The CLI option `--stress` (or `-stress`) has been removed without replacement.
* The CLI option `--minimum-priority` was changed with 7.0.0-rc1 to only take the following values:
High, Medium High, Medium, Medium Low, Low. With 7.0.0-rc2 compatibility has been restored, so that the equivalent
integer values (1 to 5) are supported as well.
* Replaced `RuleViolation::getFilename` with new {% jdoc !!core::RuleViolation#getFileId() %}, that returns a
{% jdoc core::lang.document.FileId %}. This is an identifier for a {% jdoc core::lang.document.TextFile %}
and could represent a path name. This allows to have a separate display name, e.g. renderers use
{% jdoc core::reporting.FileNameRenderer %} to either display the full path name or a relative path name
(see {% jdoc !!core::renderers.Renderer#setFileNameRenderer(net.sourceforge.pmd.reporting.FileNameRenderer) %} and
{%jdoc core::reporting.ConfigurableFileNameRenderer %}). Many places where we used a simple String for
a path-like name before have been adapted to use the new {% jdoc core::lang.document.FileId %}.
See [PR #4425](https://github.com/pmd/pmd/pull/4425) for details.
#### 7.0.0-rc2
@@ -975,6 +1033,16 @@ Related issue: [[core] Language lifecycle (#3782)](https://github.com/pmd/pmd/is
* `net.sourceforge.pmd.cli.PMDParameters`
* `net.sourceforge.pmd.cli.PmdParametersParseResult`
* The CLI option `--minimum-priority` was changed with 7.0.0-rc1 to only take the following values:
High, Medium High, Medium, Medium Low, Low. With 7.0.0-rc2 compatibility has been restored, so that the equivalent
integer values (1 to 5) are supported as well.
#### 7.0.0-rc1
* The CLI option `--stress` (or `-stress`) has been removed without replacement.
* The CLI option `--minimum-priority` now takes one of the following values instead of an integer:
High, Medium High, Medium, Medium Low, Low.
#### 6.55.0
**Go**
+5
View File
@@ -246,6 +246,11 @@
<fileset file="${parser-file}" />
</replaceregexp>
<replaceregexp flags="g">
<regexp pattern="throw new ParseException\(\);" />
<substitution expression='throw net.sourceforge.pmd.util.AssertionUtil.shouldNotReachHere("consumetoken(-1) should have thrown");' />
<fileset file="${parser-file}" />
</replaceregexp>
<replaceregexp>
<regexp pattern="public interface"/>
@@ -32,7 +32,9 @@ import net.sourceforge.pmd.lang.document.TextFile;
import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.renderers.RendererFactory;
import net.sourceforge.pmd.reporting.FileAnalysisListener;
import net.sourceforge.pmd.reporting.FileNameRenderer;
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
import net.sourceforge.pmd.reporting.ListenerInitializer;
@InternalApi
public class Formatter {
@@ -253,6 +255,16 @@ public class Formatter {
return new GlobalAnalysisListener() {
final GlobalAnalysisListener listener = renderer.newListener();
@Override
public ListenerInitializer initializer() {
return new ListenerInitializer() {
@Override
public void setFileNameRenderer(FileNameRenderer fileNameRenderer) {
renderer.setFileNameRenderer(fileNameRenderer);
}
};
}
@Override
public FileAnalysisListener startFileAnalysis(TextFile file) {
return listener.startFileAnalysis(file);
@@ -120,6 +120,7 @@ public class PMDTaskImpl {
}
}
@SuppressWarnings("PMD.CloseResource")
ReportStatsListener reportStatsListener = new ReportStatsListener();
pmd.addListener(getListener(reportStatsListener));
@@ -177,7 +178,7 @@ public class PMDTaskImpl {
@Override
public FileAnalysisListener startFileAnalysis(TextFile dataSource) {
String name = dataSource.getDisplayName();
String name = dataSource.getFileId().getUriString();
project.log("Processing file " + name, Project.MSG_VERBOSE);
return FileAnalysisListener.noop();
}
Loaded 30 of 384 files, more files were not shown because too many files have changed in this diff. Show more