-
Notifications
You must be signed in to change notification settings - Fork 106
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
Malmahrouqi3
wants to merge
42
commits into
MFlowCode:master
Choose a base branch
from
Malmahrouqi3:CI-pmd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−1
Open
PMD
Comments Removal
#889
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 a1fe811
create rulset file
Malmahrouqi3 8defa9a
corrected directory
Malmahrouqi3 1fde2bc
changed ruleset pattern typo
Malmahrouqi3 0332cf1
added rules to python and fortran
Malmahrouqi3 9f46e71
ruleset for py
Malmahrouqi3 8c3fb08
individual rules
Malmahrouqi3 cd8e2a5
java rules - errorprone
Malmahrouqi3 4db4277
java rules
Malmahrouqi3 d6d3bc8
old school integration of PMD into workflow
Malmahrouqi3 54a6fc9
removed Detect File Changes
Malmahrouqi3 515c32a
changed to cat to display reports
Malmahrouqi3 4f4134a
added java compiler as dependency
Malmahrouqi3 b3ae8fa
removed something
Malmahrouqi3 085eaa5
just checking syntax
Malmahrouqi3 e3626f6
set env var pmd=/pmd/bin/pmd
Malmahrouqi3 f022a85
quick syntax correction
Malmahrouqi3 4fdb0c3
made PMD_COMMAND globally recognized
Malmahrouqi3 c7c1bdb
corrected package path
Malmahrouqi3 393d69b
moved alias command under Running PMD
Malmahrouqi3 7448609
comments removal
36fb29e
comments removal 2
76352dd
comments removal 3
0aa7abe
reduced number of tokens
d47b810
Merge branch 'master' into CI-pmd
Malmahrouqi3 52aeefc
Update pmd.yml
Malmahrouqi3 037c2e6
Update pmd.yml
Malmahrouqi3 26f3228
Update pmd.yml
Malmahrouqi3 9605a29
Update pmd.yml
Malmahrouqi3 3c01cfa
Update pmd.yml
Malmahrouqi3 d2fff04
Update pmd.yml
Malmahrouqi3 3bd04f3
Update pmd.yml
Malmahrouqi3 d4b77fb
Update pmd.yml
Malmahrouqi3 502ab2c
Update pmd.yml
Malmahrouqi3 23d44d3
Merge branch 'master' into CI-pmd
Malmahrouqi3 31b873c
Update pmd.yml
Malmahrouqi3 8cf02c0
Update pmd.yml
Malmahrouqi3 1008246
Update pmd.yml
Malmahrouqi3 cd8f908
Update pmd.yml
Malmahrouqi3 ae4cbf5
more cleanup
Malmahrouqi3 27c9932
tokens=20
Malmahrouqi3 3c0682d
strip out majority of spaces
Malmahrouqi3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.