-
Notifications
You must be signed in to change notification settings - Fork 121
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
PMD Comments Removal
#889
Conversation
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
remove
|
@sbryngelson the number of violations is identical (63) whether the filter is on or off. |
|
strange |
|
I guess it should now presumably detect more duplicate lines if they are exactly the same operation but split out into lines differently. q_sf(j, k, l) = q_sf(j, k, l)+q_prim_vf0(mom_idx%beg)%sf(j, k, l)*fd_coeff_x(r, j)*q_prim_vf0(mom_idx%beg)%sf(r+j, k, l)+q_prim_vf0(mom_idx%beg+1)%sf(j, k, l)*fd_coeff_y(r, k)*q_prim_vf0(mom_idx%beg)%sf(j, r+k, l)+q_prim_vf0(mom_idx%end)%sf(j, k, l)*fd_coeff_z(r, l)*q_prim_vf0(mom_idx%beg)%sf(j, k, r+l)/y_cc(k) |
|
yes that's what i was thinking. you could even strip spaces (maybe?) |
|
this is actually a very valuable tool! |
|
I left behind |
yes agreed. so you already did this or not yet? |
|
yup, you can check out the last commit PMD check. |
|
Filter Full Implementation 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" |
|
i just realized that once you have removed any line continuations, you can delete all blank lines and spaces in the source code... they don't actually mean anything and the code doesn't have to compile, it just has to be parsed by PMD. by doing this we ensure we find all duplicate patterns |
|
Yup yup, it is kinda reasonable to think this way if you would rather unveil longer patterns than just ones with few lines. |
cool should be easier to do this as well. don't see a new commit yet but will look at the PR once it's updated. I did notice that the current run appears to have shorter "worst" offenders at the top of PMD output (fewer tokens). is this because you stripped their whitespace / comments and the code is the same as it was before (so # tokens dropped but the Fortran part is the same)? or is it not finding the worst offenders it was a few commits ago? I remember seeing > 200 tokens as the worst cases Edit: I checked myself. The violations (the first few worst ones) are the same, so you didn't break anything 👍 . |
|
Added to remove blank lines |
|
Looks pretty good to me. Do you have any other modifications planned? |
|
Nope |
Co-authored-by: mohdsaid497566 <[email protected]>
Description
This is subsequent to (#882) with the mere addition of filtering out inline comments and commented lines. For the PMD details, check out the original issue (#646)
To show off the difference:
Filter-off: pmd-old branch https://github.com/Malmahrouqi3/MFC-mo2/actions/runs/15693861383/job/44214858621
Filter-on: pmd-new branch https://github.com/Malmahrouqi3/MFC-mo2/actions/runs/15694477828/job/44216673771
Improves PMD.