Skip to content

PMD Comments Removal #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
de3a040
integrated pmd into CI (#646)
Malmahrouqi3 Jun 12, 2025
a1fe811
create rulset file
Malmahrouqi3 Jun 12, 2025
8defa9a
corrected directory
Malmahrouqi3 Jun 12, 2025
1fde2bc
changed ruleset pattern typo
Malmahrouqi3 Jun 12, 2025
0332cf1
added rules to python and fortran
Malmahrouqi3 Jun 12, 2025
9f46e71
ruleset for py
Malmahrouqi3 Jun 12, 2025
8c3fb08
individual rules
Malmahrouqi3 Jun 12, 2025
cd8e2a5
java rules - errorprone
Malmahrouqi3 Jun 12, 2025
4db4277
java rules
Malmahrouqi3 Jun 12, 2025
d6d3bc8
old school integration of PMD into workflow
Malmahrouqi3 Jun 12, 2025
54a6fc9
removed Detect File Changes
Malmahrouqi3 Jun 12, 2025
515c32a
changed to cat to display reports
Malmahrouqi3 Jun 13, 2025
4f4134a
added java compiler as dependency
Malmahrouqi3 Jun 13, 2025
b3ae8fa
removed something
Malmahrouqi3 Jun 13, 2025
085eaa5
just checking syntax
Malmahrouqi3 Jun 13, 2025
e3626f6
set env var pmd=/pmd/bin/pmd
Malmahrouqi3 Jun 13, 2025
f022a85
quick syntax correction
Malmahrouqi3 Jun 13, 2025
4fdb0c3
made PMD_COMMAND globally recognized
Malmahrouqi3 Jun 13, 2025
c7c1bdb
corrected package path
Malmahrouqi3 Jun 13, 2025
393d69b
moved alias command under Running PMD
Malmahrouqi3 Jun 13, 2025
7448609
comments removal
Jun 16, 2025
36fb29e
comments removal 2
Jun 16, 2025
76352dd
comments removal 3
Jun 16, 2025
0aa7abe
reduced number of tokens
Jun 16, 2025
d47b810
Merge branch 'master' into CI-pmd
Malmahrouqi3 Jun 16, 2025
52aeefc
Update pmd.yml
Malmahrouqi3 Jun 16, 2025
037c2e6
Update pmd.yml
Malmahrouqi3 Jun 16, 2025
26f3228
Update pmd.yml
Malmahrouqi3 Jun 16, 2025
9605a29
Update pmd.yml
Malmahrouqi3 Jun 16, 2025
3c01cfa
Update pmd.yml
Malmahrouqi3 Jun 16, 2025
d2fff04
Update pmd.yml
Malmahrouqi3 Jun 16, 2025
3bd04f3
Update pmd.yml
Malmahrouqi3 Jun 17, 2025
d4b77fb
Update pmd.yml
Malmahrouqi3 Jun 17, 2025
502ab2c
Update pmd.yml
Malmahrouqi3 Jun 17, 2025
23d44d3
Merge branch 'master' into CI-pmd
Malmahrouqi3 Jun 17, 2025
31b873c
Update pmd.yml
Malmahrouqi3 Jun 17, 2025
8cf02c0
Update pmd.yml
Malmahrouqi3 Jun 17, 2025
1008246
Update pmd.yml
Malmahrouqi3 Jun 17, 2025
cd8f908
Update pmd.yml
Malmahrouqi3 Jun 17, 2025
ae4cbf5
more cleanup
Malmahrouqi3 Jun 17, 2025
27c9932
tokens=20
Malmahrouqi3 Jun 17, 2025
3c0682d
strip out majority of spaces
Malmahrouqi3 Jun 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 98 additions & 1 deletion .github/workflows/pmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,104 @@ jobs:
unzip -q pmd.zip
PMD_HOME="pmd-bin-${PMD_VERSION}"

SOURCE_DIR="${1:-src}"
total_files=$(find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) | wc -l)
processed=0

find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) -print0 |
while IFS= read -r -d $'\0' file; do
processed=$((processed + 1))
echo -e "[$processed/$total_files] Processing ${file}..."

# Create a temporary file with same permissions as original
TMP_FILE=$(mktemp)
if [ $? -ne 0 ]; then
echo -e "Failed to create temporary file for $file, skipping"
continue
fi

# Copy permissions from original file
chmod --reference="$file" "$TMP_FILE"

# More comprehensive sed command to handle different Fortran comment styles:
# 1. Replace lines that are entirely comments with an empty line:
# - Lines starting with '!' (free form comments)
# - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments)
# 2. Remove end-of-line comments (anything after '!' that isn't in a string)
# 3. Preserve strings containing '!' characters
sed -E '
# First handle & continuation style (modern Fortran)
:ampersand_loop
/&[[:space:]]*$/ {
N
s/&[[:space:]]*\n[[:space:]]*(&)?/ /g
tampersand_loop
}

# Handle fixed-form continuation (column 6 indicator)
:fixed_form_loop
/^[[:space:]]{0,5}[^[:space:]!&]/ {
N
s/\n[[:space:]]{5}[^[:space:]]/ /g
tfixed_form_loop
}

# Remove any remaining continuation markers
s/&//g

# Normalize spacing - replace multiple spaces with single space
s/[[:space:]]{2,}/ /g

# Remove spaces around mathematical operators
s/[[:space:]]*\*[[:space:]]*/*/g
s/[[:space:]]*\+[[:space:]]*/+/g
s/[[:space:]]*-[[:space:]]*/-/g
s/[[:space:]]*\/[[:space:]]*/\//g
s/[[:space:]]*\*\*[[:space:]]*/\*\*/g

# Remove spaces in common Fortran constructs (array indexing, function calls)
s/\([[:space:]]*([^,)[:space:]]+)[[:space:]]*,/(\1,/g # First argument
s/,[[:space:]]*([^,)[:space:]]+)[[:space:]]*,/,\1,/g # Middle arguments
s/,[[:space:]]*([^,)[:space:]]+)[[:space:]]*\)/,\1)/g # Last argument
s/\([[:space:]]*([^,)[:space:]]+)[[:space:]]*\)/(\1)/g # Single argument

# Remove spaces around brackets and parentheses
s/\[[[:space:]]*/</g
s/\[[[:space:]]*/>/g
s/\[[[:space:]]*/</g
s/[[:space:]]*\]/]/g
s/\([[:space:]]*/(/g
s/[[:space:]]*\)/)/g

# Remove spaces around comparison operators
s/[[:space:]]*<=[[:space:]]*/</g
s/[[:space:]]*>=[[:space:]]*/>/g
s/[[:space:]]*<[[:space:]]*/</g
s/[[:space:]]*>[[:space:]]*/>/g
s/[[:space:]]*==[[:space:]]*/==/g

# Remove full-line comments
/^\s*!/d
/^[cC*dD]/d
/^[ \t]*[cC*dD]/d

# Remove end-of-line comments, preserving quoted strings
s/([^"'\''\\]*("[^"]*")?('\''[^'\'']*'\''?)?[^"'\''\\]*)[!].*$/\1/
' "$file" > "$TMP_FILE"

if cmp -s "$file" "$TMP_FILE"; then
echo -e "No changes needed for $file"
rm "$TMP_FILE"
else
# Overwrite the original file with the processed content
mv "$TMP_FILE" "$file"
echo -e "Successfully processed $file"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

fi
done

"${PMD_HOME}/bin/pmd" cpd \
--dir src \
--language fortran \
--minimum-tokens=40
--minimum-tokens=20 \
--no-fail-on-violation \
--no-fail-on-error