Java icon indicating copy to clipboard operation
Java copied to clipboard

chore: configure PMD

Open vil02 opened this issue 1 year ago • 1 comments

PMD is another static analysis tool, which can be used with Java. The pmd-exclude.properties file contains a list of rules, which currently have to be suppressed. Clearly, the long term goal, is to make this file empty. It was generated using such python script (I put it here, just to save it for the future):

# paste the relevant piece of the output of `mvn pmd:check` here
_INPUT = """
[INFO] PMD Failure: com.thealgorithms.bitmanipulation.SingleBitOperations:32 Rule:UselessParentheses Priority:4 Useless parentheses..
[INFO] PMD Failure: com.thealgorithms.ciphers.AffineCipher:36 Rule:UselessParentheses Priority:4 Useless parentheses..
[INFO] PMD Failure: com.thealgorithms.ciphers.AffineCipher:49 Rule:UselessParentheses Priority:4 Useless parentheses..
[INFO] PMD Failure: com.thealgorithms.ciphers.AffineCipher:49 Rule:UselessParentheses Priority:4 Useless parentheses..
"""

def _get_class(in_str):
    class_name, _ = in_str.split(':')
    return class_name

def _get_rule(in_str):
    _, rule = in_str.split(':')
    return rule

def _proc_line(in_str):
    parts = in_str.split()
    class_name = _get_class(parts[3])
    rule = _get_rule(parts[4]);
    return class_name, rule

def _process_pmd_failures(input_data):
    res = {}
   
    for line in input_data.strip().split('\n'):
        class_name, rule = _proc_line(line)
        if class_name not in res:
            res[class_name] = set() 
        res[class_name].add(rule)
   
    return res

for class_name, rules in sorted(_process_pmd_failures(_INPUT).items()):
    rules_str = ",".join(sorted(rules))
    print(f'{class_name}={rules_str}')

This PR is similar to #5110 and #5122.

  • [x] I have read CONTRIBUTING.md.
  • [x] This pull request is all my own work -- I have not plagiarized it.
  • [x] All filenames are in PascalCase.
  • [x] All functions and variable names follow Java naming conventions.
  • [x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • [x] All new code is formatted with clang-format -i --style=file path/to/your/file.java

vil02 avatar May 11 '24 11:05 vil02

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 38.26%. Comparing base (bbe4a02) to head (6a9758e).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #5155   +/-   ##
=========================================
  Coverage     38.26%   38.26%           
  Complexity     2362     2362           
=========================================
  Files           516      516           
  Lines         15310    15310           
  Branches       2958     2958           
=========================================
  Hits           5858     5858           
  Misses         9165     9165           
  Partials        287      287           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar May 11 '24 11:05 codecov-commenter